GATE DA 2026 | Question 49

Programming, Data Structures and Algorithms › Sorting · MSQ · 2 marks · Answer: B, C, D

  1. Question 49Programming, Data Structures and Algorithmsmsq2 marks
    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?
    • A.
      N1 = 10, N2 = 4
    • B.
      N1 > N2
      ✓
    • C.
      IS on P will perform only one swap
      ✓
    • D.
      Both BS and IS on P will make at least one unnecessary comparison (i.e., comparing elements that are already in correct order)
      ✓

    Answer: B, C, D

    Solution

    Insertion sort, inserting each element into the sorted prefix: - Inserting 2: 1 comparison (with 1). - Inserting 3: 1 comparison (with 2). - Inserting 5: 1 comparison (with 3). - Inserting 4: compare with 5 and shift, then compare with 3 and stop. 2 comparisons, 1 swap. So , with exactly one swap. Bubble sort: the standard version does comparisons. Even the early-exit version does (the second pass makes no swaps). Either way . - (A) , not 4. False. - (B) True. - (C) True. - (D) Both compare already-ordered pairs such as (1, 2). True. Answer: (B), (C), (D).

More GATE PYQ on Sorting

All GATE DA Programming, Data Structures and Algorithms PYQ →

Attempt GATE DA 2026 in real GATE exam mode

Full paper with a timer, the GATE interface and a topic-wise analysis — free.

Create free account →