AlgoViz

Tree DFS

easy 18 min

Depth-first search walks a tree by going as deep as possible down one branch before backing up to try the next.

Chapter mnemonic

Three tree traversal orders

Kids stay left to right. When does Dad get his photo?

If Dad is photographed between his two children, which traversal is that?

Inorder. Visit the left subtree, then the root, then the right subtree.