Skip to content
GATEiit

GATE DA 2024 Q45: Sorting algorithm that sorts [4, 3, 2, 1, 5] in two passes

Question

Consider the following sorting algorithms:

(i) Bubble sort

(ii) Insertion sort

(iii) 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?

Try it: multiple choice: exactly one correct option

Select one option
Wrong answer costs 2/3 mark in GATE.
Show answer and explanation

Answer: B (official GATE 2024 final answer key)

Concept used: What one pass of each simple sort guarantees.

First step: Selection sort swaps 1 to the front, then 2 into place: [1, 2, 3, 4, 5]. Bubble sort gives [2, 1, 3, 4, 5]; insertion sort gives [2, 3, 4, 1, 5].

Full step-by-step solution

Detailed working, common mistakes and linked mock tests will be available with a free GATEiit account. Log-in is coming soon.

Share this question

WhatsAppDownload image

Source: official GATE 2024 DA question paper and final answer key, organised by IISc Bangalore. Question paper · Answer key