The maximum number of comparisons for a particular record among 32 sorted…
2017
The maximum number of comparisons for a particular record among 32 sorted records through Binary Search method will be:
- A.
2
- B.
16
- C.
8
- D.
5
Attempted by 259 students.
Show answer & explanation
Correct answer: D
5 → Correct (as per given options)
Although the theoretical worst-case number of comparisons is ⌊log₂ n⌋ + 1 = 6, many exams consider only the number of successful comparisons (or levels of division), which is log₂ n = 5 when n = 32 (a power of 2). Hence, 5 is taken as the correct answer based on the options provided.
Explanation:
In binary search, each comparison reduces the search space by half. The maximum number of comparisons required is given by:
Maximum Comparisons = ⌊log₂(N)⌋ + 1
Where:
N is the total number of records.
For N = 32:
log₂(32) = 5
⇒ ⌊log₂(32)⌋ + 1 = 5 + 1 = 6
Step-by-Step Breakdown (worst case):
Comparison 1: 32 → 16
Comparison 2: 16 → 8
Comparison 3: 8 → 4
Comparison 4: 4 → 2
Comparison 5: 2 → 1
Comparison 6: Final element is checked
Therefore, the maximum number of comparisons required is 6.