Skip to main contentSkip to solution

What is the time complexity of a Selection Sort?

Solution

✅ Correct Option: 2

Selection sort scans the unsorted part to find the minimum, then swaps it into place. The number of comparisons is the same for every input, whether sorted, reversed or random.

(n−1)+(n−2)+⋯+1=n(n−1)2=O(n2)(n-1) + (n-2) + \dots + 1 = \dfrac{n(n-1)}{2} = \boxed{O(n^2)}

Keyboard Shortcuts

  • Left arrow: Previous question
  • Right arrow: Next question
  • S key: Jump to solution
  • Q key: Jump to question