Data Structures & AlgorithmsVery hardICPC regional · Codeforces Div 2

The 3×4 matrix [[1,3,5,7],[10,11,16,20],[23,30,34,60]] is treated as one sorted array of 12 entries, with mid = (lo + hi) / 2, row = mid / 4 and col = mid % 4. How many probes does a search for 9 make before it stops?

  1. A. 4
  2. B. 3
  3. C. 5
  4. D. 6

Correct answer: A. 4

The probes are (1,1)=11, (0,2)=5, (0,3)=7 and (1,0)=10. The range is then empty, so the search stops after 4 probes; 3 misses the last one.

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic