Junior
How many comparisons are needed to find the desired element out of eight?
sobes.tech AI
Answer from AI
To find an element in a sorted array of eight elements using binary search, a maximum of 3 comparisons is required.
Search:
- Compare with the median (4th or 5th element). Determine which half the desired element is in.
- Compare with the median of the chosen half (2nd or 3rd; 6th or 7th). Determine the quarter.
- Compare with the element within the chosen quarter. Find the element.