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?

  1. A. mohan sita ravi ram gita asha
  2. B. ram gita asha sita ravi mohan
  3. C. asha gita ram ravi sita mohan
  4. 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.

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

Exams that ask this topic