Upload
liliana-cain
View
212
Download
0
Embed Size (px)
Citation preview
10.3 Tree Transversal
Pre/post fix notation and order• See
handout. a
. b c
. d e f g
h i j k
Preorder transversal- root first, then left to right
• a
. b c
. d e f g
h i j k
Inorder transversal- left tree, then root, then rest of trees- left to right
• a
b c
d e f g
h i j k•
Postorder transversal- left to right, then root last
• a
. b c
. d e f g
h i j k
Infix, prefix, and postfix• See handout• Infix order is ambiguous – so parentheses are
required• Prefix and postfix are not– so parentheses are
unnecessary• Prefix- “Polish notation”– Read from R to L– Operations are on the L
• Postfix– Read from L to R– Operations are on the R
Example– transverse in 3 ways, and evaluate each notation
+
*
3 2 5 2
• Preorder- prefix
• Inorder-infix
• Postorder-postfix
Example- prefix
• Evaluate a prefix expression+ - * 2 3 5 / 2 3 4
Ex- postfix
7 2 3 * - 4 9 3 / +
Example– transverse in 3 ways, and evaluate each notation
+
*
5 2 3 4
• Preorder- prefix
• Inorder-infix
• Postorder-postfix
-
*
Find the value of each prefix expression (R to L,operations on the L)
• - * 2 / 8 4 3
• - * 3 3 * 4 2 5
Find the value of each prefix expression (R to L,operations on the L)
• + - 3 2 2 3 / 6 – 4 2
• * + 3 + 3 3 + 3 3 3
Find the value of each postfix expression (L to R, operations on R)
• 5 2 1 - - 3 1 4 + + *
Find the value of each postfix expression (L to R, operations on R)
• 9 3 / 5 + 7 2 - *
• 3 2 * 2 5 3 – 8 4 / * -