If the list to be searched using binary search contains an even number of elements, then the mid-value is calculated using _______________.
If the list to be searched using binary search contains an even number of elements, then the mid-value is calculated using _______________.
Solution
✅ Correct Option: 1
With an even number of elements there are two middle elements, so is not a whole number. Floor division (// in Python) rounds it down to a valid index, so the lower of the two middle elements is taken.
For 6 elements with indices 0 to 5:
Options 3 and 4: the average or mean of the two indices gives a decimal such as 2.5, which cannot be used as a list index.
Option 2: ceil division would also give a whole number, but the standard rule is to use floor division.
Related questions:
2026: 18 May Shift 2
2026: 19 May Shift 1
2025: 15 May Shift 2