11.3 Tree Traversal Flashcards
Universal Address Systems
A way to totally order the vertices of and ordered rooted tree. We do this recursively:
• Label the root with the integer 0. Then label its k children (at level 1) from left to right with
1, 2, 3, . . . , k.
• For each vertex v at level n with label A, label its kv children, as they are drawn from left to
right, with A.1, A.2, . . . , A.kv.
ex. The lexicographic ordering for this tree is 0
PreOrder Traversal
Root->Left->Right
InOrder Traversal
Left->Root->Right
PostOrder Traversal
Left->Right->Root
PostOrder Traversal
Left->Right->Root
A tree used to solve arithmetic
Internal vertices: operations
Leaves: variables or numbers
Infix Notation
produces the original expression with
the elements and operations in the same order as they originally occurred, except unary operations.
The fully parenthesized expression is the infix form.
Infix form: (6 − 4) ∗ (3 + (5 − 1))
Prefix Notation
obtained by traversing its rooted tree in preorder. Binary
operator precedes its two operands. Evaluate an expression in prefix form by working right to left.
Prefix form: ∗ − 64 + 3 − 51
Postfix Notation
obtained by traversing its rooted tree in postorder. Binary operator follows its two operands. Evaluate an expression in postfix form by working left to right.
Postfix form: 64 − 351 − +∗