📄 The question’s wording & key points
Exercise 1 (b): Use Binary Search to locate the number 45 in the sorted array:
[12, 13, 15, 17, 19, 22, 25, 27, 28, 31, 34, 35, 37, 42, 45, 50]
1The array must be sorted — start with left = 0, right = numrecords − 1
2Take the middle pos = (left + right) / 2 — integer division, rounded down
3Compare and throw away half — smaller goes right (left = pos + 1), larger goes left (right = pos − 1)
4Equal means return pos; an empty window (left > right) means return -1
Why so fast? Every comparison drops half of the candidates: n = 16 → 8 → 4 → 2 → 1, so at most about ⌈log₂17⌉ = 5 rounds. Time complexity O(log n), extra space O(1).
The precondition: the array must be sorted (the 16 numbers here are in ascending order), otherwise the comparison with the midpoint cannot tell you which way to go.
The courseware example: locating 45 → pos goes 7 (27<45, go right), 11 (35<45, go right), 13 (42<45, go right), 14 (45 == 45) → return 14; the Loop 5 and Loop 6 rows of the courseware table are blank because round 4 found it and the loop stopped early.
A small note: the second test in the courseware is typed DatSet[pos] — a typo for DataSet[pos].