Data Structures & AlgorithmsHard
Records are (name, key): (ram, 2), (sita, 1), (gita, 2), (mohan, 0), (ravi, 1), (asha, 2). A STABLE counting sort orders them by key 0, 1, 2, keeping the original relative order within equal keys. What is the name sequence of the output?
- A. mohan sita ravi ram gita asha
- B. ram gita asha sita ravi mohan
- C. asha gita ram ravi sita mohan
- D. asha gita mohan ram ravi sita
Correct answer: A. mohan sita ravi ram gita asha
Counting sort places records in key order, and stability means records with equal keys keep their input order. Reversing the order, sorting descending, or sorting by name all break one of these properties.
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
- Jump search uses block size m = 4 on the sorted array 1 4 6 9 11 14 18 21 25 30 33 37 40 44 48 51. It jumps by 4 while the last element of…
- The sorted array 2 5 8 11 13 17 21 was rotated so that it now reads 13 17 21 2 5 8 11. At which 0-based index is the value 11?
- What is the MEDIAN of the combined multiset of the sorted arrays 1 3 8 9 and 2 4 6 7 10? (The combined size is odd, so take the middle…
- Using the sorted arrays 1 3 8 9 and 2 4 6 7 10 together, what is the 7-th smallest value (1-based) of the combined multiset?
- Stably partition 5 2 7 4 1 8 6 3 so that all EVEN values come first and all ODD values come after, keeping the original relative order…
- Values in 4 3 2 7 8 2 3 1 lie in the range 1 to 8 (length 8). Using cyclic sort (place each value v at index v−1 by swaps), which values…