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.
- A. 5 10 30 40 50 60 80 90
- B. 5 10 40 30 60 50 80 90
- C. 10 5 30 40 50 60 80 90
- 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.
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
- From the array 3 -1 8 2 -4 6 5 you may take exactly 3 elements, each taken from the LEFT end or from the RIGHT end of what remains. What…
- In one operation you increase ALL elements of the array 1 2 4 except one chosen element by 1. What is the minimum number of operations…
- A stream arrives one character at a time: a a b c b d. After each character, report the FIRST character (in arrival order) that has…
- A linked list holds 1 through 10 in order. Going from the head, reverse the first 3 nodes, leave the next 3 unchanged, reverse the next 3…
- How many pairs of positions i < j in the array 12 21 3 30 111 24 42 have DIGIT SUMS that are equal?
- In the string "((a)(b(c)))d((e))", what is the maximum nesting depth of round brackets (the number of brackets open at the deepest point)?