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?
- A. 4
- B. 3
- C. 5
- 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.
Practise more Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questionsArrays, Strings, Linked Lists, Stacks, Queues and Hashing: notes and key points
More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions
- What is the minimum number of swaps needed to transpose a 6×6 matrix in place?
- For (i = 1; i < n; i = 2) and, inside it, (j = 0; j < i; j++), with n = 1024, how many times does the inner body run in total?
- How many times does the body of for (i = 2; i i ≤ n; i++) run for n = 10⁶?
- For (i = 1; i ≤ n; i = 3) with n = 1000, how many times does the body run?
- Naive recursion fib(n) = fib(n−1) + fib(n−2), with base cases n < 2, makes calls to itself. How many calls in total does fib(10) make…
- rec(n) returns at once if n ≤ 1; otherwise it calls rec(n/2) twice with integer division. How many calls are made for n = 16, counting the…