AI InterviewSearch…Search problems, topics, or pages…Ctrl KGet started
Easysortingstability

~60s

Which sort is unstable

Which of these sorting algorithms is not stable in its usual implementation?

Show the answer and the worked solution

Correct answer: D.

Quicksort

Worked solution

  1. Bubble sort and insertion sort move elements only past strictly larger neighbours, so equal keys never cross each other.
  2. Merge sort stays stable by taking from the left run whenever two keys tie.
  3. Quicksort swaps elements across long distances during partitioning, which can push one equal key past another, so it is the unstable one.

Answer: Quicksort.

The idea

Stability matters when records are sorted by one field after another. Heapsort and selection sort are the other classic unstable sorts, for the same reason: they move elements far from where they started.

Shortcut. Instability comes from long-distance swaps; of these four only quicksort's partition makes them, while the other three never move one equal key past another.

Common trap. "Merge sort" splits and recombines, so it looks as if it could scramble equal keys, but taking from the left run on a tie keeps it stable.

Which sort is unstable — Aptitude Question

Which sort is unstable: Which of these sorting algorithms is not stable in its usual implementation? Answer and worked solution on CodeKairo.

Question

Which of these sorting algorithms is not stable in its usual implementation?

Options

  1. Bubble sort
  2. Insertion sort
  3. Merge sort
  4. Quicksort
Show the answer and the worked solution

Correct answer: D. Quicksort

Worked solution

  1. Bubble sort and insertion sort move elements only past strictly larger neighbours, so equal keys never cross each other.
  2. Merge sort stays stable by taking from the left run whenever two keys tie.
  3. Quicksort swaps elements across long distances during partitioning, which can push one equal key past another, so it is the unstable one.

Answer: Quicksort.

The idea

Stability matters when records are sorted by one field after another. Heapsort and selection sort are the other classic unstable sorts, for the same reason: they move elements far from where they started.

Shortcut. Instability comes from long-distance swaps; of these four only quicksort's partition makes them, while the other three never move one equal key past another.

Common trap. "Merge sort" splits and recombines, so it looks as if it could scramble equal keys, but taking from the left run on a tie keeps it stable.

All Data Structures & Algorithms questions · placement mock tests