The GATE Grind

GATE 2013 CS (CS1) – Question 16

Algorithms · Searching, Sorting and Hashing · 1 mark · Multiple choice

What is the tightest upper bound on swaps used by selection sort on n numbers?

  1. $O(\log n)$
  2. $O(n)$
  3. $O(n\log n)$
  4. $O(n^2)$

Practise this question in The GATE Grind →

Show answer and explanation

Correct answer: (B) $O(n)$

Explanation

Selection sort selects a minimum for each successive position and performs at most one swap per pass. There are n−1 passes, giving O(n) swaps, B, despite its Θ(n²) comparisons.

More Searching, Sorting and Hashing questions

All Searching, Sorting and Hashing questions →