Selection Sort
Repeatedly selects the minimum element and places it into its final position — simple and predictable.
Selection Sort works like organizing books: for each shelf spot, you scan the remaining pile to find the smallest book and place it where it belongs. It’s easy to understand because each pass “locks in” one final element.
What It Does
Selection Sort divides the array into two regions: a sorted left side and an unsorted right side. On each pass, it finds the minimum element in the unsorted region and swaps it into the next sorted position.
How It Works
- Set the boundary: position
iis where the next smallest value should go. - Scan the unsorted portion
i..n-1to find the index of the minimum value. - Swap the minimum value into position
i. - Move i forward and repeat until the list is sorted.
Why It’s Useful
Selection Sort is valuable for learning because it has a clear structure and predictable behavior: each pass permanently places one element. It can be useful when swap cost is low and you want a simple algorithm with a small code footprint.
Performance Notes
- Time: always
O(n²)comparisons (even if nearly sorted). - Space:
O(1)extra space (in-place). - Stable: typically no (swaps can reorder equal values).
Pitfalls (Student Mistakes)
- Swapping too early: you must finish the scan before swapping.
- Wrong min index: forgetting to reset the minimum at the start of each pass.
- Unnecessary swaps: swapping even when the minimum is already at position
i. - Stability confusion: assuming equal elements keep order (usually not true with swaps).
Demo / Media
Animation
The animation emphasizes the scan to find the minimum, the selected index, and the final swap that locks the next element into the sorted region.
UX/UI • Pedagogy • HCI
A short teaching-focused rationale: what I designed, how I structured learning, and the interaction principles behind it.
- Information architecture: definition → steps → notes → pitfalls → demo.
- Visual hierarchy: cards separate “scan” vs “swap” so learners don’t mix the phases.
- Clear CTA: “Watch Demo” scrolls to the video (low navigation cost).
- Consistency: same layout pattern across all algorithm pages.
- Accessibility: readable type/spacing + native video controls +
playsinline.
- Scaffolded learning: concept (“pick smallest”) → method (scan) → action (swap) → repeat.
- Three-act structure: what it is → how it works → why it matters (+ demo).
- Cognitive load: one job per pass keeps beginner mental overhead low.
- Worked example: demo shows the scan visually before the swap occurs.
- Self-check: pitfalls address common misconceptions (swap timing, stability).
- Mental models: “sorted region grows” gives a stable progress cue after each swap.
- Recognition over recall: repeated terms (scan, minimum, swap) reinforce understanding.
- Error prevention: pitfalls warn about swapping early and forgetting to reset min index.
- Feedback cues: demo makes the “minimum found → placed” cause/effect obvious.
- Usability heuristics: clarity, consistency, predictable navigation.
Teaching strategy: scaffold → demonstrate → self-check. This supports beginner confidence while keeping the interface simple and consistent.