How many comparisons does binary search make in the worst case for an array of s

Practice Questions

Q1
How many comparisons does binary search make in the worst case for an array of size n?
  1. n
  2. log n
  3. n log n
  4. 1

Questions & Step-by-Step Solutions

How many comparisons does binary search make in the worst case for an array of size n?
  • Step 1: Understand that binary search works on a sorted array.
  • Step 2: Know that binary search repeatedly divides the array in half to find the target value.
  • Step 3: Each time the array is divided, the size of the array to search is halved.
  • Step 4: The process continues until the size of the array is reduced to 1 or the target is found.
  • Step 5: The number of times you can divide n by 2 until you reach 1 is log base 2 of n, written as log2(n).
  • Step 6: Therefore, in the worst case, binary search makes log2(n) comparisons.
  • Binary Search – A search algorithm that finds the position of a target value within a sorted array by repeatedly dividing the search interval in half.
  • Logarithmic Complexity – The time complexity of binary search is O(log n), indicating that the number of comparisons grows logarithmically with the size of the array.
Soulshift Feedback ×

On a scale of 0–10, how likely are you to recommend The Soulshift Academy?

Not likely Very likely