GATE Computer ScienceHardGATE CS (PYQ pattern)
LSD radix sort (decimal digits, stable counting sort on each digit, least significant first) is applied to [329, 457, 657, 839, 436, 720, 355, 102, 893]. What does the array look like after the second pass (tens digit)?
- A. [720, 102, 893, 355, 436, 457, 657, 329, 839]
- B. [102, 720, 329, 436, 839, 355, 457, 657, 893]
- C. [102, 329, 355, 436, 457, 657, 720, 839, 893]
- D. [102, 720, 329, 839, 436, 355, 457, 657, 893]
Correct answer: B. [102, 720, 329, 436, 839, 355, 457, 657, 893]
Pass 1 (units) gives 720, 102, 893, 355, 436, 457, 657, 329, 839; pass 2 sorts by the tens digit, keeping the order of equal digits: 102 | 720, 329 | 436, 839 | 355, 457, 657 | 893. The third pass would give the fully sorted array.
More Algorithms questions
- A shell sort pass with gap 5 (a gapped insertion sort) is applied to [23, 12, 45, 3, 67, 8, 34, 19, 56, 2, 41, 28]. The cost of the pass…
- The array [14, 5, 21, 9, 30, 7, 18, 2, 26, 11] is made into a max-heap, giving [30, 26, 21, 14, 11, 7, 18, 2, 9, 5]. Heapsort then…
- In how many ways can 30 be written as a sum of ODD positive integers, where order does not matter and parts may repeat?
- In how many ways can 20 be written as a sum of exactly 4 positive integers, where order does not matter (parts may repeat)?
- A tree on vertices 0–10 has weighted edges 0-1 (3), 1-2 (4), 1-3 (2), 3-4 (6), 3-5 (1), 5-6 (7), 0-7 (5), 7-8 (2), 2-9 (3), 9-10 (8). Its…
- Vertices 0–10 of the tree with edges 0-1, 1-2, 1-3, 3-4, 3-5, 5-6, 0-7, 7-8, 2-9, 9-10 carry weights w = 4, 7, 3, 9, 5, 2, 8, 6, 5, 4, 10…