chapter
    Elementary Sorting Algorithms PYQs for GATE DA

    Solve 3+ Elementary Sorting Algorithms previous year questions for GATE DA with answers and detailed solutions. Free sample questions below.

    Try a question

    Answer it here to see how it works. Nothing is recorded until you sign in.

    Question 1
    2026 PYQ
    Level 3: Exam Standard
    Consider the problem of sorting the given array in ascending order:

    P = [1, 2, 3, 5, 4]

    Consider two sorting algorithms Bubble Sort (BS) and Insertion Sort (IS).

    Let N1 be the total number of comparisons done by BS on the elements of P and N2 be the total number of comparisons done by IS on the elements of P.

    Which of the following options is/are correct?
    Question 2
    2025 PYQ
    Level 3: Exam Standard

    Suppose that insertion sort is applied to the array and it takes exactly two swaps to sort the array. Select all possible values of .

    Question 3
    2024 PYQ
    Level 3: Exam Standard
    Consider the following sorting algorithms:
    Bubble sort
    Insertion sort
    Selection sort
    Which ONE among the following choices of sorting algorithms sorts the numbers
    in the array [4, 3, 2, 1, 5] in increasing order after exactly two passes over the array?
    Free preview ends here

    Login to view the complete previous-year 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.

    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.

    Elementary Sorting Algorithms PYQs for GATE DA

    Solve 3+ Elementary Sorting Algorithms previous year questions for GATE DA with answers and detailed solutions. Free sample questions below.

    Chapter Roadmap: Elementary Sorting Algorithms

    Chapter Roadmap

    Elementary Sorting Algorithms

    Topic 1: Bubble, Insertion and Selection Sort Pass Analysis
    Master the invariants, intermediate states, and exact operation counts for the three elementary sorts. (Current Topic)
    Topic 2: Insertion Sort Swaps and Nearly Sorted Arrays
    Deep dive into shifts, swaps, and the mathematics of inversions in partially sorted data.

    The Core Idea of Pass Analysis

    The Core Idea of Pass Analysis

    The Concept of a "Pass"

    A pass is one complete iteration of the algorithm's primary loop. In exam questions, you are rarely asked to sort the whole array. You are asked to determine the state of the array after exactly passes.

    The Golden Rule

    Do not trace the whole algorithm. Identify the invariant: what is mathematically guaranteed to be in its final sorted position after pass ?

    • Bubble Sort: Locks elements at the end.
    • Selection Sort: Locks elements at the beginning.
    • Insertion Sort: Sorts a prefix of the array.

    Elementary Sorting Algorithms: Solved Questions with Step-by-Step Explanations (3 Problems)

    Question 1 · Programming, Data Structures and Algorithms · 2026 MSQ
    Consider the problem of sorting the given array in ascending order:

    P = [1, 2, 3, 5, 4]

    Consider two sorting algorithms Bubble Sort (BS) and Insertion Sort (IS).

    Let N1 be the total number of comparisons done by BS on the elements of P and N2 be the total number of comparisons done by IS on the elements of P.

    Which of the following options is/are correct?
    1. A.

      N1 = 10, N2 = 4

    2. B.

      N1 > N2

    3. C.

      IS on P will perform only one swap

    4. D.

      Both BS and IS on P will make at least one unnecessary comparison (i.e., comparing elements that are already in correct order)

    Correct Answer:

    ["B","C","D"]

    Step-by-Step Solution

    Insight: This is a pass-analysis question recognisable because it asks for exact operation counts on a tiny concrete array. The pivot is that Bubble Sort (standard, no early termination) has a deterministic comparison count while Insertion Sort's count is data-dependent and must be traced element by element.

    Exam route:

    1. Compute N1 using the fixed formula: for , standard Bubble Sort does ... wait, that is only for a full sort. Let us recompute carefully: pass 1 does , pass 2 does , pass 3 does , pass 4 does . Total .
    2. Trace Insertion Sort on :
    • key=2: compare with 1 (1 cmp), no shift.
    • key=3: compare with 2 (1 cmp), no shift.
    • key=5: compare with 3 (1 cmp), no shift.
    • key=4: compare with 5 (shift), compare with 3 (stop) → 2 cmp, 1 shift.
    • Total , shifts .
    1. Evaluate options: ; holds; IS does exactly 1 swap; BS in passes 2–4 compares already-sorted adjacent pairs (unnecessary), and IS compares 4 with 5 which are out of order but the comparison that stops at 3 (already in correct relative order with 4) is the boundary check — BS clearly makes unnecessary comparisons, so D holds.

    Learning route:

    Bubble Sort (standard, no flag) always performs exactly comparisons regardless of input. For , .

    Insertion Sort comparisons depend on how far each key travels. Tracing :

    • key=2 vs {1}: 1 comparison, 0 shifts.
    • key=3 vs {1,2}: 1 comparison, 0 shifts.
    • key=5 vs {1,2,3}: 1 comparison, 0 shifts.
    • key=4 vs {1,2,3,5}: compares with 5 (shift), then with 3 (stop) → 2 comparisons, 1 shift.

    Total , shifts = 1.

    Option A claims — wrong because , not 4.

    Option B: — true.

    Option C: IS performs exactly 1 swap/shift — true.

    Option D: BS in passes 2, 3, 4 compares pairs already in correct order (e.g. 1 and 2 in pass 2); IS compares 4 with 5 which are out of order but the stop-comparison with 3 is against an element already in correct relative position — both algorithms make at least one such comparison. True.

    Verification: re-running both algorithms on confirms , 1 IS shift, and unnecessary comparisons in both.

    Answer: B, C, D.

    Question 2 · Programming, Data Structures and Algorithms · 2025 MSQ

    Suppose that insertion sort is applied to the array and it takes exactly two swaps to sort the array. Select all possible values of .

    1. A.

    2. B.

    3. C.

    4. D.

    Correct Answer:

    ["C"]

    Step-by-Step Solution

    Insight: This is the classic 'unknown element in a nearly sorted array' pattern recognisable because a sorted or nearly sorted array contains one unknown and the total number of swaps (inversions) is given. The pivot is the split method: partition the array around and count inversions in each piece.

    Exam route:

    1. Split into Left , , Right .
    2. Count inversions within Left: 0 (perfectly sorted).
    3. Count inversions within Right: 1 (pair (15,13)).
    4. Count inversions involving :
    • With Left: since all Left elements , if then 0 inversions with Left; if , then inversions with Left .
    • With Right :
    • If : 0 inversions with Right.
    • If : 1 inversion (15 > x).
    • If : 2 inversions (15 > x and 13 > x).
    • If : 2 inversions with Right, plus inversions with Left.
    1. Total inversions .

    So .

    1. Case analysis:
    • : , (since all Left ). Sum = 0. No.
    • : , (since all Left ). Sum = 1. ✓
    • (i.e. ): , . Sum = 2. No.
    • : , . Sum . No.
    1. So . Among the options , only 14 is valid.

    Learning route:

    The split method works because inversions decompose additively:

    Here and , so we need .

    Since all Left elements are , any gives . Then we need , which means exactly one of is greater than . This happens iff , i.e. .

    Verification: for , inversions are (15,13) and (15,14) — total 2 ✓. For , inversions are (15,13), (11,10), (15,10), (13,10) — total 4 ✗.

    Answer: C (only 14).

    Question 3 · Programming, Data Structures and Algorithms · 2024 MCQ
    Consider the following sorting algorithms:
    Bubble sort
    Insertion sort
    Selection sort
    Which ONE among the following choices of sorting algorithms sorts the numbers
    in the array [4, 3, 2, 1, 5] in increasing order after exactly two passes over the array?
    1. A.

      only

    2. B.

      only

    3. C.

      and only

    4. D.

      and only

    Correct Answer:

    B

    Step-by-Step Solution

    Insight: This is a pass-state question recognisable because it asks which algorithm(s) fully sort a specific array in exactly two passes. The pivot is the invariant each algorithm guarantees after passes: Bubble locks the largest at the right, Selection locks the smallest at the left, Insertion sorts the first elements.

    Exam route:

    1. Apply each algorithm for 2 passes on .
    2. Bubble pass 1: swap, swap, swap, no swap → .

    Bubble pass 2: swap, swap, no, no → . Not sorted.

    1. Insertion pass 1 (key=3): shift 4 → .

    Insertion pass 2 (key=2): shift 4, shift 3 → . Not sorted.

    1. Selection pass 1: min of is 1, swap with index 0 → .

    Selection pass 2: min of is 2, swap with index 1 → . Sorted!

    1. Only Selection (iii) sorts in exactly 2 passes. Answer: B.

    Learning route:

    The array has a special structure: the first four elements are reverse-sorted and the last is already the maximum.

    • Bubble Sort bubbles the largest element to the end in pass 1, but the remaining four elements are still reverse-sorted and need 3 more passes. After 2 passes, the array is — not sorted.
    • Insertion Sort sorts a growing prefix. After 2 passes, only the first 3 elements are sorted; the 1 at index 3 is still out of place.
    • Selection Sort places the smallest element at the front each pass. Pass 1 places 1, pass 2 places 2. Since the remaining elements are already sorted, the array is fully sorted after 2 passes.

    Verification: re-tracing confirms only Selection produces after exactly 2 passes.

    Answer: B.

    More previous year questions (pyqs) in this unit