chapter

    Sorting Algorithms Practice Questions for Cmi M.sc. and Ph.d. Computer Science

    Solve 0+ Sorting Algorithms practice questions for CMI M.Sc. and Ph.D. Computer Science with answers and detailed solutions. Free sample questions below.

    Free preview ends here

    Login to view the complete practice questions and solutions

    Creating an account is free. You get the rest of this chapter, step-by-step solutions, and a study plan built around the topics you are actually weak at.

    Explore complete test series, official past papers, and chapter-wise study tools.

    Why MastersUp

    Personalised first. High quality throughout.

    Most platforms hand everyone the same content. Here the content moves with your performance, topic by topic.

    Built around you, not around a syllabus PDF

    Every answer you give moves your topic-level intelligence rate. The next question, the next revision card and tomorrow's plan all change with it.

    Revision that hits your weak spots

    We only revise topics you have actually attempted and are still below the safe bar on — never the same chapter on repeat.

    Questions calibrated to the real exam

    Each question carries a measured toughness. You are served a rung above your current level, so practice keeps stretching you.

    Notes written for recall, not for volume

    Full lesson cards for first study, curated short-note cards for the last mile — with derivations, traps and exam patterns marked.

    One place for everything

    Notes, chapter practice, previous-year questions, test series and full-length papers — all feeding one picture of your preparation.

    Honest progress

    No vanity streaks. Progress here means chapters mastered and accuracy that held up on harder questions.

    Unlock the whole course

    Full notes and short notes, the complete question bank with worked solutions, mock tests, full-length papers, and an adaptive plan that rebuilds itself as you improve.

    Sorting Algorithms Practice Questions for CMI M.Sc. and Ph.D. Computer Science

    Solve 0+ Sorting Algorithms practice questions for CMI M.Sc. and Ph.D. Computer Science with answers and detailed solutions. Free sample questions below.

    The sorting problem and records

    Intuition

    The sorting problem and records

    A sorting algorithm outputs a permutation of records such that their keys are in non-decreasing order.

    The problem it solves

    You have a stack of student papers. You want to sort them by grade. Each paper has a name and a grade.

    The analogy of a physical stack stops being valid when records have identical keys. A physical stack has thickness and order, but an array is just a sequence of memory locations where identical keys can be permuted freely unless constrained.

    The idea made exact

    The input is an array of records. Each record has a key and satellite data.

    What the exact version adds. It separates the key from the satellite data. This separation is essential when keys are not unique, because the satellite data must move with its key.

    keys and satellite data

    Defining stability for equal keys

    Derivation

    Defining stability for equal keys

    Assumptions. The input is an array of records. Let have key . A permutation maps the original indices to the output positions.

    array of records permutation
    The steps
    1. Define a valid sort. A permutation is a valid sort if .
    2. Define stability. A sort is stable if for every pair of original indices with , the output places before .
    3. Translate to positions. This means the output positions satisfy .
    4. State the consequence. The relative order of records with equal keys is preserved from the input to the output.
    The stability condition
    Check

    For keys [2, 1, 2, 3], the equal keys are at indices 0 and 2. The only stable sort must place the index 0 record before the index 2 record.

    More practice questions in this unit