Introduction to sorting - CompassProduce a fully sorted sequenceDo so with correctness and ideally efficiencyWhere Sorting Algorithms Are Helpful
Sorting is a foundational tool in computer science and appears in many real tasks:
- Binary search requires sorted data
- Many dynamic programming and greedy algorithms sort first
- Ranking students by scores
- Detecting duplicates (after sorting, equal items are adjacent)
- Sorting points by x-coordinate
- Sorting edges by weight (e.g., Kruskal’s MST algorithm)
- Sorting tasks by deadlines or durations
Simple Sorting Algorithms
- Bubble Sort — swaps adjacent elements if they’re wrong.
- Selection Sort — picks the smallest element and places it correctly.
- Insertion Sort — inserts each element into its correct position in the sorted prefix.