The maximum number of comparisons that may have to be performed if y is not an element of A is _______ . (Answer in integer)
10.00
Step-by-Step Solution
Insight: A 3-way comparison counts as exactly 1 comparison per step. The max comparisons is simply the depth of the recursion tree.
Exam route: Use the formula . For , .
Learning route:
The problem specifies a 3-way comparison (equal, less, greater). This counts as 1 comparison per recursive step.
The maximum number of comparisons is the maximum depth of the recursion tree, which occurs when the element is not found or is at the deepest leaf.
The exact formula for the maximum depth (number of comparisons) is .
Given :
.
.
Total comparisons = .
If the problem had specified two separate checks (e.g., if A[mid] == y then else if A[mid] < y), the worst case would be 2 comparisons per step, yielding 20. But the 3-way comparison explicitly avoids this trap.