Selection sort
How it works
Selection Sort finds the smallest element in the list and moves it to the correct position, one step at a time, like selecting the best items from a messy shelf.
-
πΉ Search through the list to find the smallest item β Swap it with the first unsorted position β Repeat until sorted.
-
πΉ Best & worst case: Always O(nΒ²) since it searches the entire list every time.
-
πΉ Why learn it? It's easy to understand and doesn't need extra memory.
π Think of it as: Picking the shortest friend in a line and moving them to the front.
How it works in code
How to play
Goal: Find and move the smallest element into the correct position.
Buttons:
-
Next βοΈ β Move through the list to find the smallest element.
-
Select π― β Marks the smallest element found.
-
Move π β Moves the selected element to the correct position on the left.
-
Submit β β Checks if the list is fully sorted.
π Tip: Once an element is sorted, it turns green and becomes part of the final list!
Time:
0:60
Lives:
β€οΈβ€οΈβ€οΈ