Arrays and linked lists put things in a line. A lot of the world isn't a line — it branches. And branching turns out to be the key to searching huge amounts of data in a handful of steps. Those are the two big reasons trees exist.
Whenever things contain other things, you have a tree:
(2 + 3) × 4 becomes the tree on the right, and evaluating it is a tree walk.Only trees with at most two children per node are *binary* trees, and many of these hierarchies have more. But binary trees are the ones interviews and data structure libraries are built on, and everything you learn here carries over.
Free account
Sign up to read the rest of this lesson: 4 more sections, 3 drawings, a dry-run simulator and code in JavaScript, Python, Java and C++.
Still to come