Bifalgorithm post · Brisk · Chapter 1
How is a tree traversed in pre-order?
How is a tree traversed in pre-order? (Brisk · Chapter 1) — "and traverse it in its entirety. 3. Do the same with the right child. It’s tricky because you have…
Ideas in this flowchart
- Pre-order traversal of a tree
- Visit the current node first.
- Treat each child as a subtree and apply the complete traversal process.
- Traverse the left subtree.
- After finishing the left subtree, traverse the right subtree.
- Remember where you were so you can return after completing a subtree.
- Example: begin the traversal by visiting G.
- Traverse G’s entire left subtree, beginning with K.
- Within K’s subtree, visit D, then O and I, return to K, and visit M, C, and E.
- After completing G’s left subtree, traverse its right subtree: H, A, B, F, N, and L.
- The complete visitation order is G, K, D, O, I, M, C, E, H, A, B, F, N, L.
