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).

  1. A. 3
  2. B. 7
  3. C. 12
  4. 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.

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

Exams that ask this topic