If the array is [1, 2, 3, 4, 5] and the target is 3, what will be the mid index

Practice Questions

Q1
If the array is [1, 2, 3, 4, 5] and the target is 3, what will be the mid index during the first iteration of binary search?
  1. 0
  2. 1
  3. 2
  4. 3

Questions & Step-by-Step Solutions

If the array is [1, 2, 3, 4, 5] and the target is 3, what will be the mid index during the first iteration of binary search?
  • Step 1: Identify the array and the target value. The array is [1, 2, 3, 4, 5] and the target is 3.
  • Step 2: Determine the starting and ending indices of the array. The starting index is 0 (first element) and the ending index is 4 (last element).
  • Step 3: Calculate the mid index using the formula (start + end) // 2. Here, start is 0 and end is 4.
  • Step 4: Plug in the values into the formula: (0 + 4) // 2 = 4 // 2 = 2.
  • Step 5: The mid index is 2, which corresponds to the value 3 in the array.
  • 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.
  • Index Calculation – Understanding how to calculate the mid index using the formula (low + high) // 2.
Soulshift Feedback ×

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

Not likely Very likely