



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




Universal Address Systems
A way to totally order the vertices of and ordered rooted tree. We do this recursively:
The lexicographic ordering for this tree is 0 < 1 < 1. 1 < 1. 1. 1 < 1. 1. 2 < 1. 2 < 1. 3 < 2 < 2. 1 <
Traversal Algorithms
Preorder Traversal
Let T be an ordered rooted tree with root r. If T consists only of r, then r is the preorder traversal of T. Otherwise, suppose that T 1 , T 2 ,... , Tn are the subtrees at r from left to right in T. The pre- order traversal begins by visiting r. It continues by traversing T 1 in preorder, then T 2 in preorder, and so on, until Tn is traversed in preorder.
Algorithm preorder(T : ordered rooted tree)
1: r = root of T 2: list r 3: for each child c of r from left to right do 4: T (c) = subtree with c as its root 5: preorder(T (c)) 6: end for
Inorder Traversal
Let T be an ordered rooted tree with root r. If T consists only of r, then r is the inorder traversal of T. Otherwise, suppose that T 1 , T 2 ,... , Tn are the subtrees at r from left to right. The inorder traversal begins by traversing T 1 in inorder, then visiting r. It continues by traversing T 2 in inorder, then T 3 in inorder,... , and finally Tn in inorder.
Algorithm inorder(T : ordered rooted tree)
1: r = root of T 2: if r is a leaf then 3: list r 4: else 5: l = first child of r from left to right 6: T (l) = subtree with l as its root 7: inorder(T (l)) 8: list r 9: for each child c of r except for l from left to right do 10: T (c) = subtree with c as its root 11: inorder(T (c)) 12: end for 13: end if
Postorder Traversal
Let T be an ordered rooted tree with root r. If T consists only of r, then r is the postorder traversal of T. Otherwise, suppose that T 1 , T 2 ,... , Tn are the subtrees at r from left to right. The postorder traversal begins by traversing T 1 in postorder, then T 2 in postorder,... , then Tn in postorder, and ends by visiting r.
Algorithm postorder(T : ordered rooted tree)
1: r = root of T 2: for each child c of r from left to right do 3: T (c) = subtree with c as its root 4: postorder(T (c)) 5: end for 6: list r
Infix, Prefix, and Postfix Notation
Complicated expressions, such as compound propositions, combinations of sets, and arithmetic expressions can be represented by ordered root trees. For arithmetic expressions:
The lexicographic ordering is 0 < 1 < 1. 1 < 1. 2 < 2 < 3.
11.3 pg. 783 # 7
Determine the order in which a preorder traversal visits the vertices of the given ordered rooted tree.
The preorder traversal is: a, b, d, e, f, g, c.
11.3 pg. 783 # 11
Determine the order in which an inorder traversal visits the vertices of the given ordered rooted tree.
The inorder traversal is: d, b, i, e, m, j, n, o, a, f, c, g, k, h, p, l.
11.3 pg. 783 # 13
Determine the order in which a postorder traversal visits the vertices of the given ordered rooted tree.
The postorder traversal is: d, f, g, e, b, c, a