logo. trees: in these slides: introduction to trees applications of trees tree traversal 2
TRANSCRIPT
![Page 1: LOGO. Trees: In these slides: Introduction to trees Applications of trees Tree traversal 2](https://reader038.vdocuments.site/reader038/viewer/2022110210/56649eab5503460f94bb0408/html5/thumbnails/1.jpg)
LOGO
LOGO
D i s c r e t e S t r u c t u r e s
Instructor: Dr. Ali Movaghar
Sharif University of Technology Fall 1389
In The Name of Allah
![Page 2: LOGO. Trees: In these slides: Introduction to trees Applications of trees Tree traversal 2](https://reader038.vdocuments.site/reader038/viewer/2022110210/56649eab5503460f94bb0408/html5/thumbnails/2.jpg)
LOGO
2
Trees:
In these slides: • Introduction to trees• Applications of trees• Tree traversal
Dis
cret
e S
truc
ture
s
Fal
l 138
9
![Page 3: LOGO. Trees: In these slides: Introduction to trees Applications of trees Tree traversal 2](https://reader038.vdocuments.site/reader038/viewer/2022110210/56649eab5503460f94bb0408/html5/thumbnails/3.jpg)
LOGO
3
Introduction to
Trees
Dis
cret
e S
truc
ture
s
Fal
l 138
9
![Page 4: LOGO. Trees: In these slides: Introduction to trees Applications of trees Tree traversal 2](https://reader038.vdocuments.site/reader038/viewer/2022110210/56649eab5503460f94bb0408/html5/thumbnails/4.jpg)
LOGO
4
Introduction to TreesA tree is a connected undirected graph that
contains no circuits. Theorem: There is a unique simple path between any
two of its nodes.
Dis
cret
e S
truc
ture
s
Fal
l 138
9
![Page 5: LOGO. Trees: In these slides: Introduction to trees Applications of trees Tree traversal 2](https://reader038.vdocuments.site/reader038/viewer/2022110210/56649eab5503460f94bb0408/html5/thumbnails/5.jpg)
LOGO
5
Introduction to TreesA tree is a connected undirected graph that
contains no circuits. Theorem: There is a unique simple path between any
two of its nodes.
A (not-necessarily-connected) undirected graph without simple circuits is called a forest. You can think of it as a set of trees having disjoint sets
of nodes.
Dis
cret
e S
truc
ture
s
Fal
l 138
9
![Page 6: LOGO. Trees: In these slides: Introduction to trees Applications of trees Tree traversal 2](https://reader038.vdocuments.site/reader038/viewer/2022110210/56649eab5503460f94bb0408/html5/thumbnails/6.jpg)
LOGO
6
Introduction to TreesA tree is a connected undirected graph that
contains no circuits. Theorem: There is a unique simple path between any
two of its nodes.
A (not-necessarily-connected) undirected graph without simple circuits is called a forest. You can think of it as a set of trees having disjoint sets
of nodes.
A leaf node in a tree or forest is any pendant or isolated vertex. An internal node is any non-leaf vertex (thus it has degree ≥ ? ).
Dis
cret
e S
truc
ture
s
Fal
l 138
9
![Page 7: LOGO. Trees: In these slides: Introduction to trees Applications of trees Tree traversal 2](https://reader038.vdocuments.site/reader038/viewer/2022110210/56649eab5503460f94bb0408/html5/thumbnails/7.jpg)
LOGO
7
Introduction to TreesA tree is a connected undirected graph that
contains no circuits. Theorem: There is a unique simple path between any
two of its nodes.
A (not-necessarily-connected) undirected graph without simple circuits is called a forest. You can think of it as a set of trees having disjoint sets
of nodes.
A leaf node in a tree or forest is any pendant or isolated vertex. An internal node is any non-leaf vertex (thus it has degree ≥ 2 ).
Dis
cret
e S
truc
ture
s
Fal
l 138
9
![Page 8: LOGO. Trees: In these slides: Introduction to trees Applications of trees Tree traversal 2](https://reader038.vdocuments.site/reader038/viewer/2022110210/56649eab5503460f94bb0408/html5/thumbnails/8.jpg)
LOGO
8
Tree and Forest Examples
A Tree:A Forest:
Leaves in green, internal nodes in brown.
Dis
cret
e S
truc
ture
s
Fal
l 138
9
![Page 9: LOGO. Trees: In these slides: Introduction to trees Applications of trees Tree traversal 2](https://reader038.vdocuments.site/reader038/viewer/2022110210/56649eab5503460f94bb0408/html5/thumbnails/9.jpg)
LOGO
9
Rooted Trees
A rooted tree is a tree in which one node has been designated the root. Every edge is (implicitly or explicitly) directed
away from the root.
Dis
cret
e S
truc
ture
s
Fal
l 138
9
![Page 10: LOGO. Trees: In these slides: Introduction to trees Applications of trees Tree traversal 2](https://reader038.vdocuments.site/reader038/viewer/2022110210/56649eab5503460f94bb0408/html5/thumbnails/10.jpg)
LOGO
10
Rooted Trees
A rooted tree is a tree in which one node has been designated the root. Every edge is (implicitly or explicitly) directed
away from the root.
Concepts related to rooted trees: Parent, child, siblings, ancestors, descendents, leaf,
internal node, subtree.
Dis
cret
e S
truc
ture
s
Fal
l 138
9
![Page 11: LOGO. Trees: In these slides: Introduction to trees Applications of trees Tree traversal 2](https://reader038.vdocuments.site/reader038/viewer/2022110210/56649eab5503460f94bb0408/html5/thumbnails/11.jpg)
LOGO
11
Rooted Tree Examples
Note that a given unrooted tree with n nodes yields n different rooted trees.
root
root
Same tree except
for choiceof root
Dis
cret
e S
truc
ture
s
Fal
l 138
9
![Page 12: LOGO. Trees: In these slides: Introduction to trees Applications of trees Tree traversal 2](https://reader038.vdocuments.site/reader038/viewer/2022110210/56649eab5503460f94bb0408/html5/thumbnails/12.jpg)
LOGO
12
Rooted-Tree Terminology Exercise
Find the parent,children, siblings,ancestors, & descendants of node f.
a
b
c
d
e
f
g
h
i
j k l
m
no
p
q
r
root
Dis
cret
e S
truc
ture
s
Fal
l 138
9
![Page 13: LOGO. Trees: In these slides: Introduction to trees Applications of trees Tree traversal 2](https://reader038.vdocuments.site/reader038/viewer/2022110210/56649eab5503460f94bb0408/html5/thumbnails/13.jpg)
LOGO
13
n-ary trees
A rooted tree is called n-ary if every vertex has no more than n children. It is called full if every internal (non-leaf) vertex
has exactly n children.
Dis
cret
e S
truc
ture
s
Fal
l 138
9
![Page 14: LOGO. Trees: In these slides: Introduction to trees Applications of trees Tree traversal 2](https://reader038.vdocuments.site/reader038/viewer/2022110210/56649eab5503460f94bb0408/html5/thumbnails/14.jpg)
LOGO
14
n-ary trees
A rooted tree is called n-ary if every vertex has no more than n children. It is called full if every internal (non-leaf) vertex
has exactly n children.
A 2-ary tree is called a binary tree. These are handy for describing sequences of yes-
no decisions.• Example: Comparisons in binary search algorithm.
Dis
cret
e S
truc
ture
s
Fal
l 138
9
![Page 15: LOGO. Trees: In these slides: Introduction to trees Applications of trees Tree traversal 2](https://reader038.vdocuments.site/reader038/viewer/2022110210/56649eab5503460f94bb0408/html5/thumbnails/15.jpg)
LOGO
15
Which Tree is Binary?Theorem: A given rooted tree is a binary tree iff
every node other than the root has degree ≤ ___, and the root has degree ≤ ___.
Dis
cret
e S
truc
ture
s
Fal
l 138
9
![Page 16: LOGO. Trees: In these slides: Introduction to trees Applications of trees Tree traversal 2](https://reader038.vdocuments.site/reader038/viewer/2022110210/56649eab5503460f94bb0408/html5/thumbnails/16.jpg)
LOGO
16
Ordered Rooted TreeThis is just a rooted tree in which the children
of each internal node are ordered.
Dis
cret
e S
truc
ture
s
Fal
l 138
9
![Page 17: LOGO. Trees: In these slides: Introduction to trees Applications of trees Tree traversal 2](https://reader038.vdocuments.site/reader038/viewer/2022110210/56649eab5503460f94bb0408/html5/thumbnails/17.jpg)
LOGO
17
Ordered Rooted TreeThis is just a rooted tree in which the children
of each internal node are ordered.
In ordered binary trees, we can define: left child, right child left subtree, right subtree
Dis
cret
e S
truc
ture
s
Fal
l 138
9
![Page 18: LOGO. Trees: In these slides: Introduction to trees Applications of trees Tree traversal 2](https://reader038.vdocuments.site/reader038/viewer/2022110210/56649eab5503460f94bb0408/html5/thumbnails/18.jpg)
LOGO
18
Ordered Rooted TreeThis is just a rooted tree in which the children
of each internal node are ordered.
In ordered binary trees, we can define: left child, right child left subtree, right subtree
For n-ary trees with n>2, can use terms like “leftmost”, “rightmost,” etc.
Dis
cret
e S
truc
ture
s
Fal
l 138
9
![Page 19: LOGO. Trees: In these slides: Introduction to trees Applications of trees Tree traversal 2](https://reader038.vdocuments.site/reader038/viewer/2022110210/56649eab5503460f94bb0408/html5/thumbnails/19.jpg)
LOGO
19
Trees as Models
Can use trees to model the following: Saturated hydrocarbons Organizational structures Computer file systems
In each case, would you use a rooted or a non-rooted tree?
Dis
cret
e S
truc
ture
s
Fal
l 138
9
![Page 20: LOGO. Trees: In these slides: Introduction to trees Applications of trees Tree traversal 2](https://reader038.vdocuments.site/reader038/viewer/2022110210/56649eab5503460f94bb0408/html5/thumbnails/20.jpg)
LOGO
20
Some Tree TheoremsAny tree with n nodes has e = n−1 edges.
Proof: Consider removing leaves.
Dis
cret
e S
truc
ture
s
Fal
l 138
9
![Page 21: LOGO. Trees: In these slides: Introduction to trees Applications of trees Tree traversal 2](https://reader038.vdocuments.site/reader038/viewer/2022110210/56649eab5503460f94bb0408/html5/thumbnails/21.jpg)
LOGO
21
Some Tree TheoremsAny tree with n nodes has e = n−1 edges.
Proof: Consider removing leaves.
A full m-ary tree with i internal nodes has n=mi+1 nodes, and =(m−1)i+1 leaves. Proof: There are mi children of internal nodes, plus the
root. And, = n−i = (m−1)i+1. □
Dis
cret
e S
truc
ture
s
Fal
l 138
9
![Page 22: LOGO. Trees: In these slides: Introduction to trees Applications of trees Tree traversal 2](https://reader038.vdocuments.site/reader038/viewer/2022110210/56649eab5503460f94bb0408/html5/thumbnails/22.jpg)
LOGO
22
Some Tree TheoremsAny tree with n nodes has e = n−1 edges.
Proof: Consider removing leaves.
A full m-ary tree with i internal nodes has n=mi+1 nodes, and =(m−1)i+1 leaves. Proof: There are mi children of internal nodes, plus the
root. And, = n−i = (m−1)i+1. □
Thus, when m is known and the tree is full, we can compute all four of the values e, i, n, and , given any one of them.
Dis
cret
e S
truc
ture
s
Fal
l 138
9
![Page 23: LOGO. Trees: In these slides: Introduction to trees Applications of trees Tree traversal 2](https://reader038.vdocuments.site/reader038/viewer/2022110210/56649eab5503460f94bb0408/html5/thumbnails/23.jpg)
LOGO
23
Some More Tree TheoremsDefinition: The level of a node is the length of the
simple path from the root to the node. The height of a tree is maximum node level. A rooted m-ary tree with height h is called balanced if all
leaves are at levels h or h−1.
Dis
cret
e S
truc
ture
s
Fal
l 138
9
![Page 24: LOGO. Trees: In these slides: Introduction to trees Applications of trees Tree traversal 2](https://reader038.vdocuments.site/reader038/viewer/2022110210/56649eab5503460f94bb0408/html5/thumbnails/24.jpg)
LOGO
24
Some More Tree TheoremsDefinition: The level of a node is the length of the
simple path from the root to the node. The height of a tree is maximum node level. A rooted m-ary tree with height h is called balanced if all
leaves are at levels h or h−1.
Theorem: There are at most mh leaves in an m-ary tree of height h. Corollary: An m-ary tree with leaves has height
h≥logm . If m is full and balanced then h=logm.
Dis
cret
e S
truc
ture
s
Fal
l 138
9
![Page 25: LOGO. Trees: In these slides: Introduction to trees Applications of trees Tree traversal 2](https://reader038.vdocuments.site/reader038/viewer/2022110210/56649eab5503460f94bb0408/html5/thumbnails/25.jpg)
LOGO
25
Applications of
Trees
Dis
cret
e S
truc
ture
s
Fal
l 138
9
![Page 26: LOGO. Trees: In these slides: Introduction to trees Applications of trees Tree traversal 2](https://reader038.vdocuments.site/reader038/viewer/2022110210/56649eab5503460f94bb0408/html5/thumbnails/26.jpg)
LOGO
26
Applications of Trees
Binary search trees A simple data structure for sorted lists
Dis
cret
e S
truc
ture
s
Fal
l 138
9
![Page 27: LOGO. Trees: In these slides: Introduction to trees Applications of trees Tree traversal 2](https://reader038.vdocuments.site/reader038/viewer/2022110210/56649eab5503460f94bb0408/html5/thumbnails/27.jpg)
LOGO
27
Applications of Trees
Binary search trees A simple data structure for sorted lists
Decision trees Minimum comparisons in sorting algorithms
Dis
cret
e S
truc
ture
s
Fal
l 138
9
![Page 28: LOGO. Trees: In these slides: Introduction to trees Applications of trees Tree traversal 2](https://reader038.vdocuments.site/reader038/viewer/2022110210/56649eab5503460f94bb0408/html5/thumbnails/28.jpg)
LOGO
28
Applications of Trees
Binary search trees A simple data structure for sorted lists
Decision trees Minimum comparisons in sorting algorithms
Prefix codes Huffman coding
Dis
cret
e S
truc
ture
s
Fal
l 138
9
![Page 29: LOGO. Trees: In these slides: Introduction to trees Applications of trees Tree traversal 2](https://reader038.vdocuments.site/reader038/viewer/2022110210/56649eab5503460f94bb0408/html5/thumbnails/29.jpg)
LOGO
29
Applications of Trees
Binary search trees A simple data structure for sorted lists
Decision trees Minimum comparisons in sorting algorithms
Prefix codes Huffman coding
Game trees
Dis
cret
e S
truc
ture
s
Fal
l 138
9
![Page 30: LOGO. Trees: In these slides: Introduction to trees Applications of trees Tree traversal 2](https://reader038.vdocuments.site/reader038/viewer/2022110210/56649eab5503460f94bb0408/html5/thumbnails/30.jpg)
LOGO
30
Binary Search Trees
A representation for sorted sets of items. Supports the following operations in Θ(log n)
average-case time:• Searching for an existing item.• Inserting a new item, if not already present.
Supports printing out all items in Θ(n) time.
Note that inserting into a plain sequence ai would instead take Θ(n) worst-case time.
Dis
cret
e S
truc
ture
s
Fal
l 138
9
![Page 31: LOGO. Trees: In these slides: Introduction to trees Applications of trees Tree traversal 2](https://reader038.vdocuments.site/reader038/viewer/2022110210/56649eab5503460f94bb0408/html5/thumbnails/31.jpg)
LOGO
31
Binary Search Tree Format
Items are stored at individual tree nodes.
We arrange for the tree to always obey this invariant: For every item x,
• Every node in x’s left subtree is less than x.
• Every node in x’s right subtree is greater than x.
7
3 12
1 5 9 15
0 2 8 11
Example:
Dis
cret
e S
truc
ture
s
Fal
l 138
9
![Page 32: LOGO. Trees: In these slides: Introduction to trees Applications of trees Tree traversal 2](https://reader038.vdocuments.site/reader038/viewer/2022110210/56649eab5503460f94bb0408/html5/thumbnails/32.jpg)
LOGO
32
Recursive Binary Tree Insert
procedure insert(T: binary tree, x: item)v := root[T]if v = null then begin
root[T] := x; return “Done” endelse if v = x return “Already present”else if x < v then
return insert(leftSubtree[T], x)else {must be x > v}
return insert(rightSubtree[T], x)
Dis
cret
e S
truc
ture
s
Fal
l 138
9
![Page 33: LOGO. Trees: In these slides: Introduction to trees Applications of trees Tree traversal 2](https://reader038.vdocuments.site/reader038/viewer/2022110210/56649eab5503460f94bb0408/html5/thumbnails/33.jpg)
LOGO
33
Decision TreesA decision tree represents a decision-making process.
Each possible “decision point” or situation is represented by a node.
Each possible choice that could be made at that decision point is represented by an edge to a child node.
Dis
cret
e S
truc
ture
s
Fal
l 138
9
![Page 34: LOGO. Trees: In these slides: Introduction to trees Applications of trees Tree traversal 2](https://reader038.vdocuments.site/reader038/viewer/2022110210/56649eab5503460f94bb0408/html5/thumbnails/34.jpg)
LOGO
34
Decision TreesA decision tree represents a decision-making process.
Each possible “decision point” or situation is represented by a node.
Each possible choice that could be made at that decision point is represented by an edge to a child node.
In the extended decision trees used in decision analysis, we also include nodes that represent random events and their outcomes.
Dis
cret
e S
truc
ture
s
Fal
l 138
9
![Page 35: LOGO. Trees: In these slides: Introduction to trees Applications of trees Tree traversal 2](https://reader038.vdocuments.site/reader038/viewer/2022110210/56649eab5503460f94bb0408/html5/thumbnails/35.jpg)
LOGO
35
Coin-Weighing Problem
Imagine you have 8 coins, oneof which is a lighter counterfeit, and a free-beam balance. No scale of weight markings
is required for this problem!
How many weighings are needed to guarantee that the counterfeit coin will be found?
?
Dis
cret
e S
truc
ture
s
Fal
l 138
9
![Page 36: LOGO. Trees: In these slides: Introduction to trees Applications of trees Tree traversal 2](https://reader038.vdocuments.site/reader038/viewer/2022110210/56649eab5503460f94bb0408/html5/thumbnails/36.jpg)
LOGO
36
As a Decision-Tree Problem
In each situation, we pick two disjoint and equal-size subsets of coins to put on the scale.
The balance then“decides” whether to tip left, tip right, or stay balanced.
A given sequence ofweighings thus yieldsa decision tree withbranching factor 3.
Dis
cret
e S
truc
ture
s
Fal
l 138
9
![Page 37: LOGO. Trees: In these slides: Introduction to trees Applications of trees Tree traversal 2](https://reader038.vdocuments.site/reader038/viewer/2022110210/56649eab5503460f94bb0408/html5/thumbnails/37.jpg)
LOGO
37
Applying the Tree Height TheoremThe decision tree must have at least 8 leaf
nodes, since there are 8 possible outcomes. In terms of which coin is the counterfeit one.
Recall the tree-height theorem, h≥logm. Thus the decision tree must have height
h ≥ log38 = 1.893… = 2.Let’s see if we solve the problem with only 2
weighings…
Dis
cret
e S
truc
ture
s
Fal
l 138
9
![Page 38: LOGO. Trees: In these slides: Introduction to trees Applications of trees Tree traversal 2](https://reader038.vdocuments.site/reader038/viewer/2022110210/56649eab5503460f94bb0408/html5/thumbnails/38.jpg)
LOGO
38
General Solution Strategy
The problem is an example of searching for 1 unique particular item, from among a list of n otherwise identical items. Somewhat analogous to the adage of “searching for a needle in haystack.”
Armed with our balance, we can attack the problem using a divide-and-conquer strategy, like what’s done in binary search. We want to narrow down the set of possible locations where the desired item
(coin) could be found down from n to just 1, in a logarithmic fashion. Each weighing has 3 possible outcomes.
Thus, we should use it to partition the search space into 3 pieces that are as close to equal-sized as possible.
This strategy will lead to the minimum possible worst-case number of weighings required.
Dis
cret
e S
truc
ture
s
Fal
l 138
9
![Page 39: LOGO. Trees: In these slides: Introduction to trees Applications of trees Tree traversal 2](https://reader038.vdocuments.site/reader038/viewer/2022110210/56649eab5503460f94bb0408/html5/thumbnails/39.jpg)
LOGO
39
General Balance StrategyOn each step, put n/3 of the n coins to be
searched on each side of the scale. If the scale tips to the left, then:
• The lightweight fake is in the right set of n/3 ≈ n/3 coins. If the scale tips to the right, then:
• The lightweight fake is in the left set of n/3 ≈ n/3 coins. If the scale stays balanced, then:
• The fake is in the remaining set of n − 2n/3 ≈ n/3 coins that were not weighed!
Except if n mod 3 = 1 then we can do a little better by weighing n/3 of the coins on each side.
You can prove that this strategy always leads to a balanced 3-ary tree.
Dis
cret
e S
truc
ture
s
Fal
l 138
9
![Page 40: LOGO. Trees: In these slides: Introduction to trees Applications of trees Tree traversal 2](https://reader038.vdocuments.site/reader038/viewer/2022110210/56649eab5503460f94bb0408/html5/thumbnails/40.jpg)
LOGO
40
Coin Balancing Decision Tree
Here’s what the tree looks like in our case:
123 vs 456
1 vs. 2
left:123 balanced:
78right:456
7 vs. 84 vs. 5
L:1 R:2 B:3 L:4 R:5 B:6 L:7 R:8
Dis
cret
e S
truc
ture
s
Fal
l 138
9
![Page 41: LOGO. Trees: In these slides: Introduction to trees Applications of trees Tree traversal 2](https://reader038.vdocuments.site/reader038/viewer/2022110210/56649eab5503460f94bb0408/html5/thumbnails/41.jpg)
LOGO
41
Tree Traversal
Dis
cret
e S
truc
ture
s
Fal
l 138
9
![Page 42: LOGO. Trees: In these slides: Introduction to trees Applications of trees Tree traversal 2](https://reader038.vdocuments.site/reader038/viewer/2022110210/56649eab5503460f94bb0408/html5/thumbnails/42.jpg)
LOGOUniversal Address Systems
To totally order the vertices of on ordered rooted tree:
1. Label the root with the integer 0.
2. Label its k children (at level 1) from left to right with 1, 2, 3, …, k.
3. For each vertex v at level n with label A, label its kv children, from left to right, with A.1, A.2, A.3, …, A.kv.
42
Dis
cret
e S
truc
ture
s
Fal
l 138
9
![Page 43: LOGO. Trees: In these slides: Introduction to trees Applications of trees Tree traversal 2](https://reader038.vdocuments.site/reader038/viewer/2022110210/56649eab5503460f94bb0408/html5/thumbnails/43.jpg)
LOGOUniversal Address Systems
To totally order the vertices of on ordered rooted tree:
1. Label the root with the integer 0.
2. Label its k children (at level 1) from left to right with 1, 2, 3, …, k.
3. For each vertex v at level n with label A, label its kv children, from left to right, with A.1, A.2, A.3, …, A.kv.
This labeling is called the universal address system of the ordered rooted tree.
43
Dis
cret
e S
truc
ture
s
Fal
l 138
9
![Page 44: LOGO. Trees: In these slides: Introduction to trees Applications of trees Tree traversal 2](https://reader038.vdocuments.site/reader038/viewer/2022110210/56649eab5503460f94bb0408/html5/thumbnails/44.jpg)
LOGOUniversal Address Systems
44
Dis
cret
e S
truc
ture
s
Fal
l 138
9
![Page 45: LOGO. Trees: In these slides: Introduction to trees Applications of trees Tree traversal 2](https://reader038.vdocuments.site/reader038/viewer/2022110210/56649eab5503460f94bb0408/html5/thumbnails/45.jpg)
LOGOTraversal Algorithms
A traversal algorithm is a procedure for systematically visiting every vertex of an ordered rooted tree An ordered rooted tree is a rooted tree where
the children of each internal vertex are ordered
45
Dis
cret
e S
truc
ture
s
Fal
l 138
9
![Page 46: LOGO. Trees: In these slides: Introduction to trees Applications of trees Tree traversal 2](https://reader038.vdocuments.site/reader038/viewer/2022110210/56649eab5503460f94bb0408/html5/thumbnails/46.jpg)
LOGOTraversal Algorithms
A traversal algorithm is a procedure for systematically visiting every vertex of an ordered rooted tree An ordered rooted tree is a rooted tree where
the children of each internal vertex are orderedThe three common traversals are:
Preorder traversal Inorder traversal Postorder traversal
46
Dis
cret
e S
truc
ture
s
Fal
l 138
9
![Page 47: LOGO. Trees: In these slides: Introduction to trees Applications of trees Tree traversal 2](https://reader038.vdocuments.site/reader038/viewer/2022110210/56649eab5503460f94bb0408/html5/thumbnails/47.jpg)
LOGOTraversal
Let T be an ordered rooted tree with root r.Suppose T1, T2, …,Tn are the subtrees at r
from left to right in T.
r
T1 T2 Tn
47
Dis
cret
e S
truc
ture
s
Fal
l 138
9
![Page 48: LOGO. Trees: In these slides: Introduction to trees Applications of trees Tree traversal 2](https://reader038.vdocuments.site/reader038/viewer/2022110210/56649eab5503460f94bb0408/html5/thumbnails/48.jpg)
LOGOPreorder Traversal
r
T1 T2 Tn
Step 1: Visit rStep 2: Visit T1 in preorderStep 3: Visit T2 in preorder
.
.
.Step n+1: Visit Tn in preorder
48
Dis
cret
e S
truc
ture
s
Fal
l 138
9
![Page 49: LOGO. Trees: In these slides: Introduction to trees Applications of trees Tree traversal 2](https://reader038.vdocuments.site/reader038/viewer/2022110210/56649eab5503460f94bb0408/html5/thumbnails/49.jpg)
LOGOPreorder Traversal
r
T1 T2 Tn
Step 1: Visit rStep 2: Visit T1 in preorderStep 3: Visit T2 in preorder
.
.
.Step n+1: Visit Tn in preorder
49
Dis
cret
e S
truc
ture
s
Fal
l 138
9
![Page 50: LOGO. Trees: In these slides: Introduction to trees Applications of trees Tree traversal 2](https://reader038.vdocuments.site/reader038/viewer/2022110210/56649eab5503460f94bb0408/html5/thumbnails/50.jpg)
LOGOPreorder Traversal
r
T1 T2 Tn
Step 1: Visit rStep 2: Visit T1 in preorderStep 3: Visit T2 in preorder
.
.
.Step n+1: Visit Tn in preorder
50
Dis
cret
e S
truc
ture
s
Fal
l 138
9
![Page 51: LOGO. Trees: In these slides: Introduction to trees Applications of trees Tree traversal 2](https://reader038.vdocuments.site/reader038/viewer/2022110210/56649eab5503460f94bb0408/html5/thumbnails/51.jpg)
LOGOPreorder Traversal
r
T1 T2 Tn
Step 1: Visit rStep 2: Visit T1 in preorderStep 3: Visit T2 in preorder
.
.
.Step n+1: Visit Tn in preorder
51
Dis
cret
e S
truc
ture
s
Fal
l 138
9
![Page 52: LOGO. Trees: In these slides: Introduction to trees Applications of trees Tree traversal 2](https://reader038.vdocuments.site/reader038/viewer/2022110210/56649eab5503460f94bb0408/html5/thumbnails/52.jpg)
LOGOPreorder Traversal
r
T1 T2 Tn
Step 1: Visit rStep 2: Visit T1 in preorderStep 3: Visit T2 in preorder
.
.
.Step n+1: Visit Tn in preorder
52
Dis
cret
e S
truc
ture
s
Fal
l 138
9
![Page 53: LOGO. Trees: In these slides: Introduction to trees Applications of trees Tree traversal 2](https://reader038.vdocuments.site/reader038/viewer/2022110210/56649eab5503460f94bb0408/html5/thumbnails/53.jpg)
LOGOExample
M
A
R
EY
P
M
HJ
Q T
Tree:
Visiting sequence:
53
Dis
cret
e S
truc
ture
s
Fal
l 138
9
![Page 54: LOGO. Trees: In these slides: Introduction to trees Applications of trees Tree traversal 2](https://reader038.vdocuments.site/reader038/viewer/2022110210/56649eab5503460f94bb0408/html5/thumbnails/54.jpg)
LOGOExample
AM
A
R
EY
P
M
HJ
Q T
Tree:
Visiting sequence:
54
Dis
cret
e S
truc
ture
s
Fal
l 138
9
![Page 55: LOGO. Trees: In these slides: Introduction to trees Applications of trees Tree traversal 2](https://reader038.vdocuments.site/reader038/viewer/2022110210/56649eab5503460f94bb0408/html5/thumbnails/55.jpg)
LOGOExample
AM J
A
R
EY
P
M
HJ
Q T
Tree:
Visiting sequence:
55
Dis
cret
e S
truc
ture
s
Fal
l 138
9
![Page 56: LOGO. Trees: In these slides: Introduction to trees Applications of trees Tree traversal 2](https://reader038.vdocuments.site/reader038/viewer/2022110210/56649eab5503460f94bb0408/html5/thumbnails/56.jpg)
LOGOExample
A YM J
A
R
EY
P
M
HJ
Q T
Tree:
Visiting sequence:
56
Dis
cret
e S
truc
ture
s
Fal
l 138
9
![Page 57: LOGO. Trees: In these slides: Introduction to trees Applications of trees Tree traversal 2](https://reader038.vdocuments.site/reader038/viewer/2022110210/56649eab5503460f94bb0408/html5/thumbnails/57.jpg)
LOGOExample
A RYM J
A
R
EY
P
M
HJ
Q T
Tree:
Visiting sequence:
57
Dis
cret
e S
truc
ture
s
Fal
l 138
9
![Page 58: LOGO. Trees: In these slides: Introduction to trees Applications of trees Tree traversal 2](https://reader038.vdocuments.site/reader038/viewer/2022110210/56649eab5503460f94bb0408/html5/thumbnails/58.jpg)
LOGOExample
A RYM HJ
A
R
EY
P
M
HJ
Q T
Tree:
Visiting sequence:
58
Dis
cret
e S
truc
ture
s
Fal
l 138
9
![Page 59: LOGO. Trees: In these slides: Introduction to trees Applications of trees Tree traversal 2](https://reader038.vdocuments.site/reader038/viewer/2022110210/56649eab5503460f94bb0408/html5/thumbnails/59.jpg)
LOGOExample
A RY PM HJ
A
R
EY
P
M
HJ
Q T
Tree:
Visiting sequence:
59
Dis
cret
e S
truc
ture
s
Fal
l 138
9
![Page 60: LOGO. Trees: In these slides: Introduction to trees Applications of trees Tree traversal 2](https://reader038.vdocuments.site/reader038/viewer/2022110210/56649eab5503460f94bb0408/html5/thumbnails/60.jpg)
LOGOExample
A RY PM HJ Q
A
R
EY
P
M
HJ
Q T
Tree:
Visiting sequence:
60
Dis
cret
e S
truc
ture
s
Fal
l 138
9
![Page 61: LOGO. Trees: In these slides: Introduction to trees Applications of trees Tree traversal 2](https://reader038.vdocuments.site/reader038/viewer/2022110210/56649eab5503460f94bb0408/html5/thumbnails/61.jpg)
LOGOExample
A RY PM HJ Q T
A
R
EY
P
M
HJ
Q T
Tree:
Visiting sequence:
61
Dis
cret
e S
truc
ture
s
Fal
l 138
9
![Page 62: LOGO. Trees: In these slides: Introduction to trees Applications of trees Tree traversal 2](https://reader038.vdocuments.site/reader038/viewer/2022110210/56649eab5503460f94bb0408/html5/thumbnails/62.jpg)
LOGOExample
A R EY PM HJ Q T
A
R
EY
P
M
HJ
Q T
Tree:
Visiting sequence:
62
Dis
cret
e S
truc
ture
s
Fal
l 138
9
![Page 63: LOGO. Trees: In these slides: Introduction to trees Applications of trees Tree traversal 2](https://reader038.vdocuments.site/reader038/viewer/2022110210/56649eab5503460f94bb0408/html5/thumbnails/63.jpg)
LOGOThe Preorder Traversal of T
In which order does a preorder traversal visit the vertices in the ordered rooted tree T shown to the left?Remember:Visit root, then visit subtrees left to right.
63
Dis
cret
e S
truc
ture
s
Fal
l 138
9
![Page 64: LOGO. Trees: In these slides: Introduction to trees Applications of trees Tree traversal 2](https://reader038.vdocuments.site/reader038/viewer/2022110210/56649eab5503460f94bb0408/html5/thumbnails/64.jpg)
LOGOThe Preorder Traversal of T
64
Dis
cret
e S
truc
ture
s
Fal
l 138
9
![Page 65: LOGO. Trees: In these slides: Introduction to trees Applications of trees Tree traversal 2](https://reader038.vdocuments.site/reader038/viewer/2022110210/56649eab5503460f94bb0408/html5/thumbnails/65.jpg)
LOGOThe Preorder Traversal of T
65
Dis
cret
e S
truc
ture
s
Fal
l 138
9
![Page 66: LOGO. Trees: In these slides: Introduction to trees Applications of trees Tree traversal 2](https://reader038.vdocuments.site/reader038/viewer/2022110210/56649eab5503460f94bb0408/html5/thumbnails/66.jpg)
LOGOThe Preorder Traversal of T
66
Dis
cret
e S
truc
ture
s
Fal
l 138
9
![Page 67: LOGO. Trees: In these slides: Introduction to trees Applications of trees Tree traversal 2](https://reader038.vdocuments.site/reader038/viewer/2022110210/56649eab5503460f94bb0408/html5/thumbnails/67.jpg)
LOGOThe Preorder Traversal of T
67
Dis
cret
e S
truc
ture
s
Fal
l 138
9
![Page 68: LOGO. Trees: In these slides: Introduction to trees Applications of trees Tree traversal 2](https://reader038.vdocuments.site/reader038/viewer/2022110210/56649eab5503460f94bb0408/html5/thumbnails/68.jpg)
LOGOInorder Traversal
Step 1: Visit T1 in inorderStep 2: Visit rStep 3: Visit T2 in inorder
.
.
.Step n+1: Visit Tn in inorder
r
T1 T2 Tn
68
Dis
cret
e S
truc
ture
s
Fal
l 138
9
![Page 69: LOGO. Trees: In these slides: Introduction to trees Applications of trees Tree traversal 2](https://reader038.vdocuments.site/reader038/viewer/2022110210/56649eab5503460f94bb0408/html5/thumbnails/69.jpg)
LOGOInorder Traversal
Step 1: Visit T1 in inorderStep 2: Visit rStep 3: Visit T2 in inorder
.
.
.Step n+1: Visit Tn in inorder
r
T1 T2 Tn
69
Dis
cret
e S
truc
ture
s
Fal
l 138
9
![Page 70: LOGO. Trees: In these slides: Introduction to trees Applications of trees Tree traversal 2](https://reader038.vdocuments.site/reader038/viewer/2022110210/56649eab5503460f94bb0408/html5/thumbnails/70.jpg)
LOGOInorder Traversal
Step 1: Visit T1 in inorderStep 2: Visit rStep 3: Visit T2 in inorder
.
.
.Step n+1: Visit Tn in inorder
r
T1 T2 Tn
70
Dis
cret
e S
truc
ture
s
Fal
l 138
9
![Page 71: LOGO. Trees: In these slides: Introduction to trees Applications of trees Tree traversal 2](https://reader038.vdocuments.site/reader038/viewer/2022110210/56649eab5503460f94bb0408/html5/thumbnails/71.jpg)
LOGOInorder Traversal
Step 1: Visit T1 in inorderStep 2: Visit rStep 3: Visit T2 in inorder
.
.
.Step n+1: Visit Tn in inorder
r
T1 T2 Tn
71
Dis
cret
e S
truc
ture
s
Fal
l 138
9
![Page 72: LOGO. Trees: In these slides: Introduction to trees Applications of trees Tree traversal 2](https://reader038.vdocuments.site/reader038/viewer/2022110210/56649eab5503460f94bb0408/html5/thumbnails/72.jpg)
LOGOInorder Traversal
Step 1: Visit T1 in inorderStep 2: Visit rStep 3: Visit T2 in inorder
.
.
.Step n+1: Visit Tn in inorder
r
T1 T2 Tn
72
Dis
cret
e S
truc
ture
s
Fal
l 138
9
![Page 73: LOGO. Trees: In these slides: Introduction to trees Applications of trees Tree traversal 2](https://reader038.vdocuments.site/reader038/viewer/2022110210/56649eab5503460f94bb0408/html5/thumbnails/73.jpg)
LOGOExample
J
A
R
EY
P
M
HJ
Q T
Tree:
Visiting sequence:
73
Dis
cret
e S
truc
ture
s
Fal
l 138
9
![Page 74: LOGO. Trees: In these slides: Introduction to trees Applications of trees Tree traversal 2](https://reader038.vdocuments.site/reader038/viewer/2022110210/56649eab5503460f94bb0408/html5/thumbnails/74.jpg)
LOGOExample
AJ
A
R
EY
P
M
HJ
Q T
Tree:
Visiting sequence:
74
Dis
cret
e S
truc
ture
s
Fal
l 138
9
![Page 75: LOGO. Trees: In these slides: Introduction to trees Applications of trees Tree traversal 2](https://reader038.vdocuments.site/reader038/viewer/2022110210/56649eab5503460f94bb0408/html5/thumbnails/75.jpg)
LOGOExample
A MJ
A
R
EY
P
M
HJ
Q T
Tree:
Visiting sequence:
75
Dis
cret
e S
truc
ture
s
Fal
l 138
9
![Page 76: LOGO. Trees: In these slides: Introduction to trees Applications of trees Tree traversal 2](https://reader038.vdocuments.site/reader038/viewer/2022110210/56649eab5503460f94bb0408/html5/thumbnails/76.jpg)
LOGOExample
A RMJ
A
R
EY
P
M
HJ
Q T
Tree:
Visiting sequence:
76
Dis
cret
e S
truc
ture
s
Fal
l 138
9
![Page 77: LOGO. Trees: In these slides: Introduction to trees Applications of trees Tree traversal 2](https://reader038.vdocuments.site/reader038/viewer/2022110210/56649eab5503460f94bb0408/html5/thumbnails/77.jpg)
LOGOExample
A R YMJ
A
R
EY
P
M
HJ
Q T
Tree:
Visiting sequence:
77
Dis
cret
e S
truc
ture
s
Fal
l 138
9
![Page 78: LOGO. Trees: In these slides: Introduction to trees Applications of trees Tree traversal 2](https://reader038.vdocuments.site/reader038/viewer/2022110210/56649eab5503460f94bb0408/html5/thumbnails/78.jpg)
LOGOExample
A R Y PMJ
A
R
EY
P
M
HJ
Q T
Tree:
Visiting sequence:
78
Dis
cret
e S
truc
ture
s
Fal
l 138
9
![Page 79: LOGO. Trees: In these slides: Introduction to trees Applications of trees Tree traversal 2](https://reader038.vdocuments.site/reader038/viewer/2022110210/56649eab5503460f94bb0408/html5/thumbnails/79.jpg)
LOGOExample
A R Y PM HJ
A
R
EY
P
M
HJ
Q T
Tree:
Visiting sequence:
79
Dis
cret
e S
truc
ture
s
Fal
l 138
9
![Page 80: LOGO. Trees: In these slides: Introduction to trees Applications of trees Tree traversal 2](https://reader038.vdocuments.site/reader038/viewer/2022110210/56649eab5503460f94bb0408/html5/thumbnails/80.jpg)
LOGOExample
A R Y PM HJ Q
A
R
EY
P
M
HJ
Q T
Tree:
Visiting sequence:
80
Dis
cret
e S
truc
ture
s
Fal
l 138
9
![Page 81: LOGO. Trees: In these slides: Introduction to trees Applications of trees Tree traversal 2](https://reader038.vdocuments.site/reader038/viewer/2022110210/56649eab5503460f94bb0408/html5/thumbnails/81.jpg)
LOGOExample
A R Y PM HJ Q T
A
R
EY
P
M
HJ
Q T
Tree:
Visiting sequence:
81
Dis
cret
e S
truc
ture
s
Fal
l 138
9
![Page 82: LOGO. Trees: In these slides: Introduction to trees Applications of trees Tree traversal 2](https://reader038.vdocuments.site/reader038/viewer/2022110210/56649eab5503460f94bb0408/html5/thumbnails/82.jpg)
LOGOExample
A R EY PM HJ Q T
A
R
EY
P
M
HJ
Q T
Tree:
Visiting sequence:
82
Dis
cret
e S
truc
ture
s
Fal
l 138
9
![Page 83: LOGO. Trees: In these slides: Introduction to trees Applications of trees Tree traversal 2](https://reader038.vdocuments.site/reader038/viewer/2022110210/56649eab5503460f94bb0408/html5/thumbnails/83.jpg)
LOGOThe Inorder Traversal of T
In which order does an inorder traversal visit the vertices in the ordered rooted tree T shown to the left?
Remember:Visit leftmost tree, visit root, visit other subtrees left to right.
83
Dis
cret
e S
truc
ture
s
Fal
l 138
9
![Page 84: LOGO. Trees: In these slides: Introduction to trees Applications of trees Tree traversal 2](https://reader038.vdocuments.site/reader038/viewer/2022110210/56649eab5503460f94bb0408/html5/thumbnails/84.jpg)
LOGOThe Inorder Traversal of T
84
Dis
cret
e S
truc
ture
s
Fal
l 138
9
![Page 85: LOGO. Trees: In these slides: Introduction to trees Applications of trees Tree traversal 2](https://reader038.vdocuments.site/reader038/viewer/2022110210/56649eab5503460f94bb0408/html5/thumbnails/85.jpg)
LOGOThe Inorder Traversal of T
85
Dis
cret
e S
truc
ture
s
Fal
l 138
9
![Page 86: LOGO. Trees: In these slides: Introduction to trees Applications of trees Tree traversal 2](https://reader038.vdocuments.site/reader038/viewer/2022110210/56649eab5503460f94bb0408/html5/thumbnails/86.jpg)
LOGOThe Inorder Traversal of T
86
Dis
cret
e S
truc
ture
s
Fal
l 138
9
![Page 87: LOGO. Trees: In these slides: Introduction to trees Applications of trees Tree traversal 2](https://reader038.vdocuments.site/reader038/viewer/2022110210/56649eab5503460f94bb0408/html5/thumbnails/87.jpg)
LOGOThe Inorder Traversal of T
87
Dis
cret
e S
truc
ture
s
Fal
l 138
9
![Page 88: LOGO. Trees: In these slides: Introduction to trees Applications of trees Tree traversal 2](https://reader038.vdocuments.site/reader038/viewer/2022110210/56649eab5503460f94bb0408/html5/thumbnails/88.jpg)
LOGOPostorder Traversal
Step 1: Visit T1 in postorderStep 2: Visit T2 in postorder
.
.
.Step n: Visit Tn in postorderStep n+1: Visit r
r
T1 T2 Tn
88
Dis
cret
e S
truc
ture
s
Fal
l 138
9
![Page 89: LOGO. Trees: In these slides: Introduction to trees Applications of trees Tree traversal 2](https://reader038.vdocuments.site/reader038/viewer/2022110210/56649eab5503460f94bb0408/html5/thumbnails/89.jpg)
LOGOPostorder Traversal
Step 1: Visit T1 in postorderStep 2: Visit T2 in postorder
.
.
.Step n: Visit Tn in postorderStep n+1: Visit r
r
T1 T2 Tn
89
Dis
cret
e S
truc
ture
s
Fal
l 138
9
![Page 90: LOGO. Trees: In these slides: Introduction to trees Applications of trees Tree traversal 2](https://reader038.vdocuments.site/reader038/viewer/2022110210/56649eab5503460f94bb0408/html5/thumbnails/90.jpg)
LOGOPostorder Traversal
Step 1: Visit T1 in postorderStep 2: Visit T2 in postorder
.
.
.Step n: Visit Tn in postorderStep n+1: Visit r
r
T1 T2 Tn
90
Dis
cret
e S
truc
ture
s
Fal
l 138
9
![Page 91: LOGO. Trees: In these slides: Introduction to trees Applications of trees Tree traversal 2](https://reader038.vdocuments.site/reader038/viewer/2022110210/56649eab5503460f94bb0408/html5/thumbnails/91.jpg)
LOGOPostorder Traversal
Step 1: Visit T1 in postorderStep 2: Visit T2 in postorder
.
.
.Step n: Visit Tn in postorderStep n+1: Visit r
r
T1 T2 Tn
91
Dis
cret
e S
truc
ture
s
Fal
l 138
9
![Page 92: LOGO. Trees: In these slides: Introduction to trees Applications of trees Tree traversal 2](https://reader038.vdocuments.site/reader038/viewer/2022110210/56649eab5503460f94bb0408/html5/thumbnails/92.jpg)
LOGOPostorder Traversal
Step 1: Visit T1 in postorderStep 2: Visit T2 in postorder
.
.
.Step n: Visit Tn in postorderStep n+1: Visit r
r
T1 T2 Tn
92
Dis
cret
e S
truc
ture
s
Fal
l 138
9
![Page 93: LOGO. Trees: In these slides: Introduction to trees Applications of trees Tree traversal 2](https://reader038.vdocuments.site/reader038/viewer/2022110210/56649eab5503460f94bb0408/html5/thumbnails/93.jpg)
LOGOExample
J
A
R
EY
P
M
HJ
Q T
Tree:
Visiting sequence:
93
Dis
cret
e S
truc
ture
s
Fal
l 138
9
![Page 94: LOGO. Trees: In these slides: Introduction to trees Applications of trees Tree traversal 2](https://reader038.vdocuments.site/reader038/viewer/2022110210/56649eab5503460f94bb0408/html5/thumbnails/94.jpg)
LOGOExample
AJ
A
R
EY
P
M
HJ
Q T
Tree:
Visiting sequence:
94
Dis
cret
e S
truc
ture
s
Fal
l 138
9
![Page 95: LOGO. Trees: In these slides: Introduction to trees Applications of trees Tree traversal 2](https://reader038.vdocuments.site/reader038/viewer/2022110210/56649eab5503460f94bb0408/html5/thumbnails/95.jpg)
LOGOExample
A RJ
A
R
EY
P
M
HJ
Q T
Tree:
Visiting sequence:
95
Dis
cret
e S
truc
ture
s
Fal
l 138
9
![Page 96: LOGO. Trees: In these slides: Introduction to trees Applications of trees Tree traversal 2](https://reader038.vdocuments.site/reader038/viewer/2022110210/56649eab5503460f94bb0408/html5/thumbnails/96.jpg)
LOGOExample
A R PJ
A
R
EY
P
M
HJ
Q T
Tree:
Visiting sequence:
96
Dis
cret
e S
truc
ture
s
Fal
l 138
9
![Page 97: LOGO. Trees: In these slides: Introduction to trees Applications of trees Tree traversal 2](https://reader038.vdocuments.site/reader038/viewer/2022110210/56649eab5503460f94bb0408/html5/thumbnails/97.jpg)
LOGOExample
A R PJ Q
A
R
EY
P
M
HJ
Q T
Tree:
Visiting sequence:
97
Dis
cret
e S
truc
ture
s
Fal
l 138
9
![Page 98: LOGO. Trees: In these slides: Introduction to trees Applications of trees Tree traversal 2](https://reader038.vdocuments.site/reader038/viewer/2022110210/56649eab5503460f94bb0408/html5/thumbnails/98.jpg)
LOGOExample
A R PJ Q T
A
R
EY
P
M
HJ
Q T
Tree:
Visiting sequence:
98
Dis
cret
e S
truc
ture
s
Fal
l 138
9
![Page 99: LOGO. Trees: In these slides: Introduction to trees Applications of trees Tree traversal 2](https://reader038.vdocuments.site/reader038/viewer/2022110210/56649eab5503460f94bb0408/html5/thumbnails/99.jpg)
LOGOExample
A R P HJ Q T
A
R
EY
P
M
HJ
Q T
Tree:
Visiting sequence:
99
Dis
cret
e S
truc
ture
s
Fal
l 138
9
![Page 100: LOGO. Trees: In these slides: Introduction to trees Applications of trees Tree traversal 2](https://reader038.vdocuments.site/reader038/viewer/2022110210/56649eab5503460f94bb0408/html5/thumbnails/100.jpg)
LOGOExample
A R YP HJ Q T
A
R
EY
P
M
HJ
Q T
Tree:
Visiting sequence:
100
Dis
cret
e S
truc
ture
s
Fal
l 138
9
![Page 101: LOGO. Trees: In these slides: Introduction to trees Applications of trees Tree traversal 2](https://reader038.vdocuments.site/reader038/viewer/2022110210/56649eab5503460f94bb0408/html5/thumbnails/101.jpg)
LOGOExample
A R EYP HJ Q T
A
R
EY
P
M
HJ
Q T
Tree:
Visiting sequence:
101
Dis
cret
e S
truc
ture
s
Fal
l 138
9
![Page 102: LOGO. Trees: In these slides: Introduction to trees Applications of trees Tree traversal 2](https://reader038.vdocuments.site/reader038/viewer/2022110210/56649eab5503460f94bb0408/html5/thumbnails/102.jpg)
LOGOExample
A R EYP MHJ Q T
A
R
EY
P
M
HJ
Q T
Tree:
Visiting sequence:
102
Dis
cret
e S
truc
ture
s
Fal
l 138
9
![Page 103: LOGO. Trees: In these slides: Introduction to trees Applications of trees Tree traversal 2](https://reader038.vdocuments.site/reader038/viewer/2022110210/56649eab5503460f94bb0408/html5/thumbnails/103.jpg)
LOGOThe Postorder Traversal of T
In which order does a postorder traversal visit the vertices in the ordered rooted tree T shown to the left?
Remember:Visit subtrees left to right, then visit root.
103
Dis
cret
e S
truc
ture
s
Fal
l 138
9
![Page 104: LOGO. Trees: In these slides: Introduction to trees Applications of trees Tree traversal 2](https://reader038.vdocuments.site/reader038/viewer/2022110210/56649eab5503460f94bb0408/html5/thumbnails/104.jpg)
LOGOThe Postorder Traversal of T
104
Dis
cret
e S
truc
ture
s
Fal
l 138
9
![Page 105: LOGO. Trees: In these slides: Introduction to trees Applications of trees Tree traversal 2](https://reader038.vdocuments.site/reader038/viewer/2022110210/56649eab5503460f94bb0408/html5/thumbnails/105.jpg)
LOGOThe Postorder Traversal of T
105
Dis
cret
e S
truc
ture
s
Fal
l 138
9
![Page 106: LOGO. Trees: In these slides: Introduction to trees Applications of trees Tree traversal 2](https://reader038.vdocuments.site/reader038/viewer/2022110210/56649eab5503460f94bb0408/html5/thumbnails/106.jpg)
LOGOThe Postorder Traversal of T
106
Dis
cret
e S
truc
ture
s
Fal
l 138
9
![Page 107: LOGO. Trees: In these slides: Introduction to trees Applications of trees Tree traversal 2](https://reader038.vdocuments.site/reader038/viewer/2022110210/56649eab5503460f94bb0408/html5/thumbnails/107.jpg)
LOGOThe Postorder Traversal of T
107
Dis
cret
e S
truc
ture
s
Fal
l 138
9
![Page 108: LOGO. Trees: In these slides: Introduction to trees Applications of trees Tree traversal 2](https://reader038.vdocuments.site/reader038/viewer/2022110210/56649eab5503460f94bb0408/html5/thumbnails/108.jpg)
LOGORepresenting Arithmetic Expressions
Complicated arithmetic expressions can be represented by an ordered rooted tree Internal vertices represent operators Leaves represent operands
108
Dis
cret
e S
truc
ture
s
Fal
l 138
9
![Page 109: LOGO. Trees: In these slides: Introduction to trees Applications of trees Tree traversal 2](https://reader038.vdocuments.site/reader038/viewer/2022110210/56649eab5503460f94bb0408/html5/thumbnails/109.jpg)
LOGORepresenting Arithmetic Expressions
Complicated arithmetic expressions can be represented by an ordered rooted tree Internal vertices represent operators Leaves represent operands
Build the tree bottom-up Construct smaller subtrees Incorporate the smaller subtrees as part of
larger subtrees109
Dis
cret
e S
truc
ture
s
Fal
l 138
9
![Page 110: LOGO. Trees: In these slides: Introduction to trees Applications of trees Tree traversal 2](https://reader038.vdocuments.site/reader038/viewer/2022110210/56649eab5503460f94bb0408/html5/thumbnails/110.jpg)
LOGOExample
(x+y)2 + (x-3)/(y+2)
110
Dis
cret
e S
truc
ture
s
Fal
l 138
9
![Page 111: LOGO. Trees: In these slides: Introduction to trees Applications of trees Tree traversal 2](https://reader038.vdocuments.site/reader038/viewer/2022110210/56649eab5503460f94bb0408/html5/thumbnails/111.jpg)
LOGOExample
(x+y)2 + (x-3)/(y+2)
+
x y
111
Dis
cret
e S
truc
ture
s
Fal
l 138
9
![Page 112: LOGO. Trees: In these slides: Introduction to trees Applications of trees Tree traversal 2](https://reader038.vdocuments.site/reader038/viewer/2022110210/56649eab5503460f94bb0408/html5/thumbnails/112.jpg)
LOGOExample
(x+y)2 + (x-3)/(y+2)
+
x y
2
112
Dis
cret
e S
truc
ture
s
Fal
l 138
9
![Page 113: LOGO. Trees: In these slides: Introduction to trees Applications of trees Tree traversal 2](https://reader038.vdocuments.site/reader038/viewer/2022110210/56649eab5503460f94bb0408/html5/thumbnails/113.jpg)
LOGOExample
(x+y)2 + (x-3)/(y+2)
+
x y
2
–
x 3
113
Dis
cret
e S
truc
ture
s
Fal
l 138
9
![Page 114: LOGO. Trees: In these slides: Introduction to trees Applications of trees Tree traversal 2](https://reader038.vdocuments.site/reader038/viewer/2022110210/56649eab5503460f94bb0408/html5/thumbnails/114.jpg)
LOGOExample
(x+y)2 + (x-3)/(y+2)
+
x y
2
–
x 3
+
y 2
114
Dis
cret
e S
truc
ture
s
Fal
l 138
9
![Page 115: LOGO. Trees: In these slides: Introduction to trees Applications of trees Tree traversal 2](https://reader038.vdocuments.site/reader038/viewer/2022110210/56649eab5503460f94bb0408/html5/thumbnails/115.jpg)
LOGOExample
(x+y)2 + (x-3)/(y+2)
+
x y
2
–
x 3
+
y 2
/
115
Dis
cret
e S
truc
ture
s
Fal
l 138
9
![Page 116: LOGO. Trees: In these slides: Introduction to trees Applications of trees Tree traversal 2](https://reader038.vdocuments.site/reader038/viewer/2022110210/56649eab5503460f94bb0408/html5/thumbnails/116.jpg)
LOGOExample
(x+y)2 + (x-3)/(y+2)
+
x y
2
–
x 3
+
y 2
/
+
116
Dis
cret
e S
truc
ture
s
Fal
l 138
9
![Page 117: LOGO. Trees: In these slides: Introduction to trees Applications of trees Tree traversal 2](https://reader038.vdocuments.site/reader038/viewer/2022110210/56649eab5503460f94bb0408/html5/thumbnails/117.jpg)
LOGOEvaluating Prefix NotationIn an prefix expression, a binary operator
precedes its two operands
The expression is evaluated right-left
Look for the first operator from the right
Evaluate the operator with the two operands immediately to its right
117
Dis
cret
e S
truc
ture
s
Fal
l 138
9
![Page 118: LOGO. Trees: In these slides: Introduction to trees Applications of trees Tree traversal 2](https://reader038.vdocuments.site/reader038/viewer/2022110210/56649eab5503460f94bb0408/html5/thumbnails/118.jpg)
LOGOExample
+ / + 2 2 2 / – 3 2 + 1 0
118
Dis
cret
e S
truc
ture
s
Fal
l 138
9
![Page 119: LOGO. Trees: In these slides: Introduction to trees Applications of trees Tree traversal 2](https://reader038.vdocuments.site/reader038/viewer/2022110210/56649eab5503460f94bb0408/html5/thumbnails/119.jpg)
LOGOExample
+ / + 2 2 2 / – 3 2 + 1 0
119
Dis
cret
e S
truc
ture
s
Fal
l 138
9
![Page 120: LOGO. Trees: In these slides: Introduction to trees Applications of trees Tree traversal 2](https://reader038.vdocuments.site/reader038/viewer/2022110210/56649eab5503460f94bb0408/html5/thumbnails/120.jpg)
LOGOExample
+ / + 2 2 2 / – 3 2 + 1 0+ / + 2 2 2 / – 3 2 1
120
Dis
cret
e S
truc
ture
s
Fal
l 138
9
![Page 121: LOGO. Trees: In these slides: Introduction to trees Applications of trees Tree traversal 2](https://reader038.vdocuments.site/reader038/viewer/2022110210/56649eab5503460f94bb0408/html5/thumbnails/121.jpg)
LOGOExample
+ / + 2 2 2 / – 3 2 + 1 0+ / + 2 2 2 / – 3 2 1
121
Dis
cret
e S
truc
ture
s
Fal
l 138
9
![Page 122: LOGO. Trees: In these slides: Introduction to trees Applications of trees Tree traversal 2](https://reader038.vdocuments.site/reader038/viewer/2022110210/56649eab5503460f94bb0408/html5/thumbnails/122.jpg)
LOGOExample
+ / + 2 2 2 / – 3 2 + 1 0+ / + 2 2 2 / – 3 2 1+ / + 2 2 2 / 1 1
122
Dis
cret
e S
truc
ture
s
Fal
l 138
9
![Page 123: LOGO. Trees: In these slides: Introduction to trees Applications of trees Tree traversal 2](https://reader038.vdocuments.site/reader038/viewer/2022110210/56649eab5503460f94bb0408/html5/thumbnails/123.jpg)
LOGOExample
+ / + 2 2 2 / – 3 2 + 1 0+ / + 2 2 2 / – 3 2 1+ / + 2 2 2 / 1 1
123
Dis
cret
e S
truc
ture
s
Fal
l 138
9
![Page 124: LOGO. Trees: In these slides: Introduction to trees Applications of trees Tree traversal 2](https://reader038.vdocuments.site/reader038/viewer/2022110210/56649eab5503460f94bb0408/html5/thumbnails/124.jpg)
LOGOExample
+ / + 2 2 2 / – 3 2 + 1 0+ / + 2 2 2 / – 3 2 1+ / + 2 2 2 / 1 1+ / + 2 2 2 1
124
Dis
cret
e S
truc
ture
s
Fal
l 138
9
![Page 125: LOGO. Trees: In these slides: Introduction to trees Applications of trees Tree traversal 2](https://reader038.vdocuments.site/reader038/viewer/2022110210/56649eab5503460f94bb0408/html5/thumbnails/125.jpg)
LOGOExample
+ / + 2 2 2 / – 3 2 + 1 0+ / + 2 2 2 / – 3 2 1+ / + 2 2 2 / 1 1+ / + 2 2 2 1
125
Dis
cret
e S
truc
ture
s
Fal
l 138
9
![Page 126: LOGO. Trees: In these slides: Introduction to trees Applications of trees Tree traversal 2](https://reader038.vdocuments.site/reader038/viewer/2022110210/56649eab5503460f94bb0408/html5/thumbnails/126.jpg)
LOGOExample
+ / + 2 2 2 / – 3 2 + 1 0+ / + 2 2 2 / – 3 2 1+ / + 2 2 2 / 1 1+ / + 2 2 2 1+ / 4 2 1
126
Dis
cret
e S
truc
ture
s
Fal
l 138
9
![Page 127: LOGO. Trees: In these slides: Introduction to trees Applications of trees Tree traversal 2](https://reader038.vdocuments.site/reader038/viewer/2022110210/56649eab5503460f94bb0408/html5/thumbnails/127.jpg)
LOGOExample
+ / + 2 2 2 / – 3 2 + 1 0+ / + 2 2 2 / – 3 2 1+ / + 2 2 2 / 1 1+ / + 2 2 2 1+ / 4 2 1
127
Dis
cret
e S
truc
ture
s
Fal
l 138
9
![Page 128: LOGO. Trees: In these slides: Introduction to trees Applications of trees Tree traversal 2](https://reader038.vdocuments.site/reader038/viewer/2022110210/56649eab5503460f94bb0408/html5/thumbnails/128.jpg)
LOGOExample
+ / + 2 2 2 / – 3 2 + 1 0+ / + 2 2 2 / – 3 2 1+ / + 2 2 2 / 1 1+ / + 2 2 2 1+ / 4 2 1
+ 2 1
128
Dis
cret
e S
truc
ture
s
Fal
l 138
9
![Page 129: LOGO. Trees: In these slides: Introduction to trees Applications of trees Tree traversal 2](https://reader038.vdocuments.site/reader038/viewer/2022110210/56649eab5503460f94bb0408/html5/thumbnails/129.jpg)
LOGOExample
+ / + 2 2 2 / – 3 2 + 1 0+ / + 2 2 2 / – 3 2 1+ / + 2 2 2 / 1 1+ / + 2 2 2 1+ / 4 2 1
+ 2 1
129
Dis
cret
e S
truc
ture
s
Fal
l 138
9
![Page 130: LOGO. Trees: In these slides: Introduction to trees Applications of trees Tree traversal 2](https://reader038.vdocuments.site/reader038/viewer/2022110210/56649eab5503460f94bb0408/html5/thumbnails/130.jpg)
LOGOExample
+ / + 2 2 2 / – 3 2 + 1 0+ / + 2 2 2 / – 3 2 1+ / + 2 2 2 / 1 1+ / + 2 2 2 1+ / 4 2 1
+ 2 1
3130
Dis
cret
e S
truc
ture
s
Fal
l 138
9
![Page 131: LOGO. Trees: In these slides: Introduction to trees Applications of trees Tree traversal 2](https://reader038.vdocuments.site/reader038/viewer/2022110210/56649eab5503460f94bb0408/html5/thumbnails/131.jpg)
LOGOPostfix Notation (Reverse Polish)
• Traverse in postorder
+
– +
/
+ 2
x y x 3 y 2
131
Dis
cret
e S
truc
ture
s
Fal
l 138
9
![Page 132: LOGO. Trees: In these slides: Introduction to trees Applications of trees Tree traversal 2](https://reader038.vdocuments.site/reader038/viewer/2022110210/56649eab5503460f94bb0408/html5/thumbnails/132.jpg)
LOGOPostfix Notation (Reverse Polish)
• Traverse in postorder
x
+
– +
/
+ 2
x y x 3 y 2
132
Dis
cret
e S
truc
ture
s
Fal
l 138
9
![Page 133: LOGO. Trees: In these slides: Introduction to trees Applications of trees Tree traversal 2](https://reader038.vdocuments.site/reader038/viewer/2022110210/56649eab5503460f94bb0408/html5/thumbnails/133.jpg)
LOGOPostfix Notation (Reverse Polish)
• Traverse in postorder
x y
+
– +
/
+ 2
x y x 3 y 2
133
Dis
cret
e S
truc
ture
s
Fal
l 138
9
![Page 134: LOGO. Trees: In these slides: Introduction to trees Applications of trees Tree traversal 2](https://reader038.vdocuments.site/reader038/viewer/2022110210/56649eab5503460f94bb0408/html5/thumbnails/134.jpg)
LOGOPostfix Notation (Reverse Polish)
• Traverse in postorder
x +y
+
– +
/
+ 2
x y x 3 y 2
134
Dis
cret
e S
truc
ture
s
Fal
l 138
9
![Page 135: LOGO. Trees: In these slides: Introduction to trees Applications of trees Tree traversal 2](https://reader038.vdocuments.site/reader038/viewer/2022110210/56649eab5503460f94bb0408/html5/thumbnails/135.jpg)
LOGOPostfix Notation (Reverse Polish)
• Traverse in postorder
x +y 2
+
– +
/
+ 2
x y x 3 y 2
135
Dis
cret
e S
truc
ture
s
Fal
l 138
9
![Page 136: LOGO. Trees: In these slides: Introduction to trees Applications of trees Tree traversal 2](https://reader038.vdocuments.site/reader038/viewer/2022110210/56649eab5503460f94bb0408/html5/thumbnails/136.jpg)
LOGOPostfix Notation (Reverse Polish)
• Traverse in postorder
x +y 2
+
– +
/
+ 2
x y x 3 y 2
136
Dis
cret
e S
truc
ture
s
Fal
l 138
9
![Page 137: LOGO. Trees: In these slides: Introduction to trees Applications of trees Tree traversal 2](https://reader038.vdocuments.site/reader038/viewer/2022110210/56649eab5503460f94bb0408/html5/thumbnails/137.jpg)
LOGOPostfix Notation (Reverse Polish)
• Traverse in postorder
x +y 2 x
+
– +
/
+ 2
x y x 3 y 2
137
Dis
cret
e S
truc
ture
s
Fal
l 138
9
![Page 138: LOGO. Trees: In these slides: Introduction to trees Applications of trees Tree traversal 2](https://reader038.vdocuments.site/reader038/viewer/2022110210/56649eab5503460f94bb0408/html5/thumbnails/138.jpg)
LOGOPostfix Notation (Reverse Polish)
• Traverse in postorder
x +y 2 x 3
+
– +
/
+ 2
x y x 3 y 2
138
Dis
cret
e S
truc
ture
s
Fal
l 138
9
![Page 139: LOGO. Trees: In these slides: Introduction to trees Applications of trees Tree traversal 2](https://reader038.vdocuments.site/reader038/viewer/2022110210/56649eab5503460f94bb0408/html5/thumbnails/139.jpg)
LOGOPostfix Notation (Reverse Polish)
• Traverse in postorder
x +y 2 x –3
+
– +
/
+ 2
x y x 3 y 2
139
Dis
cret
e S
truc
ture
s
Fal
l 138
9
![Page 140: LOGO. Trees: In these slides: Introduction to trees Applications of trees Tree traversal 2](https://reader038.vdocuments.site/reader038/viewer/2022110210/56649eab5503460f94bb0408/html5/thumbnails/140.jpg)
LOGOPostfix Notation (Reverse Polish)
• Traverse in postorder
x +y 2 x –3 y
+
– +
/
+ 2
x y x 3 y 2
140
Dis
cret
e S
truc
ture
s
Fal
l 138
9
![Page 141: LOGO. Trees: In these slides: Introduction to trees Applications of trees Tree traversal 2](https://reader038.vdocuments.site/reader038/viewer/2022110210/56649eab5503460f94bb0408/html5/thumbnails/141.jpg)
LOGOPostfix Notation (Reverse Polish)
• Traverse in postorder
x +y 2 x –3 y 2
+
– +
/
+ 2
x y x 3 y 2
141
Dis
cret
e S
truc
ture
s
Fal
l 138
9
![Page 142: LOGO. Trees: In these slides: Introduction to trees Applications of trees Tree traversal 2](https://reader038.vdocuments.site/reader038/viewer/2022110210/56649eab5503460f94bb0408/html5/thumbnails/142.jpg)
LOGOPostfix Notation (Reverse Polish)
• Traverse in postorder
x +y 2 x –3 y +2
+
– +
/
+ 2
x y x 3 y 2
142
Dis
cret
e S
truc
ture
s
Fal
l 138
9
![Page 143: LOGO. Trees: In these slides: Introduction to trees Applications of trees Tree traversal 2](https://reader038.vdocuments.site/reader038/viewer/2022110210/56649eab5503460f94bb0408/html5/thumbnails/143.jpg)
LOGOPostfix Notation (Reverse Polish)
• Traverse in postorder
x +y 2 x –3 /y +2
+
– +
/
+ 2
x y x 3 y 2
143
Dis
cret
e S
truc
ture
s
Fal
l 138
9
![Page 144: LOGO. Trees: In these slides: Introduction to trees Applications of trees Tree traversal 2](https://reader038.vdocuments.site/reader038/viewer/2022110210/56649eab5503460f94bb0408/html5/thumbnails/144.jpg)
LOGOPostfix Notation (Reverse Polish)
• Traverse in postorder
x +y 2 +x –3 /y +2
+
– +
/
+ 2
x y x 3 y 2
144
Dis
cret
e S
truc
ture
s
Fal
l 138
9
![Page 145: LOGO. Trees: In these slides: Introduction to trees Applications of trees Tree traversal 2](https://reader038.vdocuments.site/reader038/viewer/2022110210/56649eab5503460f94bb0408/html5/thumbnails/145.jpg)
LOGO
In an postfix expression, a binary operator follows its two operands
The expression is evaluated left-right
Look for the first operator from the left
Evaluate the operator with the two operands immediately to its left
Evaluating Postfix Notation
145
Dis
cret
e S
truc
ture
s
Fal
l 138
9
![Page 146: LOGO. Trees: In these slides: Introduction to trees Applications of trees Tree traversal 2](https://reader038.vdocuments.site/reader038/viewer/2022110210/56649eab5503460f94bb0408/html5/thumbnails/146.jpg)
LOGOExample
2 2 + 2 / 3 2 – 1 0 + / +
146
Dis
cret
e S
truc
ture
s
Fal
l 138
9
![Page 147: LOGO. Trees: In these slides: Introduction to trees Applications of trees Tree traversal 2](https://reader038.vdocuments.site/reader038/viewer/2022110210/56649eab5503460f94bb0408/html5/thumbnails/147.jpg)
LOGOExample
2 2 + 2 / 3 2 – 1 0 + / +
147
Dis
cret
e S
truc
ture
s
Fal
l 138
9
![Page 148: LOGO. Trees: In these slides: Introduction to trees Applications of trees Tree traversal 2](https://reader038.vdocuments.site/reader038/viewer/2022110210/56649eab5503460f94bb0408/html5/thumbnails/148.jpg)
LOGOExample
2 2 + 2 / 3 2 – 1 0 + / +
4 2 / 3 2 – 1 0 + / +
148
Dis
cret
e S
truc
ture
s
Fal
l 138
9
![Page 149: LOGO. Trees: In these slides: Introduction to trees Applications of trees Tree traversal 2](https://reader038.vdocuments.site/reader038/viewer/2022110210/56649eab5503460f94bb0408/html5/thumbnails/149.jpg)
LOGOExample
2 2 + 2 / 3 2 – 1 0 + / +
4 2 / 3 2 – 1 0 + / +
149
Dis
cret
e S
truc
ture
s
Fal
l 138
9
![Page 150: LOGO. Trees: In these slides: Introduction to trees Applications of trees Tree traversal 2](https://reader038.vdocuments.site/reader038/viewer/2022110210/56649eab5503460f94bb0408/html5/thumbnails/150.jpg)
LOGOExample
2 2 + 2 / 3 2 – 1 0 + / +
4 2 / 3 2 – 1 0 + / +
2 3 2 – 1 0 + / +
150
Dis
cret
e S
truc
ture
s
Fal
l 138
9
![Page 151: LOGO. Trees: In these slides: Introduction to trees Applications of trees Tree traversal 2](https://reader038.vdocuments.site/reader038/viewer/2022110210/56649eab5503460f94bb0408/html5/thumbnails/151.jpg)
LOGOExample
2 2 + 2 / 3 2 – 1 0 + / +
4 2 / 3 2 – 1 0 + / +
2 3 2 – 1 0 + / +
151
Dis
cret
e S
truc
ture
s
Fal
l 138
9
![Page 152: LOGO. Trees: In these slides: Introduction to trees Applications of trees Tree traversal 2](https://reader038.vdocuments.site/reader038/viewer/2022110210/56649eab5503460f94bb0408/html5/thumbnails/152.jpg)
LOGOExample
2 2 + 2 / 3 2 – 1 0 + / +
4 2 / 3 2 – 1 0 + / +
2 3 2 – 1 0 + / +
2 1 1 0 + / +
152
Dis
cret
e S
truc
ture
s
Fal
l 138
9
![Page 153: LOGO. Trees: In these slides: Introduction to trees Applications of trees Tree traversal 2](https://reader038.vdocuments.site/reader038/viewer/2022110210/56649eab5503460f94bb0408/html5/thumbnails/153.jpg)
LOGOExample
2 2 + 2 / 3 2 – 1 0 + / +
4 2 / 3 2 – 1 0 + / +
2 3 2 – 1 0 + / +
2 1 1 0 + / +
153
Dis
cret
e S
truc
ture
s
Fal
l 138
9
![Page 154: LOGO. Trees: In these slides: Introduction to trees Applications of trees Tree traversal 2](https://reader038.vdocuments.site/reader038/viewer/2022110210/56649eab5503460f94bb0408/html5/thumbnails/154.jpg)
LOGOExample
2 2 + 2 / 3 2 – 1 0 + / +
4 2 / 3 2 – 1 0 + / +
2 3 2 – 1 0 + / +
2 1 1 0 + / +
2 1 1 / +
154
Dis
cret
e S
truc
ture
s
Fal
l 138
9
![Page 155: LOGO. Trees: In these slides: Introduction to trees Applications of trees Tree traversal 2](https://reader038.vdocuments.site/reader038/viewer/2022110210/56649eab5503460f94bb0408/html5/thumbnails/155.jpg)
LOGOExample
2 2 + 2 / 3 2 – 1 0 + / +
4 2 / 3 2 – 1 0 + / +
2 3 2 – 1 0 + / +
2 1 1 0 + / +
2 1 1 / +
155
Dis
cret
e S
truc
ture
s
Fal
l 138
9
![Page 156: LOGO. Trees: In these slides: Introduction to trees Applications of trees Tree traversal 2](https://reader038.vdocuments.site/reader038/viewer/2022110210/56649eab5503460f94bb0408/html5/thumbnails/156.jpg)
LOGOExample
2 2 + 2 / 3 2 – 1 0 + / +
4 2 / 3 2 – 1 0 + / +
2 3 2 – 1 0 + / +
2 1 1 0 + / +
2 1 1 / +
2 1 +
156
Dis
cret
e S
truc
ture
s
Fal
l 138
9
![Page 157: LOGO. Trees: In these slides: Introduction to trees Applications of trees Tree traversal 2](https://reader038.vdocuments.site/reader038/viewer/2022110210/56649eab5503460f94bb0408/html5/thumbnails/157.jpg)
LOGOExample
2 2 + 2 / 3 2 – 1 0 + / +
4 2 / 3 2 – 1 0 + / +
2 3 2 – 1 0 + / +
2 1 1 0 + / +
2 1 1 / +
2 1 +
157
Dis
cret
e S
truc
ture
s
Fal
l 138
9
![Page 158: LOGO. Trees: In these slides: Introduction to trees Applications of trees Tree traversal 2](https://reader038.vdocuments.site/reader038/viewer/2022110210/56649eab5503460f94bb0408/html5/thumbnails/158.jpg)
LOGOExample
3
2 2 + 2 / 3 2 – 1 0 + / +
4 2 / 3 2 – 1 0 + / +
2 3 2 – 1 0 + / +
2 1 1 0 + / +
2 1 1 / +
2 1 +
158
Dis
cret
e S
truc
ture
s
Fal
l 138
9
![Page 159: LOGO. Trees: In these slides: Introduction to trees Applications of trees Tree traversal 2](https://reader038.vdocuments.site/reader038/viewer/2022110210/56649eab5503460f94bb0408/html5/thumbnails/159.jpg)
LOGO
159
Spanning Trees
You will learn about the following topics in tree later in other courses: Spanning Trees Minimum Spanning Trees
Dis
cret
e S
truc
ture
s
Fal
l 138
9
![Page 160: LOGO. Trees: In these slides: Introduction to trees Applications of trees Tree traversal 2](https://reader038.vdocuments.site/reader038/viewer/2022110210/56649eab5503460f94bb0408/html5/thumbnails/160.jpg)
LOGO
LOGO
Any Question?Good Luck