What is the result of the following binary search on the array [1, 2, 3, 4, 5] f

Practice Questions

Q1
What is the result of the following binary search on the array [1, 2, 3, 4, 5] for target 3?
  1. 0
  2. 1
  3. 2
  4. 3

Questions & Step-by-Step Solutions

What is the result of the following binary search on the array [1, 2, 3, 4, 5] for target 3?
  • Step 1: Initialize left at index 0 and right at index 4.
  • Step 2: Calculate middle index: middle = (0 + 4) // 2 = 2.
  • Step 3: Check the element at index 2, which is 3.
  • Step 4: Compare the middle element (3) with the target (3). They are equal.
  • Step 5: Return the index of the target, which is 2.
No concepts available.
Soulshift Feedback ×

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

Not likely Very likely