Showing Posts From

Trees

Advanced Binary Tree & BST

Advanced Binary Tree & BST

Week 22 notes: the harder tree problems, where a node has to report several facts to its parent at once. The return-tuple DFS pattern, lowest common ancestor, path sums, and serialize/deserialize.

N-ary Trees: Traversal & Encoding

N-ary Trees: Traversal & Encoding

Week 13 notes: once a node can have any number of children, the binary-tree patterns still work, you just loop over children. Plus encoding an N-ary tree as a binary one.

Tries: Prefix Trees for Fast Lookups

Tries: Prefix Trees for Fast Lookups

Week 12 notes: a trie stores strings by shared prefixes, so lookup and prefix search depend on word length, not how many words you've got. Where autocomplete comes from.

Binary Search Trees: Order, Search & Balance

Binary Search Trees: Order, Search & Balance

Week 11 notes: a BST keeps values ordered so search, insert, and delete are O(h). The invariant, why inorder comes out sorted, and why balance is everything.

Binary Trees: Traversals & DFS / BFS

Binary Trees: Traversals & DFS / BFS

Week 10 notes: binary trees are basically recursion you can draw. The three DFS orders, level-order BFS, and the one move that solves most tree problems.