Skip to content
dsa/roadmap
← All chapters
Chapter 08Weeks 13–15Phase 3 ~4 h

Advanced Sorting & Searching

Heap, quick, merge and shell sort, then hashing for near-instant search.

  1. 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
  2. 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
  3. 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
  4. 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
  5. 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

Keyboard shortcuts

⌘K /
Search topics, glossary, cheat sheets
space
Play / pause the visualizer
← →
Step back / forward
r
Reset the visualizer
?
Show this help