What is the average time complexity of binary search?

Practice Questions

Q1
What is the average time complexity of binary search?
  1. O(n)
  2. O(log n)
  3. O(n log n)
  4. O(1)

Questions & Step-by-Step Solutions

What is the average time complexity of binary search?
  • Step 1: Understand what binary search is. It is a method used to find an item in a sorted list by repeatedly dividing the search interval in half.
  • Step 2: Start with the entire list. Check the middle element of the list.
  • Step 3: If the middle element is the target, you are done.
  • Step 4: If the target is less than the middle element, repeat the search on the left half of the list.
  • Step 5: If the target is greater than the middle element, repeat the search on the right half of the list.
  • Step 6: Each time you repeat the search, you are halving the number of elements you need to check.
  • Step 7: This halving process continues until you find the target or the search space is empty.
  • Step 8: The number of times you can halve the list is logarithmic in relation to the number of elements, which is why the time complexity is O(log n).
No concepts available.
Soulshift Feedback ×

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

Not likely Very likely