Count binary search steps for specific keys
Problem Description
You are given a sorted array of integers:
[22, 34, 55, 77, 89, 93, 99, 102, 120, 140]
Using the standard binary search algorithm, where low and high define the search range and the middle index mid is calculated as floor((low + high) / 2), determine the number of comparisons required to find each of the following target keys: 77, 34, and 99.
Your task is to provide a triple representing the total comparisons for each key in the specified order: (comparisons for 77, comparisons for 34, comparisons for 99).
AI interview prep
Core dilemma
Ensuring precise and consistent application of a fundamental algorithm's mechanics, especially concerning boundary conditions and comparison counting in a specific implementation context.
3 tradeoffs and 3 stress tests locked
Interview prep
Unlock the interviewer X-Ray rubric, tradeoff matrix, stress tests, clarifying questions, and key concepts.
Count binary search steps for specific keys
Problem Description
You are given a sorted array of integers:
[22, 34, 55, 77, 89, 93, 99, 102, 120, 140]
Using the standard binary search algorithm, where low and high define the search range and the middle index mid is calculated as floor((low + high) / 2), determine the number of comparisons required to find each of the following target keys: 77, 34, and 99.
Your task is to provide a triple representing the total comparisons for each key in the specified order: (comparisons for 77, comparisons for 34, comparisons for 99).