Binary Trees and the Recursive Mind-Shift
Until now, the data structures you've built have been flat. Arrays are a row of values; linked lists are a chain. You walk them with a loop. Trees break that pattern in a specific…
Trees and Priority Queues covers: Binary Trees and the Recursive Mind-Shift, Binary Search Trees, Balanced BSTs, B-Trees, Heaps, Priority Queues, and Heap Sort. Year 1, Quarter 2. Includes 21 exercises and 2 projects.
This course unlocks once you've finished its prerequisite. Open prerequisite →
Until now, the data structures you've built have been flat. Arrays are a row of values; linked lists are a chain. You walk them with a loop. Trees break that pattern in a specific…
You ended the last lesson with an inorder traversal that printed 1, 3, 4, 5, 8, 9, 11 — sorted. That wasn't an accident. The tree was a Binary Search Tree, a binary tree where eve…
You ended the last lesson with the BST that degenerated into a linked list when given sorted input. The fix isn't a different data structure — it's the same BST with one more inva…
A binary search tree gives you O(log₂ n) operations. For n = 1 billion that's ~30 comparisons. Sounds fast. Now consider where the tree lives: if it's on a spinning disk (or even …
A regular queue is fair: oldest in, oldest out. But almost every system you've ever used violates that fairness for a reason — the OS's process scheduler runs urgent tasks before …
- [ ] Invert Binary Tree (#226) — NC/LC — Recursive swap of left/right children - [ ] Maximum Depth of Binary Tree (#104) — NC/LC — Recursive or BFS depth calculation - [ ] Diamet…
- [ ] Binary Tree Level Order Traversal (#102) — NC/LC — BFS with level tracking - [ ] Validate Binary Search Tree (#98) — NC/LC — Inorder traversal or min/max range - [ ] Kth Sma…
- [ ] Binary Tree Maximum Path Sum (#124) — NC/LC — DFS tracking max path through each node - [ ] Serialize and Deserialize Binary Tree (#297) — NC/LC — Preorder with null markers…
- [ ] Build a Huffman encoder/decoder in Ruby — construct the Huffman tree from character frequencies using a priority queue, generate prefix codes, compress and decompress a text…
Build a min-heap-based priority queue in Ruby. Use it to implement a task scheduler where tasks have priorities and deadlines. Support addtask, nexttask, peek, updatepriority. Wri…
Implement a BST and AVL tree in Ruby. After each insertion or deletion, print the tree structure as ASCII art (showing the tree shape with node values). Demonstrate how the AVL tr…
- [ ] What are the four tree traversals (inorder, preorder, postorder, level-order)? When would you use each? - [ ] What is a Binary Search Tree? What is its worst-case time compl…
12 lessons. Read in order; spiral back when you need to. By the end you'll have used the core ideas twice — once on the abstract, once on something you'll meet at work next week.