Data Structures & AlgorithmsHard

Two sorted lists A = 10 30 50 and B = 5 40 60 80 90 are merged by taking nodes ALTERNATELY (first from A, then from B, and so on) until one list is exhausted; the rest of the other list is then appended. Give the merged sequence.

  1. A. 5 10 30 40 50 60 80 90
  2. B. 5 10 40 30 60 50 80 90
  3. C. 10 5 30 40 50 60 80 90
  4. D. 10 5 30 40 50 60 80

Correct answer: C. 10 5 30 40 50 60 80 90

Alternation picks from the lists in turn rather than by value, so the result is not sorted here. Forcing the sorted merge, starting with the wrong list, or dropping the appended tail each give a different sequence.

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

Exams that ask this topic