Bifalgorithm post · Brisk · Chapter 1
How does post-order traversal visit the nodes of a tree?
How does post-order traversal visit the nodes of a tree? (Brisk · Chapter 1) — "It’s the same as pre-order, except that we visit the root after the children in…
Ideas in this flowchart
- Post-order traversal of a tree
- The root is visited after its left and right subtrees, unlike in pre-order traversal.
- The traversal is difficult because node visits are postponed and their later order must be remembered.
- A node can be visited only after both of its subtrees have been completed.
- In the sample tree, I is the first node visited.
- G waits for its subtrees, K waits for its subtrees, D waits for O’s subtree, and O waits for I.
- During the unwinding, K still waits because its right subtree has not been visited.
- The right-subtree visits produce C, E, and M, in that order, before K is visited.
- The complete visitation order is I, O, D, C, E, M, K, A, F, L, N, B, H, and G.
- This order is not the reverse of the pre-order visitation; G is last instead of first, while the remaining order is rearranged.
- The post-order visitation sequence is shown in a figure.
