Walking a tree
Lesson 14 of 20 · Algo.Micro
Pre-order, in-order and post-order: three ways to visit every node.
A tree is a node plus two smaller trees, so walking it is naturally recursive. Pre-order visits the node first, then the left subtree, then the right. The output line grows at the bottom.
Check yourself
Which traversal lists a BST in sorted order?
Do it in the browser: a real algorithms tool, a short mission and instant feedback. No install.
Start this lesson — free