Home
/
Tutorials
/
Selection Sort - Practice & Quiz Selection Sort - Practice & Quiz Algorithms Sorting Selection Sort
You’ve learned selection sort. Let’s see how well you understand it.
Knowledge Check This interactive quiz requires JavaScript to be enabled.
Question 1: What is the time complexity of selection sort in all cases? A. O(n) B. O(n log n) C. O(n²) (Correct) D. O(2ⁿ) Explanation: Selection sort always has O(n²) time complexity because it always performs the same number of comparisons regardless of input order.
Question 2: How many swaps does selection sort make in the worst case? A. O(n) (Correct) B. O(n log n) C. O(n²) D. O(1) Explanation: Selection sort makes at most n-1 swaps, one per pass, giving O(n) swaps. This is one advantage over bubble sort.
Question 3: Is selection sort stable? A. Yes, always B. No, never (Correct) C. Sometimes D. Depends on implementation Explanation: Selection sort is not stable because it may change the relative order of equal elements when swapping.
Question 4: What is the main advantage of selection sort over bubble sort? A. Faster time complexity B. Fewer swaps (Correct) C. Stable sorting D. Better for sorted arrays Explanation: Selection sort makes O(n) swaps compared to bubble sort's O(n²) swaps, which is its main advantage.
Implement selection sort:
Run code to see output...
You’ve mastered:
✅ Selection Sort Algorithm : Find minimum, swap, repeat
✅ Implementation : Nested loops with minimum finding
✅ Complexity : O(n²) time, O(1) space
✅ Characteristics : Few swaps, not stable, always O(n²)
✅ When to Use : Educational, small datasets, minimal swaps needed
With selection sort knowledge, you can:
Understand sorting fundamentals
Implement simple sorting
Appreciate why better algorithms exist
Solve basic sorting problems
Build intuition for algorithm analysis
Practice with more sorting problems
Learn faster algorithms (quicksort, mergesort)
Study algorithm analysis techniques
Explore other O(n²) sorting algorithms
Great job completing this tutorial!
Discussion
Loading comments...