Data Structures & AlgorithmsHard
Jump search uses block size m = 4 on the sorted array 1 4 6 9 11 14 18 21 25 30 33 37 40 44 48 51. It jumps by 4 while the last element of the block is smaller than the key, then scans the block linearly. Count every comparison made while searching for the key 37 (each jump check and each element check counts one).
- A. 3
- B. 7
- C. 12
- D. 4
Correct answer: B. 7
Jump checks: A[3] = 9 < 37, A[7] = 21 < 37, A[11] = 37 not smaller, stop (3 checks); then scan 25, 30, 33, 37 (4 checks): 7. Counting only jumps gives 3, only the scan 4, and a plain linear search needs 12.
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
- The sorted array 2 5 8 11 13 17 21 was rotated so that it now reads 13 17 21 2 5 8 11. At which 0-based index is the value 11?
- What is the MEDIAN of the combined multiset of the sorted arrays 1 3 8 9 and 2 4 6 7 10? (The combined size is odd, so take the middle…
- Using the sorted arrays 1 3 8 9 and 2 4 6 7 10 together, what is the 7-th smallest value (1-based) of the combined multiset?
- Stably partition 5 2 7 4 1 8 6 3 so that all EVEN values come first and all ODD values come after, keeping the original relative order…
- Values in 4 3 2 7 8 2 3 1 lie in the range 1 to 8 (length 8). Using cyclic sort (place each value v at index v−1 by swaps), which values…
- Find the duplicate in 2 5 9 6 9 3 8 9 7 1 (values 1 to 9, one repeated) with Floyd's method: slow = a[slow] and fast = a[a[fast]], both…