← All chapters
Chapter 08Weeks 13–15Phase 3 ~4 h
Advanced Sorting & Searching
Heap, quick, merge and shell sort, then hashing for near-instant search.
- 8.1Shell SortInsertion sort on items a gap apart, with the gap shrinking to 1. Far-away items move in big jumps, so the final insertion sort has little work left. 35 minmedium
- 8.2Quick SortPick a pivot, partition so smaller items go left and bigger items go right, then sort each side recursively. Average O(n log n), worst O(n²). 55 minhard
- 8.3Merge SortSplit the array in half, sort each half recursively, then merge the two sorted halves. Always O(n log n), stable, but needs O(n) extra space. 50 minmedium
- 8.4Heap SortBuild a max-heap in the array, then repeatedly swap the root (the largest item) to the end and sift down. O(n log n) in every case, in-place. 55 minhard
- 8.5Hashing BasicsA hash function turns a key into an array index, so search is O(1) on average. Collisions, separate chaining, linear probing and the load factor. 45 minmedium