GATE Computer ScienceHardGATE CS (PYQ pattern)

A singly linked list 10 -> 11 -> ... -> 19 is rearranged by a routine that places all nodes at odd positions (1st, 3rd, ...) first, followed by all nodes at even positions, each group keeping its order. After that, the routine is applied once more to the new list. What is the 4th node of the final list?

  1. A. 16
  2. B. 17
  3. C. 13
  4. D. 18

Correct answer: C. 13

After one pass the list is [10, 12, 14, 16, 18, 11, 13, 15, 17, 19]; after the second pass it is [10, 14, 18, 13, 17, 12, 16, 11, 15, 19], whose 4th node is 13.

More Programming and Data Structures (GATE) questions

Exams that ask this topic