<aside> 📚

L5: Make Friends with Trees covers trees in general (definition, terminology), binary trees (structure, node counts, expression trees), implementing binary trees in Java (Node class with left/right/parent), binary search trees (recursive definition, search, inorder traversal, non-recursive traversal with stack), implementing sets with BSTs, the Comparable interface, and tree iterators.

</aside>

📋 At a Glance

<aside> 📅

Week 9 Feb (w/c 9 Feb) — Lecture 5 of 26 | Tutorial 3 applies

</aside>

<aside> 💡

Key principle: Binary search trees keep elements ordered so that search follows a single path from root to leaf. The worst-case number of comparisons equals the height of the tree — a balanced tree gives O(log n) search, but an unbalanced one degrades to O(n).

</aside>


1. Trees: Definition and Terminology

Mathematically, a tree is an acyclic undirected graph: