Bifalgorithm post · Brisk · Chapter 1
How does in-order traversal position the root between its subtrees?
How does in-order traversal position the root between its subtrees? (Brisk · Chapter 1) — "Finally, to traverse a tree in-order, we: 1. Treat the left child an…
Ideas in this flowchart
- In-order traversal visits each node between its left and right subtrees.
- Traverse the left child and all of its descendants as a complete subtree.
- Visit the root node.
- Traverse the right subtree as a complete subtree.
- Unlike pre-order or post-order, in-order traversal visits the root between its children.
- In the sample tree, D is visited first because it has no left subtree.
- After D, O and I are visited for the same reason.
- K is visited before its right subtree, which visits C, M, and E in that order.
- The complete visitation order is D, O, I, K, C, M, E, G, A, H, F, B, L, N.
- If nodes are evenly spaced, the order can be read from left to right in the diagram.
- Spatial position does not determine the traversal order; relationships between nodes do.
- Moving I farther right would not change the order or make K visited earlier.
- The node-visitation order is shown in a figure.
