What is the result of binary search if the array is empty?

Practice Questions

Q1
What is the result of binary search if the array is empty?
  1. Returns 0
  2. Returns -1
  3. Returns null
  4. Throws an error

Questions & Step-by-Step Solutions

What is the result of binary search if the array is empty?
  • Step 1: Understand what binary search is. It is a method to find a target value in a sorted array by repeatedly dividing the search interval in half.
  • Step 2: Consider the case when the array is empty. An empty array means there are no elements to search through.
  • Step 3: Since there are no elements in the array, the binary search cannot find the target value.
  • Step 4: Therefore, the result of the binary search in an empty array is -1, which indicates that the target is not found.
No concepts available.
Soulshift Feedback ×

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

Not likely Very likely