Sorting AlgorithmsΒΆ
Prerequisites: Arrays, Loops
Learning ObjectivesΒΆ
- Understand why sorting is required.
- Compare common sorting techniques.
- Choose a suitable algorithm by input size.
Why Sorting MattersΒΆ
Sorted data improves readability, search speed, ranking, and report generation.
Core AlgorithmsΒΆ
- Bubble Sort: simple, educational, O(n^2).
- Selection Sort: fewer swaps, still O(n^2).
- Insertion Sort: good for small/nearly-sorted data.
- Merge/Quick Sort: better for large datasets.
Complexity SnapshotΒΆ
- Bubble/Selection/Insertion: O(n^2)
- Merge Sort: O(n log n)
- Quick Sort: average O(n log n), worst O(n^2)
Practical ExampleΒΆ
Marks [67, 82, 45, 91] sorted ascending become [45, 67, 82, 91].
Practice TasksΒΆ
- Implement bubble sort with pass-by-pass output.
- Count comparisons and swaps for selection sort.
- Compare runtime for n=100 and n=1000.
SummaryΒΆ
Start with simple sorts for understanding, then move to O(n log n) for scale.