What will be the return value of binary search if the element is not found?

Practice Questions

Q1
What will be the return value of binary search if the element is not found?
  1. -1
  2. 0
  3. 1
  4. n

Questions & Step-by-Step Solutions

What will be the return value of binary search if the element is not found?
  • Understand that binary search is used to find an element in a sorted array.
  • Check the middle element of the array.
  • If the middle element is not the target, decide to search either the left or right half.
  • Continue this process until you either find the element or exhaust the search space.
  • If the element is not found, return -1 to indicate it is not in the array.
No concepts available.
Soulshift Feedback ×

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

Not likely Very likely