Discrete Mathematics - Treesnlp.jbnu.ac.kr/DM/slides/ch11_trees.pdfDiscrete Mathematics Trees H....
Transcript of Discrete Mathematics - Treesnlp.jbnu.ac.kr/DM/slides/ch11_trees.pdfDiscrete Mathematics Trees H....
![Page 1: Discrete Mathematics - Treesnlp.jbnu.ac.kr/DM/slides/ch11_trees.pdfDiscrete Mathematics Trees H. Turgut Uyar Ay¸seg¨ul Gencata Yayımlı Emre Harmancı 2001-2016](https://reader035.fdocuments.in/reader035/viewer/2022062505/5edc7621ad6a402d66672064/html5/thumbnails/1.jpg)
Discrete MathematicsTrees
H. Turgut Uyar Aysegul Gencata Yayımlı Emre Harmancı
2001-2016
![Page 2: Discrete Mathematics - Treesnlp.jbnu.ac.kr/DM/slides/ch11_trees.pdfDiscrete Mathematics Trees H. Turgut Uyar Ay¸seg¨ul Gencata Yayımlı Emre Harmancı 2001-2016](https://reader035.fdocuments.in/reader035/viewer/2022062505/5edc7621ad6a402d66672064/html5/thumbnails/2.jpg)
License
c© 2001-2016 T. Uyar, A. Yayımlı, E. Harmancı
You are free to:
Share – copy and redistribute the material in any medium or format
Adapt – remix, transform, and build upon the material
Under the following terms:
Attribution – You must give appropriate credit, provide a link to the license,and indicate if changes were made.
NonCommercial – You may not use the material for commercial purposes.
ShareAlike – If you remix, transform, or build upon the material, you mustdistribute your contributions under the same license as the original.
For more information:https://creativecommons.org/licenses/by-nc-sa/4.0/
Read the full license:
https://creativecommons.org/licenses/by-nc-sa/4.0/legalcode
![Page 3: Discrete Mathematics - Treesnlp.jbnu.ac.kr/DM/slides/ch11_trees.pdfDiscrete Mathematics Trees H. Turgut Uyar Ay¸seg¨ul Gencata Yayımlı Emre Harmancı 2001-2016](https://reader035.fdocuments.in/reader035/viewer/2022062505/5edc7621ad6a402d66672064/html5/thumbnails/3.jpg)
Topics
1 TreesIntroductionRooted TreesBinary TreesDecision Trees
2 Tree ProblemsMinimum Spanning Tree
![Page 4: Discrete Mathematics - Treesnlp.jbnu.ac.kr/DM/slides/ch11_trees.pdfDiscrete Mathematics Trees H. Turgut Uyar Ay¸seg¨ul Gencata Yayımlı Emre Harmancı 2001-2016](https://reader035.fdocuments.in/reader035/viewer/2022062505/5edc7621ad6a402d66672064/html5/thumbnails/4.jpg)
Topics
1 TreesIntroductionRooted TreesBinary TreesDecision Trees
2 Tree ProblemsMinimum Spanning Tree
![Page 5: Discrete Mathematics - Treesnlp.jbnu.ac.kr/DM/slides/ch11_trees.pdfDiscrete Mathematics Trees H. Turgut Uyar Ay¸seg¨ul Gencata Yayımlı Emre Harmancı 2001-2016](https://reader035.fdocuments.in/reader035/viewer/2022062505/5edc7621ad6a402d66672064/html5/thumbnails/5.jpg)
Tree
Definition
tree: connected graph with no cycle
examples
![Page 6: Discrete Mathematics - Treesnlp.jbnu.ac.kr/DM/slides/ch11_trees.pdfDiscrete Mathematics Trees H. Turgut Uyar Ay¸seg¨ul Gencata Yayımlı Emre Harmancı 2001-2016](https://reader035.fdocuments.in/reader035/viewer/2022062505/5edc7621ad6a402d66672064/html5/thumbnails/6.jpg)
Tree Theorems
Theorem
T is a tree (T is connected and contains no cycle).⇔
There is one and only one pathbetween any two distinct nodes in T .
⇔T is connected, but if any edge is removed
it will no longer be connected.⇔
T contains no cycle, but if an edge is addedbetween any pair of nodes one and only one cycle will be formed.
![Page 7: Discrete Mathematics - Treesnlp.jbnu.ac.kr/DM/slides/ch11_trees.pdfDiscrete Mathematics Trees H. Turgut Uyar Ay¸seg¨ul Gencata Yayımlı Emre Harmancı 2001-2016](https://reader035.fdocuments.in/reader035/viewer/2022062505/5edc7621ad6a402d66672064/html5/thumbnails/7.jpg)
Tree Theorems
Theorem
|E | = |V | − 1
proof method: induction on the number of edges
![Page 8: Discrete Mathematics - Treesnlp.jbnu.ac.kr/DM/slides/ch11_trees.pdfDiscrete Mathematics Trees H. Turgut Uyar Ay¸seg¨ul Gencata Yayımlı Emre Harmancı 2001-2016](https://reader035.fdocuments.in/reader035/viewer/2022062505/5edc7621ad6a402d66672064/html5/thumbnails/8.jpg)
Tree Theorems
Proof: Base step.
|E | = 0 ⇒ |V | = 1
|E | = 1 ⇒ |V | = 2
|E | = 2 ⇒ |V | = 3
assume that |E | = |V | − 1 for |E | ≤ k
![Page 9: Discrete Mathematics - Treesnlp.jbnu.ac.kr/DM/slides/ch11_trees.pdfDiscrete Mathematics Trees H. Turgut Uyar Ay¸seg¨ul Gencata Yayımlı Emre Harmancı 2001-2016](https://reader035.fdocuments.in/reader035/viewer/2022062505/5edc7621ad6a402d66672064/html5/thumbnails/9.jpg)
Tree Theorems
Proof: Base step.
|E | = 0 ⇒ |V | = 1
|E | = 1 ⇒ |V | = 2
|E | = 2 ⇒ |V | = 3
assume that |E | = |V | − 1 for |E | ≤ k
![Page 10: Discrete Mathematics - Treesnlp.jbnu.ac.kr/DM/slides/ch11_trees.pdfDiscrete Mathematics Trees H. Turgut Uyar Ay¸seg¨ul Gencata Yayımlı Emre Harmancı 2001-2016](https://reader035.fdocuments.in/reader035/viewer/2022062505/5edc7621ad6a402d66672064/html5/thumbnails/10.jpg)
Tree Theorems
Proof: Induction step.
|E | = k + 1
remove edge (y , z):T1 = (V1,E1), T2 = (V2,E2)
|V | = |V1|+ |V2|= |E1|+ 1 + |E2|+ 1
= (|E1|+ |E2|+ 1) + 1
= |E |+ 1
![Page 11: Discrete Mathematics - Treesnlp.jbnu.ac.kr/DM/slides/ch11_trees.pdfDiscrete Mathematics Trees H. Turgut Uyar Ay¸seg¨ul Gencata Yayımlı Emre Harmancı 2001-2016](https://reader035.fdocuments.in/reader035/viewer/2022062505/5edc7621ad6a402d66672064/html5/thumbnails/11.jpg)
Tree Theorems
Proof: Induction step.
|E | = k + 1
remove edge (y , z):T1 = (V1,E1), T2 = (V2,E2)
|V | = |V1|+ |V2|= |E1|+ 1 + |E2|+ 1
= (|E1|+ |E2|+ 1) + 1
= |E |+ 1
![Page 12: Discrete Mathematics - Treesnlp.jbnu.ac.kr/DM/slides/ch11_trees.pdfDiscrete Mathematics Trees H. Turgut Uyar Ay¸seg¨ul Gencata Yayımlı Emre Harmancı 2001-2016](https://reader035.fdocuments.in/reader035/viewer/2022062505/5edc7621ad6a402d66672064/html5/thumbnails/12.jpg)
Tree Theorems
Proof: Induction step.
|E | = k + 1
remove edge (y , z):T1 = (V1,E1), T2 = (V2,E2)
|V | = |V1|+ |V2|= |E1|+ 1 + |E2|+ 1
= (|E1|+ |E2|+ 1) + 1
= |E |+ 1
![Page 13: Discrete Mathematics - Treesnlp.jbnu.ac.kr/DM/slides/ch11_trees.pdfDiscrete Mathematics Trees H. Turgut Uyar Ay¸seg¨ul Gencata Yayımlı Emre Harmancı 2001-2016](https://reader035.fdocuments.in/reader035/viewer/2022062505/5edc7621ad6a402d66672064/html5/thumbnails/13.jpg)
Tree Theorems
Proof: Induction step.
|E | = k + 1
remove edge (y , z):T1 = (V1,E1), T2 = (V2,E2)
|V | = |V1|+ |V2|= |E1|+ 1 + |E2|+ 1
= (|E1|+ |E2|+ 1) + 1
= |E |+ 1
![Page 14: Discrete Mathematics - Treesnlp.jbnu.ac.kr/DM/slides/ch11_trees.pdfDiscrete Mathematics Trees H. Turgut Uyar Ay¸seg¨ul Gencata Yayımlı Emre Harmancı 2001-2016](https://reader035.fdocuments.in/reader035/viewer/2022062505/5edc7621ad6a402d66672064/html5/thumbnails/14.jpg)
Tree Theorems
Proof: Induction step.
|E | = k + 1
remove edge (y , z):T1 = (V1,E1), T2 = (V2,E2)
|V | = |V1|+ |V2|= |E1|+ 1 + |E2|+ 1
= (|E1|+ |E2|+ 1) + 1
= |E |+ 1
![Page 15: Discrete Mathematics - Treesnlp.jbnu.ac.kr/DM/slides/ch11_trees.pdfDiscrete Mathematics Trees H. Turgut Uyar Ay¸seg¨ul Gencata Yayımlı Emre Harmancı 2001-2016](https://reader035.fdocuments.in/reader035/viewer/2022062505/5edc7621ad6a402d66672064/html5/thumbnails/15.jpg)
Tree Theorems
Proof: Induction step.
|E | = k + 1
remove edge (y , z):T1 = (V1,E1), T2 = (V2,E2)
|V | = |V1|+ |V2|= |E1|+ 1 + |E2|+ 1
= (|E1|+ |E2|+ 1) + 1
= |E |+ 1
![Page 16: Discrete Mathematics - Treesnlp.jbnu.ac.kr/DM/slides/ch11_trees.pdfDiscrete Mathematics Trees H. Turgut Uyar Ay¸seg¨ul Gencata Yayımlı Emre Harmancı 2001-2016](https://reader035.fdocuments.in/reader035/viewer/2022062505/5edc7621ad6a402d66672064/html5/thumbnails/16.jpg)
Tree Theorems
Theorem
T is a tree (T is connected and contains no cycle).⇔
T is connected and |E | = |V | − 1.⇔
T contains no cycle and |E | = |V | − 1.
![Page 17: Discrete Mathematics - Treesnlp.jbnu.ac.kr/DM/slides/ch11_trees.pdfDiscrete Mathematics Trees H. Turgut Uyar Ay¸seg¨ul Gencata Yayımlı Emre Harmancı 2001-2016](https://reader035.fdocuments.in/reader035/viewer/2022062505/5edc7621ad6a402d66672064/html5/thumbnails/17.jpg)
Tree Theorems
Theorem
In a tree, there are at least two nodes with degree 1.
Proof.
2|E | =∑
v∈V dv
assume: only 1 node with degree 1:⇒ 2|E | ≥ 2(|V | − 1) + 1⇒ 2|E | ≥ 2|V | − 1⇒ |E | ≥ |V | − 1
2 > |V | − 1
![Page 18: Discrete Mathematics - Treesnlp.jbnu.ac.kr/DM/slides/ch11_trees.pdfDiscrete Mathematics Trees H. Turgut Uyar Ay¸seg¨ul Gencata Yayımlı Emre Harmancı 2001-2016](https://reader035.fdocuments.in/reader035/viewer/2022062505/5edc7621ad6a402d66672064/html5/thumbnails/18.jpg)
Tree Theorems
Theorem
In a tree, there are at least two nodes with degree 1.
Proof.
2|E | =∑
v∈V dv
assume: only 1 node with degree 1:⇒ 2|E | ≥ 2(|V | − 1) + 1⇒ 2|E | ≥ 2|V | − 1⇒ |E | ≥ |V | − 1
2 > |V | − 1
![Page 19: Discrete Mathematics - Treesnlp.jbnu.ac.kr/DM/slides/ch11_trees.pdfDiscrete Mathematics Trees H. Turgut Uyar Ay¸seg¨ul Gencata Yayımlı Emre Harmancı 2001-2016](https://reader035.fdocuments.in/reader035/viewer/2022062505/5edc7621ad6a402d66672064/html5/thumbnails/19.jpg)
Tree Theorems
Theorem
In a tree, there are at least two nodes with degree 1.
Proof.
2|E | =∑
v∈V dv
assume: only 1 node with degree 1:⇒ 2|E | ≥ 2(|V | − 1) + 1⇒ 2|E | ≥ 2|V | − 1⇒ |E | ≥ |V | − 1
2 > |V | − 1
![Page 20: Discrete Mathematics - Treesnlp.jbnu.ac.kr/DM/slides/ch11_trees.pdfDiscrete Mathematics Trees H. Turgut Uyar Ay¸seg¨ul Gencata Yayımlı Emre Harmancı 2001-2016](https://reader035.fdocuments.in/reader035/viewer/2022062505/5edc7621ad6a402d66672064/html5/thumbnails/20.jpg)
Tree Theorems
Theorem
In a tree, there are at least two nodes with degree 1.
Proof.
2|E | =∑
v∈V dv
assume: only 1 node with degree 1:⇒ 2|E | ≥ 2(|V | − 1) + 1⇒ 2|E | ≥ 2|V | − 1⇒ |E | ≥ |V | − 1
2 > |V | − 1
![Page 21: Discrete Mathematics - Treesnlp.jbnu.ac.kr/DM/slides/ch11_trees.pdfDiscrete Mathematics Trees H. Turgut Uyar Ay¸seg¨ul Gencata Yayımlı Emre Harmancı 2001-2016](https://reader035.fdocuments.in/reader035/viewer/2022062505/5edc7621ad6a402d66672064/html5/thumbnails/21.jpg)
Tree Theorems
Theorem
In a tree, there are at least two nodes with degree 1.
Proof.
2|E | =∑
v∈V dv
assume: only 1 node with degree 1:⇒ 2|E | ≥ 2(|V | − 1) + 1⇒ 2|E | ≥ 2|V | − 1⇒ |E | ≥ |V | − 1
2 > |V | − 1
![Page 22: Discrete Mathematics - Treesnlp.jbnu.ac.kr/DM/slides/ch11_trees.pdfDiscrete Mathematics Trees H. Turgut Uyar Ay¸seg¨ul Gencata Yayımlı Emre Harmancı 2001-2016](https://reader035.fdocuments.in/reader035/viewer/2022062505/5edc7621ad6a402d66672064/html5/thumbnails/22.jpg)
Tree Theorems
Theorem
In a tree, there are at least two nodes with degree 1.
Proof.
2|E | =∑
v∈V dv
assume: only 1 node with degree 1:⇒ 2|E | ≥ 2(|V | − 1) + 1⇒ 2|E | ≥ 2|V | − 1⇒ |E | ≥ |V | − 1
2 > |V | − 1
![Page 23: Discrete Mathematics - Treesnlp.jbnu.ac.kr/DM/slides/ch11_trees.pdfDiscrete Mathematics Trees H. Turgut Uyar Ay¸seg¨ul Gencata Yayımlı Emre Harmancı 2001-2016](https://reader035.fdocuments.in/reader035/viewer/2022062505/5edc7621ad6a402d66672064/html5/thumbnails/23.jpg)
Tree Theorems
Theorem
In a tree, there are at least two nodes with degree 1.
Proof.
2|E | =∑
v∈V dv
assume: only 1 node with degree 1:⇒ 2|E | ≥ 2(|V | − 1) + 1⇒ 2|E | ≥ 2|V | − 1⇒ |E | ≥ |V | − 1
2 > |V | − 1
![Page 24: Discrete Mathematics - Treesnlp.jbnu.ac.kr/DM/slides/ch11_trees.pdfDiscrete Mathematics Trees H. Turgut Uyar Ay¸seg¨ul Gencata Yayımlı Emre Harmancı 2001-2016](https://reader035.fdocuments.in/reader035/viewer/2022062505/5edc7621ad6a402d66672064/html5/thumbnails/24.jpg)
Topics
1 TreesIntroductionRooted TreesBinary TreesDecision Trees
2 Tree ProblemsMinimum Spanning Tree
![Page 25: Discrete Mathematics - Treesnlp.jbnu.ac.kr/DM/slides/ch11_trees.pdfDiscrete Mathematics Trees H. Turgut Uyar Ay¸seg¨ul Gencata Yayımlı Emre Harmancı 2001-2016](https://reader035.fdocuments.in/reader035/viewer/2022062505/5edc7621ad6a402d66672064/html5/thumbnails/25.jpg)
Rooted Tree
hierarchy between nodes
creates implicit direction on edges: in and out degrees
in-degree 0: root (only 1 such node)
out-degree 0: leaf
not a leaf: internal node
![Page 26: Discrete Mathematics - Treesnlp.jbnu.ac.kr/DM/slides/ch11_trees.pdfDiscrete Mathematics Trees H. Turgut Uyar Ay¸seg¨ul Gencata Yayımlı Emre Harmancı 2001-2016](https://reader035.fdocuments.in/reader035/viewer/2022062505/5edc7621ad6a402d66672064/html5/thumbnails/26.jpg)
Rooted Tree
hierarchy between nodes
creates implicit direction on edges: in and out degrees
in-degree 0: root (only 1 such node)
out-degree 0: leaf
not a leaf: internal node
![Page 27: Discrete Mathematics - Treesnlp.jbnu.ac.kr/DM/slides/ch11_trees.pdfDiscrete Mathematics Trees H. Turgut Uyar Ay¸seg¨ul Gencata Yayımlı Emre Harmancı 2001-2016](https://reader035.fdocuments.in/reader035/viewer/2022062505/5edc7621ad6a402d66672064/html5/thumbnails/27.jpg)
Node Level
level of node: distance from root
parent: adjacent node closer to root (only 1 such node)
child: adjacent nodes further from root
sibling: nodes with same parent
depth of tree: maximum level in tree
![Page 28: Discrete Mathematics - Treesnlp.jbnu.ac.kr/DM/slides/ch11_trees.pdfDiscrete Mathematics Trees H. Turgut Uyar Ay¸seg¨ul Gencata Yayımlı Emre Harmancı 2001-2016](https://reader035.fdocuments.in/reader035/viewer/2022062505/5edc7621ad6a402d66672064/html5/thumbnails/28.jpg)
Rooted Tree Example
root: r
leaves: x y z u v
internal nodes: r p n t s q w
parent of y : wchildren of w : y and z
y and z are siblings
![Page 29: Discrete Mathematics - Treesnlp.jbnu.ac.kr/DM/slides/ch11_trees.pdfDiscrete Mathematics Trees H. Turgut Uyar Ay¸seg¨ul Gencata Yayımlı Emre Harmancı 2001-2016](https://reader035.fdocuments.in/reader035/viewer/2022062505/5edc7621ad6a402d66672064/html5/thumbnails/29.jpg)
Rooted Tree Example
Book
C1
S1.1S1.2
C2
C3
S3.1S3.2
S3.2.1S3.2.2
S3.3
![Page 30: Discrete Mathematics - Treesnlp.jbnu.ac.kr/DM/slides/ch11_trees.pdfDiscrete Mathematics Trees H. Turgut Uyar Ay¸seg¨ul Gencata Yayımlı Emre Harmancı 2001-2016](https://reader035.fdocuments.in/reader035/viewer/2022062505/5edc7621ad6a402d66672064/html5/thumbnails/30.jpg)
Ordered Rooted Tree
siblings ordered from left to right
universal address system
root: 0
children of root: 1, 2, 3, . . .
v : internal node with address achildren of v : a.1, a.2, a.3, . . .
![Page 31: Discrete Mathematics - Treesnlp.jbnu.ac.kr/DM/slides/ch11_trees.pdfDiscrete Mathematics Trees H. Turgut Uyar Ay¸seg¨ul Gencata Yayımlı Emre Harmancı 2001-2016](https://reader035.fdocuments.in/reader035/viewer/2022062505/5edc7621ad6a402d66672064/html5/thumbnails/31.jpg)
Lexicographic Order
address A comes before address B if one of:
A = x1x2 . . . xixj . . .B = x1x2 . . . xixk . . .xj comes before xk
A = x1x2 . . . xi
B = x1x2 . . . xixk . . .
![Page 32: Discrete Mathematics - Treesnlp.jbnu.ac.kr/DM/slides/ch11_trees.pdfDiscrete Mathematics Trees H. Turgut Uyar Ay¸seg¨ul Gencata Yayımlı Emre Harmancı 2001-2016](https://reader035.fdocuments.in/reader035/viewer/2022062505/5edc7621ad6a402d66672064/html5/thumbnails/32.jpg)
Lexicographic Order
address A comes before address B if one of:
A = x1x2 . . . xixj . . .B = x1x2 . . . xixk . . .xj comes before xk
A = x1x2 . . . xi
B = x1x2 . . . xixk . . .
![Page 33: Discrete Mathematics - Treesnlp.jbnu.ac.kr/DM/slides/ch11_trees.pdfDiscrete Mathematics Trees H. Turgut Uyar Ay¸seg¨ul Gencata Yayımlı Emre Harmancı 2001-2016](https://reader035.fdocuments.in/reader035/viewer/2022062505/5edc7621ad6a402d66672064/html5/thumbnails/33.jpg)
Lexicographic Order Example
0 - 1 - 1.1 - 1.2- 1.2.1 - 1.2.2 - 1.2.3- 1.2.3.1 - 1.2.3.2- 1.3 - 1.4 - 2- 2.1 - 2.2 - 2.2.1- 3 - 3.1 - 3.2
![Page 34: Discrete Mathematics - Treesnlp.jbnu.ac.kr/DM/slides/ch11_trees.pdfDiscrete Mathematics Trees H. Turgut Uyar Ay¸seg¨ul Gencata Yayımlı Emre Harmancı 2001-2016](https://reader035.fdocuments.in/reader035/viewer/2022062505/5edc7621ad6a402d66672064/html5/thumbnails/34.jpg)
Topics
1 TreesIntroductionRooted TreesBinary TreesDecision Trees
2 Tree ProblemsMinimum Spanning Tree
![Page 35: Discrete Mathematics - Treesnlp.jbnu.ac.kr/DM/slides/ch11_trees.pdfDiscrete Mathematics Trees H. Turgut Uyar Ay¸seg¨ul Gencata Yayımlı Emre Harmancı 2001-2016](https://reader035.fdocuments.in/reader035/viewer/2022062505/5edc7621ad6a402d66672064/html5/thumbnails/35.jpg)
Binary Trees
T = (V ,E ) is a binary tree:∀v ∈ V [dv
o ∈ {0, 1, 2}]
T = (V ,E ) is a complete binary tree:∀v ∈ V [dv
o ∈ {0, 2}]
![Page 36: Discrete Mathematics - Treesnlp.jbnu.ac.kr/DM/slides/ch11_trees.pdfDiscrete Mathematics Trees H. Turgut Uyar Ay¸seg¨ul Gencata Yayımlı Emre Harmancı 2001-2016](https://reader035.fdocuments.in/reader035/viewer/2022062505/5edc7621ad6a402d66672064/html5/thumbnails/36.jpg)
Expression Tree
binary operations can be represented as binary trees
root: operator, children: operands
mathematical expression can be represented as trees
internal nodes: operators, leaves: variables and values
![Page 37: Discrete Mathematics - Treesnlp.jbnu.ac.kr/DM/slides/ch11_trees.pdfDiscrete Mathematics Trees H. Turgut Uyar Ay¸seg¨ul Gencata Yayımlı Emre Harmancı 2001-2016](https://reader035.fdocuments.in/reader035/viewer/2022062505/5edc7621ad6a402d66672064/html5/thumbnails/37.jpg)
Expression Tree Examples
7− a a + b
![Page 38: Discrete Mathematics - Treesnlp.jbnu.ac.kr/DM/slides/ch11_trees.pdfDiscrete Mathematics Trees H. Turgut Uyar Ay¸seg¨ul Gencata Yayımlı Emre Harmancı 2001-2016](https://reader035.fdocuments.in/reader035/viewer/2022062505/5edc7621ad6a402d66672064/html5/thumbnails/38.jpg)
Expression Tree Examples
7− a
5(a + b)3
![Page 39: Discrete Mathematics - Treesnlp.jbnu.ac.kr/DM/slides/ch11_trees.pdfDiscrete Mathematics Trees H. Turgut Uyar Ay¸seg¨ul Gencata Yayımlı Emre Harmancı 2001-2016](https://reader035.fdocuments.in/reader035/viewer/2022062505/5edc7621ad6a402d66672064/html5/thumbnails/39.jpg)
Expression Tree Examples
7− a
5· (a + b)3
![Page 40: Discrete Mathematics - Treesnlp.jbnu.ac.kr/DM/slides/ch11_trees.pdfDiscrete Mathematics Trees H. Turgut Uyar Ay¸seg¨ul Gencata Yayımlı Emre Harmancı 2001-2016](https://reader035.fdocuments.in/reader035/viewer/2022062505/5edc7621ad6a402d66672064/html5/thumbnails/40.jpg)
Expression Tree Examples
t +u ∗ v
w + x − y z
![Page 41: Discrete Mathematics - Treesnlp.jbnu.ac.kr/DM/slides/ch11_trees.pdfDiscrete Mathematics Trees H. Turgut Uyar Ay¸seg¨ul Gencata Yayımlı Emre Harmancı 2001-2016](https://reader035.fdocuments.in/reader035/viewer/2022062505/5edc7621ad6a402d66672064/html5/thumbnails/41.jpg)
Expression Tree Traversals
1 inorder traversal:traverse left subtree, visit root, traverse right subtree
2 preorder traversal:visit root, traverse left subtree, traverse right subtree
3 postorder traversal (reverse Polish notation):traverse left subtree, traverse right subtree, visit root
![Page 42: Discrete Mathematics - Treesnlp.jbnu.ac.kr/DM/slides/ch11_trees.pdfDiscrete Mathematics Trees H. Turgut Uyar Ay¸seg¨ul Gencata Yayımlı Emre Harmancı 2001-2016](https://reader035.fdocuments.in/reader035/viewer/2022062505/5edc7621ad6a402d66672064/html5/thumbnails/42.jpg)
Expression Tree Traversals
1 inorder traversal:traverse left subtree, visit root, traverse right subtree
2 preorder traversal:visit root, traverse left subtree, traverse right subtree
3 postorder traversal (reverse Polish notation):traverse left subtree, traverse right subtree, visit root
![Page 43: Discrete Mathematics - Treesnlp.jbnu.ac.kr/DM/slides/ch11_trees.pdfDiscrete Mathematics Trees H. Turgut Uyar Ay¸seg¨ul Gencata Yayımlı Emre Harmancı 2001-2016](https://reader035.fdocuments.in/reader035/viewer/2022062505/5edc7621ad6a402d66672064/html5/thumbnails/43.jpg)
Expression Tree Traversals
1 inorder traversal:traverse left subtree, visit root, traverse right subtree
2 preorder traversal:visit root, traverse left subtree, traverse right subtree
3 postorder traversal (reverse Polish notation):traverse left subtree, traverse right subtree, visit root
![Page 44: Discrete Mathematics - Treesnlp.jbnu.ac.kr/DM/slides/ch11_trees.pdfDiscrete Mathematics Trees H. Turgut Uyar Ay¸seg¨ul Gencata Yayımlı Emre Harmancı 2001-2016](https://reader035.fdocuments.in/reader035/viewer/2022062505/5edc7621ad6a402d66672064/html5/thumbnails/44.jpg)
Inorder Traversal Example
t + u ∗ v / w + x − y ↑ z
![Page 45: Discrete Mathematics - Treesnlp.jbnu.ac.kr/DM/slides/ch11_trees.pdfDiscrete Mathematics Trees H. Turgut Uyar Ay¸seg¨ul Gencata Yayımlı Emre Harmancı 2001-2016](https://reader035.fdocuments.in/reader035/viewer/2022062505/5edc7621ad6a402d66672064/html5/thumbnails/45.jpg)
Preorder Traversal Example
+ t / ∗ u v + w − x ↑ y z
![Page 46: Discrete Mathematics - Treesnlp.jbnu.ac.kr/DM/slides/ch11_trees.pdfDiscrete Mathematics Trees H. Turgut Uyar Ay¸seg¨ul Gencata Yayımlı Emre Harmancı 2001-2016](https://reader035.fdocuments.in/reader035/viewer/2022062505/5edc7621ad6a402d66672064/html5/thumbnails/46.jpg)
Postorder Traversal Example
t u v ∗ w x y z ↑ − + / +
![Page 47: Discrete Mathematics - Treesnlp.jbnu.ac.kr/DM/slides/ch11_trees.pdfDiscrete Mathematics Trees H. Turgut Uyar Ay¸seg¨ul Gencata Yayımlı Emre Harmancı 2001-2016](https://reader035.fdocuments.in/reader035/viewer/2022062505/5edc7621ad6a402d66672064/html5/thumbnails/47.jpg)
Expression Tree Evaluation
inorder traversal requires parantheses for precedence
preorder and postorder traversals do not require parantheses
![Page 48: Discrete Mathematics - Treesnlp.jbnu.ac.kr/DM/slides/ch11_trees.pdfDiscrete Mathematics Trees H. Turgut Uyar Ay¸seg¨ul Gencata Yayımlı Emre Harmancı 2001-2016](https://reader035.fdocuments.in/reader035/viewer/2022062505/5edc7621ad6a402d66672064/html5/thumbnails/48.jpg)
Postorder Evaluation Example
t u v ∗ w x y z ↑ − + / +4 2 3 ∗ 1 9 2 3 ↑ − + / +
4 2 3 ∗4 6 1 9 2 3 ↑4 6 1 9 8 −4 6 1 1 +4 6 2 /4 3 +7
![Page 49: Discrete Mathematics - Treesnlp.jbnu.ac.kr/DM/slides/ch11_trees.pdfDiscrete Mathematics Trees H. Turgut Uyar Ay¸seg¨ul Gencata Yayımlı Emre Harmancı 2001-2016](https://reader035.fdocuments.in/reader035/viewer/2022062505/5edc7621ad6a402d66672064/html5/thumbnails/49.jpg)
Postorder Evaluation Example
t u v ∗ w x y z ↑ − + / +4 2 3 ∗ 1 9 2 3 ↑ − + / +
4 2 3 ∗4 6 1 9 2 3 ↑4 6 1 9 8 −4 6 1 1 +4 6 2 /4 3 +7
![Page 50: Discrete Mathematics - Treesnlp.jbnu.ac.kr/DM/slides/ch11_trees.pdfDiscrete Mathematics Trees H. Turgut Uyar Ay¸seg¨ul Gencata Yayımlı Emre Harmancı 2001-2016](https://reader035.fdocuments.in/reader035/viewer/2022062505/5edc7621ad6a402d66672064/html5/thumbnails/50.jpg)
Postorder Evaluation Example
t u v ∗ w x y z ↑ − + / +4 2 3 ∗ 1 9 2 3 ↑ − + / +
4 2 3 ∗4 6 1 9 2 3 ↑4 6 1 9 8 −4 6 1 1 +4 6 2 /4 3 +7
![Page 51: Discrete Mathematics - Treesnlp.jbnu.ac.kr/DM/slides/ch11_trees.pdfDiscrete Mathematics Trees H. Turgut Uyar Ay¸seg¨ul Gencata Yayımlı Emre Harmancı 2001-2016](https://reader035.fdocuments.in/reader035/viewer/2022062505/5edc7621ad6a402d66672064/html5/thumbnails/51.jpg)
Postorder Evaluation Example
t u v ∗ w x y z ↑ − + / +4 2 3 ∗ 1 9 2 3 ↑ − + / +
4 2 3 ∗4 6 1 9 2 3 ↑4 6 1 9 8 −4 6 1 1 +4 6 2 /4 3 +7
![Page 52: Discrete Mathematics - Treesnlp.jbnu.ac.kr/DM/slides/ch11_trees.pdfDiscrete Mathematics Trees H. Turgut Uyar Ay¸seg¨ul Gencata Yayımlı Emre Harmancı 2001-2016](https://reader035.fdocuments.in/reader035/viewer/2022062505/5edc7621ad6a402d66672064/html5/thumbnails/52.jpg)
Postorder Evaluation Example
t u v ∗ w x y z ↑ − + / +4 2 3 ∗ 1 9 2 3 ↑ − + / +
4 2 3 ∗4 6 1 9 2 3 ↑4 6 1 9 8 −4 6 1 1 +4 6 2 /4 3 +7
![Page 53: Discrete Mathematics - Treesnlp.jbnu.ac.kr/DM/slides/ch11_trees.pdfDiscrete Mathematics Trees H. Turgut Uyar Ay¸seg¨ul Gencata Yayımlı Emre Harmancı 2001-2016](https://reader035.fdocuments.in/reader035/viewer/2022062505/5edc7621ad6a402d66672064/html5/thumbnails/53.jpg)
Postorder Evaluation Example
t u v ∗ w x y z ↑ − + / +4 2 3 ∗ 1 9 2 3 ↑ − + / +
4 2 3 ∗4 6 1 9 2 3 ↑4 6 1 9 8 −4 6 1 1 +4 6 2 /4 3 +7
![Page 54: Discrete Mathematics - Treesnlp.jbnu.ac.kr/DM/slides/ch11_trees.pdfDiscrete Mathematics Trees H. Turgut Uyar Ay¸seg¨ul Gencata Yayımlı Emre Harmancı 2001-2016](https://reader035.fdocuments.in/reader035/viewer/2022062505/5edc7621ad6a402d66672064/html5/thumbnails/54.jpg)
Postorder Evaluation Example
t u v ∗ w x y z ↑ − + / +4 2 3 ∗ 1 9 2 3 ↑ − + / +
4 2 3 ∗4 6 1 9 2 3 ↑4 6 1 9 8 −4 6 1 1 +4 6 2 /4 3 +7
![Page 55: Discrete Mathematics - Treesnlp.jbnu.ac.kr/DM/slides/ch11_trees.pdfDiscrete Mathematics Trees H. Turgut Uyar Ay¸seg¨ul Gencata Yayımlı Emre Harmancı 2001-2016](https://reader035.fdocuments.in/reader035/viewer/2022062505/5edc7621ad6a402d66672064/html5/thumbnails/55.jpg)
Postorder Evaluation Example
t u v ∗ w x y z ↑ − + / +4 2 3 ∗ 1 9 2 3 ↑ − + / +
4 2 3 ∗4 6 1 9 2 3 ↑4 6 1 9 8 −4 6 1 1 +4 6 2 /4 3 +7
![Page 56: Discrete Mathematics - Treesnlp.jbnu.ac.kr/DM/slides/ch11_trees.pdfDiscrete Mathematics Trees H. Turgut Uyar Ay¸seg¨ul Gencata Yayımlı Emre Harmancı 2001-2016](https://reader035.fdocuments.in/reader035/viewer/2022062505/5edc7621ad6a402d66672064/html5/thumbnails/56.jpg)
Postorder Evaluation Example
t u v ∗ w x y z ↑ − + / +4 2 3 ∗ 1 9 2 3 ↑ − + / +
4 2 3 ∗4 6 1 9 2 3 ↑4 6 1 9 8 −4 6 1 1 +4 6 2 /4 3 +7
![Page 57: Discrete Mathematics - Treesnlp.jbnu.ac.kr/DM/slides/ch11_trees.pdfDiscrete Mathematics Trees H. Turgut Uyar Ay¸seg¨ul Gencata Yayımlı Emre Harmancı 2001-2016](https://reader035.fdocuments.in/reader035/viewer/2022062505/5edc7621ad6a402d66672064/html5/thumbnails/57.jpg)
Postorder Evaluation Example
t u v ∗ w x y z ↑ − + / +4 2 3 ∗ 1 9 2 3 ↑ − + / +
4 2 3 ∗4 6 1 9 2 3 ↑4 6 1 9 8 −4 6 1 1 +4 6 2 /4 3 +7
![Page 58: Discrete Mathematics - Treesnlp.jbnu.ac.kr/DM/slides/ch11_trees.pdfDiscrete Mathematics Trees H. Turgut Uyar Ay¸seg¨ul Gencata Yayımlı Emre Harmancı 2001-2016](https://reader035.fdocuments.in/reader035/viewer/2022062505/5edc7621ad6a402d66672064/html5/thumbnails/58.jpg)
Postorder Evaluation Example
t u v ∗ w x y z ↑ − + / +4 2 3 ∗ 1 9 2 3 ↑ − + / +
4 2 3 ∗4 6 1 9 2 3 ↑4 6 1 9 8 −4 6 1 1 +4 6 2 /4 3 +7
![Page 59: Discrete Mathematics - Treesnlp.jbnu.ac.kr/DM/slides/ch11_trees.pdfDiscrete Mathematics Trees H. Turgut Uyar Ay¸seg¨ul Gencata Yayımlı Emre Harmancı 2001-2016](https://reader035.fdocuments.in/reader035/viewer/2022062505/5edc7621ad6a402d66672064/html5/thumbnails/59.jpg)
Postorder Evaluation Example
t u v ∗ w x y z ↑ − + / +4 2 3 ∗ 1 9 2 3 ↑ − + / +
4 2 3 ∗4 6 1 9 2 3 ↑4 6 1 9 8 −4 6 1 1 +4 6 2 /4 3 +7
![Page 60: Discrete Mathematics - Treesnlp.jbnu.ac.kr/DM/slides/ch11_trees.pdfDiscrete Mathematics Trees H. Turgut Uyar Ay¸seg¨ul Gencata Yayımlı Emre Harmancı 2001-2016](https://reader035.fdocuments.in/reader035/viewer/2022062505/5edc7621ad6a402d66672064/html5/thumbnails/60.jpg)
Postorder Evaluation Example
t u v ∗ w x y z ↑ − + / +4 2 3 ∗ 1 9 2 3 ↑ − + / +
4 2 3 ∗4 6 1 9 2 3 ↑4 6 1 9 8 −4 6 1 1 +4 6 2 /4 3 +7
![Page 61: Discrete Mathematics - Treesnlp.jbnu.ac.kr/DM/slides/ch11_trees.pdfDiscrete Mathematics Trees H. Turgut Uyar Ay¸seg¨ul Gencata Yayımlı Emre Harmancı 2001-2016](https://reader035.fdocuments.in/reader035/viewer/2022062505/5edc7621ad6a402d66672064/html5/thumbnails/61.jpg)
Postorder Evaluation Example
t u v ∗ w x y z ↑ − + / +4 2 3 ∗ 1 9 2 3 ↑ − + / +
4 2 3 ∗4 6 1 9 2 3 ↑4 6 1 9 8 −4 6 1 1 +4 6 2 /4 3 +7
![Page 62: Discrete Mathematics - Treesnlp.jbnu.ac.kr/DM/slides/ch11_trees.pdfDiscrete Mathematics Trees H. Turgut Uyar Ay¸seg¨ul Gencata Yayımlı Emre Harmancı 2001-2016](https://reader035.fdocuments.in/reader035/viewer/2022062505/5edc7621ad6a402d66672064/html5/thumbnails/62.jpg)
Regular Trees
T = (V ,E ) is an m-ary tree:∀v ∈ V [dv
o ≤ m]
T = (V ,E ) is a complete m-ary tree:∀v ∈ V [dv
o ∈ {0,m}]
![Page 63: Discrete Mathematics - Treesnlp.jbnu.ac.kr/DM/slides/ch11_trees.pdfDiscrete Mathematics Trees H. Turgut Uyar Ay¸seg¨ul Gencata Yayımlı Emre Harmancı 2001-2016](https://reader035.fdocuments.in/reader035/viewer/2022062505/5edc7621ad6a402d66672064/html5/thumbnails/63.jpg)
Regular Tree Theorem
Theorem
T = (V ,E ): complete m-ary tree
n: number of nodes
l : number of leaves
i : number of internal nodes
n = m · i + 1
l = n − i = m · i + 1− i = (m − 1) · i + 1
i =l − 1
m − 1
![Page 64: Discrete Mathematics - Treesnlp.jbnu.ac.kr/DM/slides/ch11_trees.pdfDiscrete Mathematics Trees H. Turgut Uyar Ay¸seg¨ul Gencata Yayımlı Emre Harmancı 2001-2016](https://reader035.fdocuments.in/reader035/viewer/2022062505/5edc7621ad6a402d66672064/html5/thumbnails/64.jpg)
Regular Tree Theorem
Theorem
T = (V ,E ): complete m-ary tree
n: number of nodes
l : number of leaves
i : number of internal nodes
n = m · i + 1
l = n − i = m · i + 1− i = (m − 1) · i + 1
i =l − 1
m − 1
![Page 65: Discrete Mathematics - Treesnlp.jbnu.ac.kr/DM/slides/ch11_trees.pdfDiscrete Mathematics Trees H. Turgut Uyar Ay¸seg¨ul Gencata Yayımlı Emre Harmancı 2001-2016](https://reader035.fdocuments.in/reader035/viewer/2022062505/5edc7621ad6a402d66672064/html5/thumbnails/65.jpg)
Regular Tree Theorem
Theorem
T = (V ,E ): complete m-ary tree
n: number of nodes
l : number of leaves
i : number of internal nodes
n = m · i + 1
l = n − i = m · i + 1− i = (m − 1) · i + 1
i =l − 1
m − 1
![Page 66: Discrete Mathematics - Treesnlp.jbnu.ac.kr/DM/slides/ch11_trees.pdfDiscrete Mathematics Trees H. Turgut Uyar Ay¸seg¨ul Gencata Yayımlı Emre Harmancı 2001-2016](https://reader035.fdocuments.in/reader035/viewer/2022062505/5edc7621ad6a402d66672064/html5/thumbnails/66.jpg)
Regular Tree Theorem
Theorem
T = (V ,E ): complete m-ary tree
n: number of nodes
l : number of leaves
i : number of internal nodes
n = m · i + 1
l = n − i = m · i + 1− i = (m − 1) · i + 1
i =l − 1
m − 1
![Page 67: Discrete Mathematics - Treesnlp.jbnu.ac.kr/DM/slides/ch11_trees.pdfDiscrete Mathematics Trees H. Turgut Uyar Ay¸seg¨ul Gencata Yayımlı Emre Harmancı 2001-2016](https://reader035.fdocuments.in/reader035/viewer/2022062505/5edc7621ad6a402d66672064/html5/thumbnails/67.jpg)
Regular Tree Theorem
Theorem
T = (V ,E ): complete m-ary tree
n: number of nodes
l : number of leaves
i : number of internal nodes
n = m · i + 1
l = n − i = m · i + 1− i = (m − 1) · i + 1
i =l − 1
m − 1
![Page 68: Discrete Mathematics - Treesnlp.jbnu.ac.kr/DM/slides/ch11_trees.pdfDiscrete Mathematics Trees H. Turgut Uyar Ay¸seg¨ul Gencata Yayımlı Emre Harmancı 2001-2016](https://reader035.fdocuments.in/reader035/viewer/2022062505/5edc7621ad6a402d66672064/html5/thumbnails/68.jpg)
Regular Tree Theorem
Theorem
T = (V ,E ): complete m-ary tree
n: number of nodes
l : number of leaves
i : number of internal nodes
n = m · i + 1
l = n − i = m · i + 1− i = (m − 1) · i + 1
i =l − 1
m − 1
![Page 69: Discrete Mathematics - Treesnlp.jbnu.ac.kr/DM/slides/ch11_trees.pdfDiscrete Mathematics Trees H. Turgut Uyar Ay¸seg¨ul Gencata Yayımlı Emre Harmancı 2001-2016](https://reader035.fdocuments.in/reader035/viewer/2022062505/5edc7621ad6a402d66672064/html5/thumbnails/69.jpg)
Regular Tree Examples
how many matches are played in a tennis tournamentwith 27 players?
every player is a leaf: l = 27
every match is an internal node: m = 2
number of matches: i = l−1m−1 = 27−1
2−1 = 26
![Page 70: Discrete Mathematics - Treesnlp.jbnu.ac.kr/DM/slides/ch11_trees.pdfDiscrete Mathematics Trees H. Turgut Uyar Ay¸seg¨ul Gencata Yayımlı Emre Harmancı 2001-2016](https://reader035.fdocuments.in/reader035/viewer/2022062505/5edc7621ad6a402d66672064/html5/thumbnails/70.jpg)
Regular Tree Examples
how many matches are played in a tennis tournamentwith 27 players?
every player is a leaf: l = 27
every match is an internal node: m = 2
number of matches: i = l−1m−1 = 27−1
2−1 = 26
![Page 71: Discrete Mathematics - Treesnlp.jbnu.ac.kr/DM/slides/ch11_trees.pdfDiscrete Mathematics Trees H. Turgut Uyar Ay¸seg¨ul Gencata Yayımlı Emre Harmancı 2001-2016](https://reader035.fdocuments.in/reader035/viewer/2022062505/5edc7621ad6a402d66672064/html5/thumbnails/71.jpg)
Regular Tree Examples
how many extension cords with 4 outlets are requiredto connect 25 computers to a wall socket?
every computer is a leaf: l = 25
every extension cord is an internal node: m = 4
number of cords: i = l−1m−1 = 25−1
4−1 = 8
![Page 72: Discrete Mathematics - Treesnlp.jbnu.ac.kr/DM/slides/ch11_trees.pdfDiscrete Mathematics Trees H. Turgut Uyar Ay¸seg¨ul Gencata Yayımlı Emre Harmancı 2001-2016](https://reader035.fdocuments.in/reader035/viewer/2022062505/5edc7621ad6a402d66672064/html5/thumbnails/72.jpg)
Regular Tree Examples
how many extension cords with 4 outlets are requiredto connect 25 computers to a wall socket?
every computer is a leaf: l = 25
every extension cord is an internal node: m = 4
number of cords: i = l−1m−1 = 25−1
4−1 = 8
![Page 73: Discrete Mathematics - Treesnlp.jbnu.ac.kr/DM/slides/ch11_trees.pdfDiscrete Mathematics Trees H. Turgut Uyar Ay¸seg¨ul Gencata Yayımlı Emre Harmancı 2001-2016](https://reader035.fdocuments.in/reader035/viewer/2022062505/5edc7621ad6a402d66672064/html5/thumbnails/73.jpg)
Topics
1 TreesIntroductionRooted TreesBinary TreesDecision Trees
2 Tree ProblemsMinimum Spanning Tree
![Page 74: Discrete Mathematics - Treesnlp.jbnu.ac.kr/DM/slides/ch11_trees.pdfDiscrete Mathematics Trees H. Turgut Uyar Ay¸seg¨ul Gencata Yayımlı Emre Harmancı 2001-2016](https://reader035.fdocuments.in/reader035/viewer/2022062505/5edc7621ad6a402d66672064/html5/thumbnails/74.jpg)
Decision Trees
one of 8 coins is counterfeit (heavier)
find counterfeit coin using a beam balance
depth of tree: number of weighings
![Page 75: Discrete Mathematics - Treesnlp.jbnu.ac.kr/DM/slides/ch11_trees.pdfDiscrete Mathematics Trees H. Turgut Uyar Ay¸seg¨ul Gencata Yayımlı Emre Harmancı 2001-2016](https://reader035.fdocuments.in/reader035/viewer/2022062505/5edc7621ad6a402d66672064/html5/thumbnails/75.jpg)
Decision Trees
![Page 76: Discrete Mathematics - Treesnlp.jbnu.ac.kr/DM/slides/ch11_trees.pdfDiscrete Mathematics Trees H. Turgut Uyar Ay¸seg¨ul Gencata Yayımlı Emre Harmancı 2001-2016](https://reader035.fdocuments.in/reader035/viewer/2022062505/5edc7621ad6a402d66672064/html5/thumbnails/76.jpg)
Decision Trees
![Page 77: Discrete Mathematics - Treesnlp.jbnu.ac.kr/DM/slides/ch11_trees.pdfDiscrete Mathematics Trees H. Turgut Uyar Ay¸seg¨ul Gencata Yayımlı Emre Harmancı 2001-2016](https://reader035.fdocuments.in/reader035/viewer/2022062505/5edc7621ad6a402d66672064/html5/thumbnails/77.jpg)
Topics
1 TreesIntroductionRooted TreesBinary TreesDecision Trees
2 Tree ProblemsMinimum Spanning Tree
![Page 78: Discrete Mathematics - Treesnlp.jbnu.ac.kr/DM/slides/ch11_trees.pdfDiscrete Mathematics Trees H. Turgut Uyar Ay¸seg¨ul Gencata Yayımlı Emre Harmancı 2001-2016](https://reader035.fdocuments.in/reader035/viewer/2022062505/5edc7621ad6a402d66672064/html5/thumbnails/78.jpg)
Spanning Tree
T = (V ′,E ′) is a spanning tree of G (V ,E ):T is a subgraph of GT is a treeV ′ = V
minimum spanning tree:total weight of edges in E ′ is minimal
![Page 79: Discrete Mathematics - Treesnlp.jbnu.ac.kr/DM/slides/ch11_trees.pdfDiscrete Mathematics Trees H. Turgut Uyar Ay¸seg¨ul Gencata Yayımlı Emre Harmancı 2001-2016](https://reader035.fdocuments.in/reader035/viewer/2022062505/5edc7621ad6a402d66672064/html5/thumbnails/79.jpg)
Kruskal’s Algorithm
1 G ′ = (V ′,E ′),V ′ = ∅,E ′ = ∅2 select e = (v1, v2) ∈ E − E ′ such that:
E ′ ∪ {e} contains no cycle, and wt(e) is minimal
3 E ′ = E ∪ {e},V ′ = V ′ ∪ {v1, v2}4 if |E ′| = |V | − 1: result is G ′
5 go to step 2
![Page 80: Discrete Mathematics - Treesnlp.jbnu.ac.kr/DM/slides/ch11_trees.pdfDiscrete Mathematics Trees H. Turgut Uyar Ay¸seg¨ul Gencata Yayımlı Emre Harmancı 2001-2016](https://reader035.fdocuments.in/reader035/viewer/2022062505/5edc7621ad6a402d66672064/html5/thumbnails/80.jpg)
Kruskal’s Algorithm Example
minimum weight: 1(e, g)
E ′ = {(e, g)}|E ′| = 1
![Page 81: Discrete Mathematics - Treesnlp.jbnu.ac.kr/DM/slides/ch11_trees.pdfDiscrete Mathematics Trees H. Turgut Uyar Ay¸seg¨ul Gencata Yayımlı Emre Harmancı 2001-2016](https://reader035.fdocuments.in/reader035/viewer/2022062505/5edc7621ad6a402d66672064/html5/thumbnails/81.jpg)
Kruskal’s Algorithm Example
minimum weight: 1(e, g)
E ′ = {(e, g)}|E ′| = 1
![Page 82: Discrete Mathematics - Treesnlp.jbnu.ac.kr/DM/slides/ch11_trees.pdfDiscrete Mathematics Trees H. Turgut Uyar Ay¸seg¨ul Gencata Yayımlı Emre Harmancı 2001-2016](https://reader035.fdocuments.in/reader035/viewer/2022062505/5edc7621ad6a402d66672064/html5/thumbnails/82.jpg)
Kruskal’s Algorithm Example
minimum weight: 1(e, g)
E ′ = {(e, g)}|E ′| = 1
![Page 83: Discrete Mathematics - Treesnlp.jbnu.ac.kr/DM/slides/ch11_trees.pdfDiscrete Mathematics Trees H. Turgut Uyar Ay¸seg¨ul Gencata Yayımlı Emre Harmancı 2001-2016](https://reader035.fdocuments.in/reader035/viewer/2022062505/5edc7621ad6a402d66672064/html5/thumbnails/83.jpg)
Kruskal’s Algorithm Example
minimum weight: 2(d , e), (d , f ), (f , g)
E ′ = {(e, g), (d , f )}|E ′| = 2
![Page 84: Discrete Mathematics - Treesnlp.jbnu.ac.kr/DM/slides/ch11_trees.pdfDiscrete Mathematics Trees H. Turgut Uyar Ay¸seg¨ul Gencata Yayımlı Emre Harmancı 2001-2016](https://reader035.fdocuments.in/reader035/viewer/2022062505/5edc7621ad6a402d66672064/html5/thumbnails/84.jpg)
Kruskal’s Algorithm Example
minimum weight: 2(d , e), (d , f ), (f , g)
E ′ = {(e, g), (d , f )}|E ′| = 2
![Page 85: Discrete Mathematics - Treesnlp.jbnu.ac.kr/DM/slides/ch11_trees.pdfDiscrete Mathematics Trees H. Turgut Uyar Ay¸seg¨ul Gencata Yayımlı Emre Harmancı 2001-2016](https://reader035.fdocuments.in/reader035/viewer/2022062505/5edc7621ad6a402d66672064/html5/thumbnails/85.jpg)
Kruskal’s Algorithm Example
minimum weight: 2(d , e), (d , f ), (f , g)
E ′ = {(e, g), (d , f )}|E ′| = 2
![Page 86: Discrete Mathematics - Treesnlp.jbnu.ac.kr/DM/slides/ch11_trees.pdfDiscrete Mathematics Trees H. Turgut Uyar Ay¸seg¨ul Gencata Yayımlı Emre Harmancı 2001-2016](https://reader035.fdocuments.in/reader035/viewer/2022062505/5edc7621ad6a402d66672064/html5/thumbnails/86.jpg)
Kruskal’s Algorithm Example
minimum weight: 2(d , e), (f , g)
E ′ = {(e, g), (d , f ), (d , e)}|E ′| = 3
![Page 87: Discrete Mathematics - Treesnlp.jbnu.ac.kr/DM/slides/ch11_trees.pdfDiscrete Mathematics Trees H. Turgut Uyar Ay¸seg¨ul Gencata Yayımlı Emre Harmancı 2001-2016](https://reader035.fdocuments.in/reader035/viewer/2022062505/5edc7621ad6a402d66672064/html5/thumbnails/87.jpg)
Kruskal’s Algorithm Example
minimum weight: 2(d , e), (f , g)
E ′ = {(e, g), (d , f ), (d , e)}|E ′| = 3
![Page 88: Discrete Mathematics - Treesnlp.jbnu.ac.kr/DM/slides/ch11_trees.pdfDiscrete Mathematics Trees H. Turgut Uyar Ay¸seg¨ul Gencata Yayımlı Emre Harmancı 2001-2016](https://reader035.fdocuments.in/reader035/viewer/2022062505/5edc7621ad6a402d66672064/html5/thumbnails/88.jpg)
Kruskal’s Algorithm Example
minimum weight: 2(d , e), (f , g)
E ′ = {(e, g), (d , f ), (d , e)}|E ′| = 3
![Page 89: Discrete Mathematics - Treesnlp.jbnu.ac.kr/DM/slides/ch11_trees.pdfDiscrete Mathematics Trees H. Turgut Uyar Ay¸seg¨ul Gencata Yayımlı Emre Harmancı 2001-2016](https://reader035.fdocuments.in/reader035/viewer/2022062505/5edc7621ad6a402d66672064/html5/thumbnails/89.jpg)
Kruskal’s Algorithm Example
minimum weight: 2(f , g) forms a cycle
minimum weight: 3(c, e), (c, g), (d , g)(d , g) forms a cycle
E ′ = {(e, g), (d , f ), (d , e), (c, e)}|E ′| = 4
![Page 90: Discrete Mathematics - Treesnlp.jbnu.ac.kr/DM/slides/ch11_trees.pdfDiscrete Mathematics Trees H. Turgut Uyar Ay¸seg¨ul Gencata Yayımlı Emre Harmancı 2001-2016](https://reader035.fdocuments.in/reader035/viewer/2022062505/5edc7621ad6a402d66672064/html5/thumbnails/90.jpg)
Kruskal’s Algorithm Example
minimum weight: 2(f , g) forms a cycle
minimum weight: 3(c, e), (c, g), (d , g)(d , g) forms a cycle
E ′ = {(e, g), (d , f ), (d , e), (c, e)}|E ′| = 4
![Page 91: Discrete Mathematics - Treesnlp.jbnu.ac.kr/DM/slides/ch11_trees.pdfDiscrete Mathematics Trees H. Turgut Uyar Ay¸seg¨ul Gencata Yayımlı Emre Harmancı 2001-2016](https://reader035.fdocuments.in/reader035/viewer/2022062505/5edc7621ad6a402d66672064/html5/thumbnails/91.jpg)
Kruskal’s Algorithm Example
minimum weight: 2(f , g) forms a cycle
minimum weight: 3(c, e), (c, g), (d , g)(d , g) forms a cycle
E ′ = {(e, g), (d , f ), (d , e), (c, e)}|E ′| = 4
![Page 92: Discrete Mathematics - Treesnlp.jbnu.ac.kr/DM/slides/ch11_trees.pdfDiscrete Mathematics Trees H. Turgut Uyar Ay¸seg¨ul Gencata Yayımlı Emre Harmancı 2001-2016](https://reader035.fdocuments.in/reader035/viewer/2022062505/5edc7621ad6a402d66672064/html5/thumbnails/92.jpg)
Kruskal’s Algorithm Example
minimum weight: 2(f , g) forms a cycle
minimum weight: 3(c, e), (c, g), (d , g)(d , g) forms a cycle
E ′ = {(e, g), (d , f ), (d , e), (c, e)}|E ′| = 4
![Page 93: Discrete Mathematics - Treesnlp.jbnu.ac.kr/DM/slides/ch11_trees.pdfDiscrete Mathematics Trees H. Turgut Uyar Ay¸seg¨ul Gencata Yayımlı Emre Harmancı 2001-2016](https://reader035.fdocuments.in/reader035/viewer/2022062505/5edc7621ad6a402d66672064/html5/thumbnails/93.jpg)
Kruskal’s Algorithm Example
E ′ = {(e, g), (d , f ), (d , e),(c, e), (b, e)
}|E ′| = 5
![Page 94: Discrete Mathematics - Treesnlp.jbnu.ac.kr/DM/slides/ch11_trees.pdfDiscrete Mathematics Trees H. Turgut Uyar Ay¸seg¨ul Gencata Yayımlı Emre Harmancı 2001-2016](https://reader035.fdocuments.in/reader035/viewer/2022062505/5edc7621ad6a402d66672064/html5/thumbnails/94.jpg)
Kruskal’s Algorithm Example
E ′ = {(e, g), (d , f ), (d , e),(c, e), (b, e)
}|E ′| = 5
![Page 95: Discrete Mathematics - Treesnlp.jbnu.ac.kr/DM/slides/ch11_trees.pdfDiscrete Mathematics Trees H. Turgut Uyar Ay¸seg¨ul Gencata Yayımlı Emre Harmancı 2001-2016](https://reader035.fdocuments.in/reader035/viewer/2022062505/5edc7621ad6a402d66672064/html5/thumbnails/95.jpg)
Kruskal’s Algorithm Example
E ′ = {(e, g), (d , f ), (d , e),(c, e), (b, e), (a, b)
}|E ′| = 6
![Page 96: Discrete Mathematics - Treesnlp.jbnu.ac.kr/DM/slides/ch11_trees.pdfDiscrete Mathematics Trees H. Turgut Uyar Ay¸seg¨ul Gencata Yayımlı Emre Harmancı 2001-2016](https://reader035.fdocuments.in/reader035/viewer/2022062505/5edc7621ad6a402d66672064/html5/thumbnails/96.jpg)
Kruskal’s Algorithm Example
E ′ = {(e, g), (d , f ), (d , e),(c, e), (b, e), (a, b)
}|E ′| = 6
![Page 97: Discrete Mathematics - Treesnlp.jbnu.ac.kr/DM/slides/ch11_trees.pdfDiscrete Mathematics Trees H. Turgut Uyar Ay¸seg¨ul Gencata Yayımlı Emre Harmancı 2001-2016](https://reader035.fdocuments.in/reader035/viewer/2022062505/5edc7621ad6a402d66672064/html5/thumbnails/97.jpg)
Kruskal’s Algorithm Example
total weight: 17
![Page 98: Discrete Mathematics - Treesnlp.jbnu.ac.kr/DM/slides/ch11_trees.pdfDiscrete Mathematics Trees H. Turgut Uyar Ay¸seg¨ul Gencata Yayımlı Emre Harmancı 2001-2016](https://reader035.fdocuments.in/reader035/viewer/2022062505/5edc7621ad6a402d66672064/html5/thumbnails/98.jpg)
Prim’s Algorithm
1 T ′ = (V ′,E ′),E ′ = ∅, v0 ∈ V ,V ′ = {v0}2 select v ∈ V − V ′ such that for a node x ∈ V ′
e = (x , v),E ′ ∪ {e} contains no cycle, and wt(e) is minimal
3 E ′ = E ∪ {e},V ′ = V ′ ∪ {x}4 if |V ′| = |V |: result is T ′
5 go to step 2
![Page 99: Discrete Mathematics - Treesnlp.jbnu.ac.kr/DM/slides/ch11_trees.pdfDiscrete Mathematics Trees H. Turgut Uyar Ay¸seg¨ul Gencata Yayımlı Emre Harmancı 2001-2016](https://reader035.fdocuments.in/reader035/viewer/2022062505/5edc7621ad6a402d66672064/html5/thumbnails/99.jpg)
Prim’s Algorithm Example
E ′ = ∅V ′ = {a}|V ′| = 1
![Page 100: Discrete Mathematics - Treesnlp.jbnu.ac.kr/DM/slides/ch11_trees.pdfDiscrete Mathematics Trees H. Turgut Uyar Ay¸seg¨ul Gencata Yayımlı Emre Harmancı 2001-2016](https://reader035.fdocuments.in/reader035/viewer/2022062505/5edc7621ad6a402d66672064/html5/thumbnails/100.jpg)
Prim’s Algorithm Example
E ′ = ∅V ′ = {a}|V ′| = 1
![Page 101: Discrete Mathematics - Treesnlp.jbnu.ac.kr/DM/slides/ch11_trees.pdfDiscrete Mathematics Trees H. Turgut Uyar Ay¸seg¨ul Gencata Yayımlı Emre Harmancı 2001-2016](https://reader035.fdocuments.in/reader035/viewer/2022062505/5edc7621ad6a402d66672064/html5/thumbnails/101.jpg)
Prim’s Algorithm Example
E ′ = {(a, b)}V ′ = {a, b}|V ′| = 2
![Page 102: Discrete Mathematics - Treesnlp.jbnu.ac.kr/DM/slides/ch11_trees.pdfDiscrete Mathematics Trees H. Turgut Uyar Ay¸seg¨ul Gencata Yayımlı Emre Harmancı 2001-2016](https://reader035.fdocuments.in/reader035/viewer/2022062505/5edc7621ad6a402d66672064/html5/thumbnails/102.jpg)
Prim’s Algorithm Example
E ′ = {(a, b)}V ′ = {a, b}|V ′| = 2
![Page 103: Discrete Mathematics - Treesnlp.jbnu.ac.kr/DM/slides/ch11_trees.pdfDiscrete Mathematics Trees H. Turgut Uyar Ay¸seg¨ul Gencata Yayımlı Emre Harmancı 2001-2016](https://reader035.fdocuments.in/reader035/viewer/2022062505/5edc7621ad6a402d66672064/html5/thumbnails/103.jpg)
Prim’s Algorithm Example
E ′ = {(a, b), (b, e)}V ′ = {a, b, e}|V ′| = 3
![Page 104: Discrete Mathematics - Treesnlp.jbnu.ac.kr/DM/slides/ch11_trees.pdfDiscrete Mathematics Trees H. Turgut Uyar Ay¸seg¨ul Gencata Yayımlı Emre Harmancı 2001-2016](https://reader035.fdocuments.in/reader035/viewer/2022062505/5edc7621ad6a402d66672064/html5/thumbnails/104.jpg)
Prim’s Algorithm Example
E ′ = {(a, b), (b, e)}V ′ = {a, b, e}|V ′| = 3
![Page 105: Discrete Mathematics - Treesnlp.jbnu.ac.kr/DM/slides/ch11_trees.pdfDiscrete Mathematics Trees H. Turgut Uyar Ay¸seg¨ul Gencata Yayımlı Emre Harmancı 2001-2016](https://reader035.fdocuments.in/reader035/viewer/2022062505/5edc7621ad6a402d66672064/html5/thumbnails/105.jpg)
Prim’s Algorithm Example
E ′ = {(a, b), (b, e), (e, g)}V ′ = {a, b, e, g}|V ′| = 4
![Page 106: Discrete Mathematics - Treesnlp.jbnu.ac.kr/DM/slides/ch11_trees.pdfDiscrete Mathematics Trees H. Turgut Uyar Ay¸seg¨ul Gencata Yayımlı Emre Harmancı 2001-2016](https://reader035.fdocuments.in/reader035/viewer/2022062505/5edc7621ad6a402d66672064/html5/thumbnails/106.jpg)
Prim’s Algorithm Example
E ′ = {(a, b), (b, e), (e, g)}V ′ = {a, b, e, g}|V ′| = 4
![Page 107: Discrete Mathematics - Treesnlp.jbnu.ac.kr/DM/slides/ch11_trees.pdfDiscrete Mathematics Trees H. Turgut Uyar Ay¸seg¨ul Gencata Yayımlı Emre Harmancı 2001-2016](https://reader035.fdocuments.in/reader035/viewer/2022062505/5edc7621ad6a402d66672064/html5/thumbnails/107.jpg)
Prim’s Algorithm Example
E ′ = {(a, b), (b, e), (e, g), (d , e)}V ′ = {a, b, e, g , d}|V ′| = 5
![Page 108: Discrete Mathematics - Treesnlp.jbnu.ac.kr/DM/slides/ch11_trees.pdfDiscrete Mathematics Trees H. Turgut Uyar Ay¸seg¨ul Gencata Yayımlı Emre Harmancı 2001-2016](https://reader035.fdocuments.in/reader035/viewer/2022062505/5edc7621ad6a402d66672064/html5/thumbnails/108.jpg)
Prim’s Algorithm Example
E ′ = {(a, b), (b, e), (e, g), (d , e)}V ′ = {a, b, e, g , d}|V ′| = 5
![Page 109: Discrete Mathematics - Treesnlp.jbnu.ac.kr/DM/slides/ch11_trees.pdfDiscrete Mathematics Trees H. Turgut Uyar Ay¸seg¨ul Gencata Yayımlı Emre Harmancı 2001-2016](https://reader035.fdocuments.in/reader035/viewer/2022062505/5edc7621ad6a402d66672064/html5/thumbnails/109.jpg)
Prim’s Algorithm Example
E ′ = {(a, b), (b, e), (e, g),(d , e), (f , g)
}V ′ = {a, b, e, g , d , f }|V ′| = 6
![Page 110: Discrete Mathematics - Treesnlp.jbnu.ac.kr/DM/slides/ch11_trees.pdfDiscrete Mathematics Trees H. Turgut Uyar Ay¸seg¨ul Gencata Yayımlı Emre Harmancı 2001-2016](https://reader035.fdocuments.in/reader035/viewer/2022062505/5edc7621ad6a402d66672064/html5/thumbnails/110.jpg)
Prim’s Algorithm Example
E ′ = {(a, b), (b, e), (e, g),(d , e), (f , g)
}V ′ = {a, b, e, g , d , f }|V ′| = 6
![Page 111: Discrete Mathematics - Treesnlp.jbnu.ac.kr/DM/slides/ch11_trees.pdfDiscrete Mathematics Trees H. Turgut Uyar Ay¸seg¨ul Gencata Yayımlı Emre Harmancı 2001-2016](https://reader035.fdocuments.in/reader035/viewer/2022062505/5edc7621ad6a402d66672064/html5/thumbnails/111.jpg)
Prim’s Algorithm Example
E ′ = {(a, b), (b, e), (e, g),(d , e), (f , g), (c, g)
}V ′ = {a, b, e, g , d , f , c}|V ′| = 7
![Page 112: Discrete Mathematics - Treesnlp.jbnu.ac.kr/DM/slides/ch11_trees.pdfDiscrete Mathematics Trees H. Turgut Uyar Ay¸seg¨ul Gencata Yayımlı Emre Harmancı 2001-2016](https://reader035.fdocuments.in/reader035/viewer/2022062505/5edc7621ad6a402d66672064/html5/thumbnails/112.jpg)
Prim’s Algorithm Example
E ′ = {(a, b), (b, e), (e, g),(d , e), (f , g), (c, g)
}V ′ = {a, b, e, g , d , f , c}|V ′| = 7
![Page 113: Discrete Mathematics - Treesnlp.jbnu.ac.kr/DM/slides/ch11_trees.pdfDiscrete Mathematics Trees H. Turgut Uyar Ay¸seg¨ul Gencata Yayımlı Emre Harmancı 2001-2016](https://reader035.fdocuments.in/reader035/viewer/2022062505/5edc7621ad6a402d66672064/html5/thumbnails/113.jpg)
Prim’s Algorithm Example
total weight: 17
![Page 114: Discrete Mathematics - Treesnlp.jbnu.ac.kr/DM/slides/ch11_trees.pdfDiscrete Mathematics Trees H. Turgut Uyar Ay¸seg¨ul Gencata Yayımlı Emre Harmancı 2001-2016](https://reader035.fdocuments.in/reader035/viewer/2022062505/5edc7621ad6a402d66672064/html5/thumbnails/114.jpg)
References
Required Reading: Grimaldi
Chapter 12: Trees
12.1. Definitions and Examples12.2. Rooted Trees
Chapter 13: Optimization and Matching
13.2. Minimal Spanning Trees:The Algorithms of Kruskal and Prim