GATE / CS ARCHIVE

GATE CSE 1999 / QUESTION 1.14

Second bottom-up merge pass

Algorithms · Searching, Sorting & Selection · Full GATE CSE 1999 paper

GATE 1999, Q1.14 1 mark · MCQ
Report issue

Searching, Sorting & Selection

Question 1.14, GATE 1999: Sort 20,47,15,8,9,4,40,30,12,17 by straight two-way merging. What is the order after the second pass?
Tap to enlarge
Your answer
Answer & solution

Answer: B: 8,15,20,47,4,9,30,40,12,17 (no official key was published)

Step through it (10 steps)

Pass one merges singleton runs into pairs: [20,47], [8,15], [4,9], [30,40], [12,17]. Pass two merges adjacent pairs into four-element sorted runs. The first two yield [8,15,20,47]; the next two yield [4,9,30,40]. The final pair has no partner and remains [12,17]. Concatenating these runs gives B. The whole array is not yet sorted; later passes merge the length-four runs and the remaining tail.

Original paper, page 2