Exam-style question
Try this first
Why must the data be ordered before binary search is used?.
- A.The algorithm uses the order to decide which half can be discarded
- B.The algorithm can only store ordered values
- C.Ordering makes every search take exactly one comparison
- D.The algorithm changes the values into numbers
Model answer
What a good answer should say
- The algorithm uses the order to decide which half can be discarded
Explanation
Why this works
After checking the middle value, binary search compares it with the target. The ordering allows the algorithm to discard the half that cannot contain the target.
Common mistake
No common mistake is linked to this question yet.
