1
COMP 250
Lecture 21
binary trees, expression trees
- Oct. 27, 2017
expression trees Oct. 27, 2017 1 Binary tree: each node has at - - PowerPoint PPT Presentation
COMP 250 Lecture 21 binary trees, expression trees Oct. 27, 2017 1 Binary tree: each node has at most two children. 2 Maximum number of nodes in a binary tree? Height (e.g. 3) 3 Maximum number of nodes in a binary tree? Height
1
2
3
4
5
6
7
depthFirst(root){ if (root is not empty){ visit root for each child of root depthFirst( child ) } }
8
preorder(root){ if (root is not empty){ visit root for each child of root preorder( child ) } }
9
preorderBT (root){ if (root is not empty){ visit root preorderBT( root.left ) preorderBT( root.right ) } } preorder(root){ if (root is not empty){ visit root for each child of root preorder( child ) } }
10
11
12
13
14
a b c d e f g
15
a b c d e f g
16
a b c d e f g
17
a b c d e f g
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
(after Polish logician Jan Lucasewicz 1920’s)
35
(after Polish logician Jan Lucasewicz 1920’s)
36
37
38
39
40
41
42
e f g / * a d + b c
This expression tree is not given. It is shown here so that you can visualize the expression more easily.
43
e f g / * a d + b c
This expression tree is not given. It is shown here so that you can visualize the expression more easily.
44
e f g / * a d + b c
45
e f g / * a d + b c
46
e f g / * a d + b c
47
e f g / * a d + b c
48
e f g / * a d + b c
49
e f g / * a d + b c
50
e f g / * a d + b c
51
52
53