📢 Too many exams? Don’t know which one suits you best? Book Your Free Expert 👉 call Now!

  • google app store apple app store
  • ✖

      Question

      A bank's customer database has 1,000,000 sorted records.

      Compare the maximum number of comparisons needed by Linear Search vs Binary Search to find a specific CustomerID.
      A Linear Search: 500,000 comparisons; Binary Search: 100 comparisons Correct Answer Incorrect Answer
      B Both require 1,000,000 comparisons in the worst case Correct Answer Incorrect Answer
      C Linear Search: 1,000 comparisons; Binary Search: 10 comparisons Correct Answer Incorrect Answer
      D Linear Search: 1,000,000 comparisons; Binary Search: 1,000 comparisons Correct Answer Incorrect Answer
      E Linear Search: 1,000,000 comparisons; Binary Search: 20 comparisons Correct Answer Incorrect Answer

      Solution

      Linear Search: Sequentially checks each record from the first. Worst case (element at last position or not found). So n = 1,000,000 comparisons. Time: O(n). Binary Search: Requires SORTED data. Each comparison eliminates half the remaining search space and hence Maximum comparisons = ⌈log₂(1,000,000)⌉ = ⌈19.93⌉ = 20.

      Practice Next

      Relevant for Exams:

      ask-question