Be able to trace the tree-traversal algorithms:
- pre-order
- post-order
- in-order
Pre-order traversal is when you visit the parent first, and then the left then right child.
To spot a pre-order traversal you will start at the root and then traverse left.
- Start at root node
- Explore the left sub-tree, working top-down
- Explore the right sub-tree, working top-down
In-order traversal is where you visit the left child, the parent and then the right child.
To spot in-order traversal you will start at the left most child (the deepest left child).
- Explore the left sub-tree, working bottom-up
- Visit root node
- Explore the right sub-tree, working bottom-up
Post-order traversal is when you visit the left child, the right child and then the parent.
- Explore the left sub-tree, working bottom-up
- Explore the right sub-tree, working bottom-up
- Visit root node
Be able to describe uses of tree-traversal algorithms.
Pre-Order: copying a tree.
In-Order: binary search tree, outputting the contents of a binary search tree in ascending order.
Post-Order: Infix to RPN (Reverse Polish Notation) conversions, producing a postfix expression from an expression tree, emptying a tree.