Skip to content
GATEiit

GATE DA 2024 Q30: Swaps by Quicksort with last-element pivot on a sorted array

Question

Consider sorting the following array of integers in ascending order using an in-place Quicksort algorithm that uses the last element as the pivot.

60 70 80 90 100

The minimum number of swaps performed during this Quicksort is ______.

Try it: numerical answer: type the value

Numerical answer. No negative marking.
Show answer and explanation

Answer: 0 (official GATE 2024 final answer key)

Concept used: Quicksort partitioning only needs to swap elements that are on the wrong side of the pivot.

First step: In a sorted array every element is already on the correct side of each pivot, so no exchange of distinct positions is needed.

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