Chapter 8
Trees
MAD101
Ly Anh Duong
[email protected]
Table of Contents
1 Intro.& Def.
▶ Intro.& Def.
▶ Bi.S.Tr.
▶ Prefix code
▶ De.tree
▶ Tree Traversal
▶ I.,P.&P.fix No.
▶ Spa.Trees
▶ Min.Span.Trees
▶ Problems
The Bernoulli family of mathematicians
1 Intro.& Def.
Ly Anh Duong Chapter 8 Trees [email protected] 3 / 135
An organizational tree for a computer company
1 Intro.& Def.
Ly Anh Duong Chapter 8 Trees [email protected] 4 / 135
Definition
1 Intro.& Def.
A tree is a connected undirected graph with no simple circuits.
Ly Anh Duong Chapter 8 Trees [email protected] 5 / 135
Definition
1 Intro.& Def.
A tree is a connected undirected graph with no simple circuits.
G1 , G2 are trees and G3 , G4 are not.
Ly Anh Duong Chapter 8 Trees
[email protected] 5 / 135
Theorem
1 Intro.& Def.
An undirected graph is a tree if and only if there is a unique simple path between
any two of its vertices.
Ly Anh Duong Chapter 8 Trees [email protected] 6 / 135
Definition
1 Intro.& Def.
A rooted tree is a tree in which one vertex has been designated as the root and
every edge is directed away from the root.
Ly Anh Duong Chapter 8 Trees [email protected] 7 / 135
Some common concepts
1 Intro.& Def.
• g is root of tree
• j is parent of m and l
• m or l is a child of j
• m, l are siblings
• g is ancestor of m and m is descendant of
g
• i, k, l, m are leaves: nodes without children.
• g, h, j are Internal nodes: nodes have
children.
• n=i+l
Ly Anh Duong Chapter 8 Trees [email protected] 8 / 135
Definition
1 Intro.& Def.
• A rooted tree is called an m-ary tree if every internal vertex has no more
than m children.
• The tree is called a full m-ary tree if every internal vertex has exactly m
children.
• An m-ary tree with m = 2 is called a binary tree.
Ly Anh Duong Chapter 8 Trees [email protected] 9 / 135
Definition
1 Intro.& Def.
An ordered rooted tree is a rooted tree where the children of each internal
vertex are ordered (which is usually represented as in the graph).
f is the left child of d and g is the right child of d
(b): the left subtree of c and (c): the right subtree of c.
Ly Anh Duong Chapter 8 Trees
[email protected] 10 / 135
Properties of trees
1 Intro.& Def.
1. A tree with n vertices has n − 1 edges.
2. For a m-ary tree
n=i+l
3. For a full m-ary tree
n = mi + 1
• n are number of nodes,
• i are number of internal nodes,
• l are number of leaves.
Example.
a. How many leaves are there in a full 5-ary tree with 56 nodes. (l = 45)
b. How many vertices are there in a full ternary (3-ary) tree with 27 leaves.
(n = 40)
Ly Anh Duong Chapter 8 Trees
[email protected] 11 / 135
Definition
1 Intro.& Def.
• The level of a vertex v in a rooted
tree is the length of the unique path
from the root to this vertex.
• The level of the root is defined to
be zero.
• The height of a rooted tree is the
maximum of the levels of vertices.
Ly Anh Duong Chapter 8 Trees [email protected] 12 / 135
Example.
1 Intro.& Def.
1. There are 10 nodes leaves in T1 and their level are 3&4.(h=4)
2. There are 7 nodes leaves in T2 and their level are 2,3 & 4.(h=4)
3. There are 10 nodes leaves in T3 and their level are 3.(h=3)
A rooted m-ary tree of height h is balanced if all leaves are at levels h or h − 1.
In example above, T1 , T3 are balanced and T2 is not.
Ly Anh Duong Chapter 8 Trees
[email protected] 13 / 135
Theorem
1 Intro.& Def.
There are at most mh leaves in an m-ary tree of height h.
Ly Anh Duong Chapter 8 Trees [email protected] 14 / 135
Corollary
1 Intro.& Def.
If an m-ary tree of height h has l leaves, then h ≥ ⌈logm l⌉. If the m-ary tree is full
and balanced, then h = ⌈logm l⌉.
Ly Anh Duong Chapter 8 Trees [email protected] 15 / 135
Table of Contents
2 Bi.S.Tr.
▶ Intro.& Def.
▶ Bi.S.Tr.
▶ Prefix code
▶ De.tree
▶ Tree Traversal
▶ I.,P.&P.fix No.
▶ Spa.Trees
▶ Min.Span.Trees
▶ Problems
Definition
2 Bi.S.Tr.
• A binary search tree where each vertex is labeled with a key.
• The key of a vertex is both larger than the keys of all vertices in its left
subtree and smaller than the keys of all vertices in its right subtree.
Ly Anh Duong Chapter 8 Trees [email protected] 17 / 135
Example.
2 Bi.S.Tr.
How about 6, 13, 4?
Ly Anh Duong Chapter 8 Trees
[email protected] 18 / 135
Example.
2 Bi.S.Tr.
Construct the Binary Search Trees for 8, 3, 11, 15, 2, 4, 14. How many comparisons
are required to locate number 6 in the search tree.
Ly Anh Duong Chapter 8 Trees [email protected] 19 / 135
Example.
2 Bi.S.Tr.
Construct the Binary Search Trees for 8, 3, 11, 15, 2, 4, 14. How many comparisons
are required to locate number 6 in the search tree. =⇒ 4 comparisons are
required.
Ly Anh Duong Chapter 8 Trees [email protected] 19 / 135
Alphabetical order
2 Bi.S.Tr.
Binary search tree for words: mango,
cherry, grape, apple, guava, watermelon,
satsuma, banana.
a < b < c...; ab < ac < ae...; abc < abd <
abe...
Ly Anh Duong Chapter 8 Trees [email protected] 20 / 135
Algorithm: Locating an Item in or Adding an
Item to a Binary Search Tree
2 Bi.S.Tr.
Note: The algorithm returns the location of x or adds a new vertex with label x
into binary search tree. Complexity O(logn).
Ly Anh Duong Chapter 8 Trees [email protected] 21 / 135
Table of Contents
3 Prefix code
▶ Intro.& Def.
▶ Bi.S.Tr.
▶ Prefix code
▶ De.tree
▶ Tree Traversal
▶ I.,P.&P.fix No.
▶ Spa.Trees
▶ Min.Span.Trees
▶ Problems
Introduction
3 Prefix code
• Standard ASCII (American Standard Code for Information Interchange)
character encoding: use 8 bits (1 byte) to store each character.
• For example, using the standard ASCII encoding, the 12- characters string
”no one knows” requires 12 ∗ 8 = 96 bits total.
Ly Anh Duong Chapter 8 Trees [email protected] 23 / 135
Introduction
3 Prefix code
• A better code scheme
12 ∗ 3 = 36 bits total.
• A variable-length encoding
Use 32 bits total.
Ly Anh Duong Chapter 8 Trees
[email protected] 24 / 135
Introduction
3 Prefix code
Consider the codes
1. Use the following code a : 10 e : 01 t : 0110 n:1
Decode the message 01101
01101 mean ”ean”
01101 mean ”tn”
Hence, it is not a prefix code.
2. Use the following code a : 10 e : 01 t : 001 n : 11
Decode the message 1101001
1101001 mean ”net” only.
It is Prefix code
Ly Anh Duong Chapter 8 Trees [email protected] 25 / 135
Definition
3 Prefix code
Prefix code is a type of codes which encodes the letters so that the bit string for
a letter never occurs as the first part of the bit string for another letter.
Ly Anh Duong Chapter 8 Trees [email protected] 26 / 135
A binary tree with a prefix code
3 Prefix code
s : 1111
a : 10
n : 1110
e:0
So, ”sane” will be store as 11111011100 →
11 bits.
Hence, compression factor: 32/11 ∼ 3. Is
it best? How to construct a prefix code
that is using the fewest bits?
Ly Anh Duong Chapter 8 Trees [email protected] 27 / 135
Huffman coding algorithm
3 Prefix code
• Find frequencies (probabilities) of each character in a text,
• Contructing a binary tree representing prefix codes of character. Notes:
• Sort by frequencies (probabilities) from small to large after each step,
• The larger weight sub-tree is on the left of the binary tree.
Example. Use Huffman coding algorithm to encode the word ”google”.
Ly Anh Duong Chapter 8 Trees [email protected] 28 / 135
Solution.
3 Prefix code
• Counting frequencies of letter
e l g o
1/6 1/6 2/6 2/6
• P (l) = P (e) = 1/6
Ly Anh Duong Chapter 8 Trees [email protected] 29 / 135
Example
3 Prefix code
• P (l) + P (e) = 2/6 = P (g)
• Final character
Ly Anh Duong Chapter 8 Trees [email protected] 30 / 135
Example.
3 Prefix code
• 0:1
• g : 01
• l : 001
• e : 000
Hence, ”google” will be store as 011101001000 →
12 bits. Compare with ASCII, the copression factor
is 48/12 ∼ 4.
Ly Anh Duong Chapter 8 Trees [email protected] 31 / 135
Example.
3 Prefix code
Use Huffman coding algorithm to encode the text ”maximum”. What is the
average number of bits?
Ly Anh Duong Chapter 8 Trees [email protected] 32 / 135
Example.
3 Prefix code
Use Huffman coding algorithm to encode the text ”maximum”. What is the
average number of bits?
Ans: The average number of bits used to encode a symbol using this encoding is
15
≈ 2.14
7
Ly Anh Duong Chapter 8 Trees [email protected] 32 / 135
Example
3 Prefix code
Use Huffman coding to encode the following symbols with the frequencies listed:
A: 0.08, B: 0.10, C: 0.12, D: 0.15, E: 0.20, F: 0.35. What is the average number of
bits used to encode a character?
Ly Anh Duong Chapter 8 Trees [email protected] 33 / 135
Example
3 Prefix code
Use Huffman coding to encode the following symbols with the frequencies listed:
A: 0.08, B: 0.10, C: 0.12, D: 0.15, E: 0.20, F: 0.35. What is the average number of
bits used to encode a character?
Ans: The average number of bits used to encode a symbol using this encoding is
3 × 0.08 + 3 × 0.10 + 3 × 0.12 + 3 × 0.15 + 2 × 0.20 + 2 × 0.35 = 2.45
Ly Anh Duong Chapter 8 Trees [email protected] 33 / 135
Huffman Coding Algorithm
3 Prefix code
Ly Anh Duong Chapter 8 Trees [email protected] 34 / 135
Table of Contents
4 De.tree
▶ Intro.& Def.
▶ Bi.S.Tr.
▶ Prefix code
▶ De.tree
▶ Tree Traversal
▶ I.,P.&P.fix No.
▶ Spa.Trees
▶ Min.Span.Trees
▶ Problems
A counterfeit coin problem
4 De.tree
Suppose there are seven coins, all with the
same weight, and a counterfeit coin that
weighs less than the others. How many
weighings are necessary using a balance
scale to determine which of the eight coins
is the counterfeit one?
Ly Anh Duong Chapter 8 Trees [email protected] 36 / 135
Solution
4 De.tree
Thus, n = 8, we need 2 = ⌈log3 8⌉ = 2 weighings. How about n = 3, n = 9, n = 27?
→ In general, we need ⌈log3 n⌉ weighings to find the counterfeit coin.
Ly Anh Duong Chapter 8 Trees
[email protected] 37 / 135
Definition
4 De.tree
A rooted tree in which each internal vertex corresponds to a decision, with a
subtree at these vertices for each possible outcome of the decision, is called a
decision tree.
Ly Anh Duong Chapter 8 Trees [email protected] 38 / 135
Example
4 De.tree
Form a decision tree of sorting three number a, b, c.
Ly Anh Duong Chapter 8 Trees [email protected] 39 / 135
Theorem
4 De.tree
A sorting algorithm based on binary comparisons requires at least ⌈log n!⌉
comparisons.
Ly Anh Duong Chapter 8 Trees [email protected] 40 / 135
Corollary
4 De.tree
The number of comparisons used by a sorting algorithm to sort n elements based
on binary comparisons is Ω(n log n).
Ly Anh Duong Chapter 8 Trees [email protected] 41 / 135
Theorem
4 De.tree
The average number of comparisons used by a sorting algorithm to sort n elements
based on binary comparisons is Ω(n log n).
Ly Anh Duong Chapter 8 Trees [email protected] 42 / 135
Table of Contents
5 Tree Traversal
▶ Intro.& Def.
▶ Bi.S.Tr.
▶ Prefix code
▶ De.tree
▶ Tree Traversal
▶ I.,P.&P.fix No.
▶ Spa.Trees
▶ Min.Span.Trees
▶ Problems
Introduction
5 Tree Traversal
Ly Anh Duong Chapter 8 Trees [email protected] 44 / 135
Tree Traversal
5 Tree Traversal
Traversal a tree: A way to visit all vertices of the rooted tree.
Ly Anh Duong Chapter 8 Trees [email protected] 45 / 135
Traversal Algorithms
5 Tree Traversal
• At a time, a vertex is visited,
• Recursive algorithm,
• Bases on orders of tasks, traversals are classified into:
1. Pre-order traversal. N L R
2. In-order traversal. L N R
3. Post-order traversal. L R N
where,
• N: root node
• L: left subtree
• R: right subtree
Ly Anh Duong Chapter 8 Trees [email protected] 46 / 135
Example.
5 Tree Traversal
Pre-order In-order Post-order
NLR LNR LRN
abcd bacd bcda
Ly Anh Duong Chapter 8 Trees
[email protected] 47 / 135
Pre-order traversal example.
5 Tree Traversal
Ly Anh Duong Chapter 8 Trees [email protected] 48 / 135
Pre-order traversal example.
5 Tree Traversal
Pre-order traversal: a b e f c d g h
Ly Anh Duong Chapter 8 Trees [email protected] 48 / 135
Pre-order traversal algorithm
5 Tree Traversal
Ly Anh Duong Chapter 8 Trees [email protected] 49 / 135
In-order traversal example
5 Tree Traversal
In-order traversal: e b f a c g d h
Ly Anh Duong Chapter 8 Trees [email protected] 50 / 135
In-order traversal algorithm
5 Tree Traversal
Ly Anh Duong Chapter 8 Trees [email protected] 51 / 135
Post-order traversal example.
5 Tree Traversal
Post-order traversal: e f b c g h d a
Ly Anh Duong Chapter 8 Trees [email protected] 52 / 135
Post-order traversal algorithm
5 Tree Traversal
Ly Anh Duong Chapter 8 Trees [email protected] 53 / 135
Exercise
5 Tree Traversal
Ly Anh Duong Chapter 8 Trees [email protected] 54 / 135
Solution.
5 Tree Traversal
1. Pre-order: 8 3 1 6 7 11 9 13 21
2. In-order: 1 3 6 7 8 9 11 13 21
3. Post-order: 1 7 6 3 9 21 13 11 8
In in-order, the sequences of numbers are sorted.
Ly Anh Duong Chapter 8 Trees [email protected] 55 / 135
Table of Contents
6 I.,P.&P.fix No.
▶ Intro.& Def.
▶ Bi.S.Tr.
▶ Prefix code
▶ De.tree
▶ Tree Traversal
▶ I.,P.&P.fix No.
▶ Spa.Trees
▶ Min.Span.Trees
▶ Problems
Representing the expression
6 I.,P.&P.fix No.
• +: addition
• −: subtraction
• ∗: multiplication
• /: division
• ↑: exponentiation
The expression can be represent by the binary trees with the rules:
• The internal vertices represent operations,
• The leaves represent the variables or numbers.
Ly Anh Duong Chapter 8 Trees [email protected] 57 / 135
Example
6 I.,P.&P.fix No.
What is the ordered rooted tree that represents the expression
((x + y) ↑ 2) + ((x − 4)/3)?
Ly Anh Duong Chapter 8 Trees [email protected] 58 / 135
Example
6 I.,P.&P.fix No.
What is the ordered rooted tree that represents the expression
(x + y)/(x + 3), (x + (y/x)) + 3, and x + (y/(x + 3))?
Ly Anh Duong Chapter 8 Trees [email protected] 59 / 135
Definition
6 I.,P.&P.fix No.
• We obtain prefix form of an expression when we traverse its rooted tree in
preorder + x y
• We obtain infix form of an expression when we traverse its rooted tree in
inorder x + y
• We obtain postfix form of an expression when we traverse its rooted tree in
postorder x y +
Note: Prefix form is called Polish notation and Postfix form is called reverse
Polish notation.
Ly Anh Duong Chapter 8 Trees [email protected] 60 / 135
How to find prefix and postfix form from infix
form?
6 I.,P.&P.fix No.
1. Draw expression tree.
2. Using Preorder traverse → Prefix form. Using Postorder traverse → Postfix
form.
Ly Anh Duong Chapter 8 Trees [email protected] 61 / 135
Example
6 I.,P.&P.fix No.
What is the prefix (infix, postfix) form of the following tree?
• Infix form ((x + y) ↑ 2) + ((x − 4)/3)
• Prefix form + ↑ +xy2/ − x43
• Postfix form xy + 2 ↑ x4 − 3/+
Ly Anh Duong Chapter 8 Trees [email protected] 62 / 135
Evaluate a Prefix and Postfix form
6 I.,P.&P.fix No.
1. Postfix form, work from left to right.
2. Prefix form, work from right to left.
Examples
1. + − ∗235/ ↑ 234
2. 723 ∗ −4 ↑ 93/+
Ly Anh Duong Chapter 8 Trees [email protected] 63 / 135
Solution.
6 I.,P.&P.fix No.
Ly Anh Duong Chapter 8 Trees [email protected] 64 / 135
Table of Contents
7 Spa.Trees
▶ Intro.& Def.
▶ Bi.S.Tr.
▶ Prefix code
▶ De.tree
▶ Tree Traversal
▶ I.,P.&P.fix No.
▶ Spa.Trees
▶ Min.Span.Trees
▶ Problems
Introduction
7 Spa.Trees
The system of roads in Maine (USA)
• The only way the roads can be kept open in the winter is by frequently
plowing them,
• The highway department wants to plow the fewest roads so that there will
always be cleared roads connecting any two towns,
• How can this be done?
Ly Anh Duong Chapter 8 Trees [email protected] 66 / 135
Introduction
7 Spa.Trees
At least five roads must be plowed to ensure that there is a path between any two
towns
Ly Anh Duong Chapter 8 Trees [email protected] 67 / 135
Definition
7 Spa.Trees
Let G be a simple graph. A spanning tree of G is a subgraph of G that is a tree
containing every vertex of G.
Ly Anh Duong Chapter 8 Trees [email protected] 68 / 135
Example
7 Spa.Trees
Find a spanning tree of this simple graph:
Ly Anh Duong Chapter 8 Trees [email protected] 69 / 135
Solution.
7 Spa.Trees
• Removed {a, e} • Removed {c, g}
• Removed {e, f }
Ly Anh Duong Chapter 8 Trees [email protected] 70 / 135
Solution.
7 Spa.Trees
The spanning tree above is not unique, there are four different spanning trees
Ly Anh Duong Chapter 8 Trees [email protected] 71 / 135
Theorem
7 Spa.Trees
A simple graph is connected if and only if it has a spanning tree.
Ly Anh Duong Chapter 8 Trees [email protected] 72 / 135
Depth-First Search (backtracking)
7 Spa.Trees
• Arbitrarily choose a vertex of the graph as the root. Form a path starting at
this vertex by successively adding vertices and edges, where each new edge is
incident with the last vertex in the path and a vertex not already in the path.
• Continue adding vertices and edges to this path as long as possible,
1. If the path goes through all vertices of the graph, the tree consisting of this path
is a spanning tree.
2. If the path does not go through all vertices, move back to the next to last vertex
in the path, forming new paths (adding new vertices and edges) that are as long
as possible until no more edges can be added → spanning tree.
Ly Anh Duong Chapter 8 Trees [email protected] 73 / 135
Example
7 Spa.Trees
Find a spanning tree of this graph using Depth-First Search:
Ly Anh Duong Chapter 8 Trees [email protected] 74 / 135
Solution.
7 Spa.Trees
Ly Anh Duong Chapter 8 Trees [email protected] 75 / 135
Solution.
7 Spa.Trees
Ly Anh Duong Chapter 8 Trees [email protected] 76 / 135
Tree edges and back edges
7 Spa.Trees
• Tree edges: highlight,
• Ly
Back edges: thinner black lines.Chapter 8 Trees
Anh Duong
[email protected] 77 / 135
Example
7 Spa.Trees
Find a spanning tree of this graph using Depth-First Search:
Ly Anh Duong Chapter 8 Trees [email protected] 78 / 135
Solution.
7 Spa.Trees
Ly Anh Duong Chapter 8 Trees [email protected] 79 / 135
Depth-First Search Algorithm
7 Spa.Trees
Ly Anh Duong Chapter 8 Trees [email protected] 80 / 135
Breadth-First Search
7 Spa.Trees
• Arbitrarily choose a root from the vertices of the graph, then add all edges
incident to this vertex (level 1),
• For each vertex at level 1, add each edge incident to this vertex to the tree as
long as it does not produce a simple circuit (level 2),
• The same procedure until all the vertices in the tree have been added.
Ly Anh Duong Chapter 8 Trees [email protected] 81 / 135
Example
7 Spa.Trees
Find a spanning tree of this graph using Breadth-First Search:
Ly Anh Duong Chapter 8 Trees [email protected] 82 / 135
Solution.
7 Spa.Trees
Ly Anh Duong Chapter 8 Trees [email protected] 83 / 135
Example.
7 Spa.Trees
Find a spanning tree of this graph using Breadth-First Search:
Ly Anh Duong Chapter 8 Trees [email protected] 84 / 135
Solution
7 Spa.Trees
Ly Anh Duong Chapter 8 Trees [email protected] 85 / 135
Breadth-First Search Algorithm
7 Spa.Trees
Ly Anh Duong Chapter 8 Trees [email protected] 86 / 135
Table of Contents
8 Min.Span.Trees
▶ Intro.& Def.
▶ Bi.S.Tr.
▶ Prefix code
▶ De.tree
▶ Tree Traversal
▶ I.,P.&P.fix No.
▶ Spa.Trees
▶ Min.Span.Trees
▶ Problems
Introduction
8 Min.Span.Trees
A company plans to build a communications network connecting its five computer
centers.
• Which links should be made to ensure that there is a path between any two
computer centers so that the total cost of the network is minimized?
• We can solve this problem by finding a spanning tree so that the sum of the
weights of the edges of the tree is minimized. Such a spanning tree is called a
minimum spanning tree.
Ly Anh Duong Chapter 8 Trees [email protected] 88 / 135
Definition
8 Min.Span.Trees
A minimum spanning tree in a connected weighted graph is a spanning tree
that has the smallest possible sum of weights of its edges.
Ly Anh Duong Chapter 8 Trees [email protected] 89 / 135
Prim’s Algorithm
8 Min.Span.Trees
• Begin by choosing any edge with smallest weight, putting it into the spanning
tree.
• Successively add to the tree edges of minimum weight that are incident to a
vertex already in the tree, never forming a simple circuit with those edges
already in the tree.
• Stop when n − 1 edges have been added.
Ly Anh Duong Chapter 8 Trees [email protected] 90 / 135
Example
8 Min.Span.Trees
Use Prim’s algorithm to find a minimum spanning tree in the graph
Ly Anh Duong Chapter 8 Trees [email protected] 91 / 135
Solution.
8 Min.Span.Trees
Ly Anh Duong Chapter 8 Trees [email protected] 92 / 135
Solution.
8 Min.Span.Trees
Ly Anh Duong Chapter 8 Trees [email protected] 93 / 135
Solution.
8 Min.Span.Trees
=⇒ Total 24
Ly Anh Duong Chapter 8 Trees [email protected] 94 / 135
Example.
8 Min.Span.Trees
Use Prim’s algorithm to find a minimum spanning tree in the graph
Ly Anh Duong Chapter 8 Trees [email protected] 95 / 135
Solution.
8 Min.Span.Trees
Ly Anh Duong Chapter 8 Trees [email protected] 96 / 135
Prim’s Algorithm
8 Min.Span.Trees
Ly Anh Duong Chapter 8 Trees [email protected] 97 / 135
Kruskal’s Algorithm
8 Min.Span.Trees
• Choose an edge in the graph with minimum weight,
• Successively add edges with minimum weight that do not form a simple circuit
with those edges already chosen,
• Stop after n − 1 edges have been selected.
Ly Anh Duong Chapter 8 Trees [email protected] 98 / 135
Example.
8 Min.Span.Trees
Use Kruskal’s algorithm to find a minimum spanning tree in the weighted graph
Ly Anh Duong Chapter 8 Trees [email protected] 99 / 135
Solution.
8 Min.Span.Trees
Ly Anh Duong Chapter 8 Trees [email protected] 100 / 135
Kruskal’s Algorithm
8 Min.Span.Trees
Ly Anh Duong Chapter 8 Trees [email protected] 101 / 135
Note.
8 Min.Span.Trees
In Prim’s algorithm, edges of minimum weight that are incident to a vertex
already in the tree, and not forming a circuit, are chosen; whereas in Kruskal’s
algorithm edges of minimum weight that are not necessarily incident to a vertex
already in the tree, and that do not form a circuit, are chosen.
Ly Anh Duong Chapter 8 Trees [email protected] 102 / 135
Table of Contents
9 Problems
▶ Intro.& Def.
▶ Bi.S.Tr.
▶ Prefix code
▶ De.tree
▶ Tree Traversal
▶ I.,P.&P.fix No.
▶ Spa.Trees
▶ Min.Span.Trees
▶ Problems
Quizz
9 Problems
Ans: 2.5
Ly Anh Duong Chapter 8 Trees [email protected] 104 / 135
Quizz
9 Problems
Ly Anh Duong Chapter 8 Trees [email protected] 105 / 135
Quizz
9 Problems
Ans: 5, 3, 2, 4, 6, 7
Ly Anh Duong Chapter 8 Trees [email protected] 106 / 135
Quizz
9 Problems
Ans: 200
Ly Anh Duong Chapter 8 Trees [email protected] 107 / 135
Quizz
9 Problems
Ans:Ly(i)
Anh Duong Chapter 8 Trees [email protected] 108 / 135
Quizz
9 Problems
Ans:None of the others
Ly Anh Duong Chapter 8 Trees
[email protected] 109 / 135
Quizz
9 Problems
Ans: dabbce
Ly Anh Duong Chapter 8 Trees [email protected] 110 / 135
Quizz
9 Problems
Ans: 3
Ly Anh Duong Chapter 8 Trees [email protected] 111 / 135
Introduction to Trees
9 Problems
Ly Anh Duong Chapter 8 Trees [email protected] 112 / 135
Introduction to Trees
9 Problems
Ly Anh Duong Chapter 8 Trees [email protected] 113 / 135
Introduction to Trees
9 Problems
Ly Anh Duong Chapter 8 Trees [email protected] 114 / 135
Applications of Trees
9 Problems
Ly Anh Duong Chapter 8 Trees [email protected] 115 / 135
Applications of Trees
9 Problems
Ly Anh Duong Chapter 8 Trees [email protected] 116 / 135
Applications of Trees
9 Problems
Ly Anh Duong Chapter 8 Trees [email protected] 117 / 135
Applications of Trees
9 Problems
Ly Anh Duong Chapter 8 Trees [email protected] 118 / 135
Tree Traversal
9 Problems
Ly Anh Duong Chapter 8 Trees [email protected] 119 / 135
Tree Traversal
9 Problems
Ly Anh Duong Chapter 8 Trees [email protected] 120 / 135
Tree Traversal
9 Problems
Ly Anh Duong Chapter 8 Trees [email protected] 121 / 135
Tree Traversal
9 Problems
Ly Anh Duong Chapter 8 Trees [email protected] 122 / 135
Spanning Trees
9 Problems
Ly Anh Duong Chapter 8 Trees [email protected] 123 / 135
Spanning Trees
9 Problems
Ly Anh Duong Chapter 8 Trees [email protected] 124 / 135
Spanning Trees
9 Problems
Ly Anh Duong Chapter 8 Trees [email protected] 125 / 135
Spanning Trees
9 Problems
Ly Anh Duong Chapter 8 Trees [email protected] 126 / 135
Spanning Trees
9 Problems
Ly Anh Duong Chapter 8 Trees [email protected] 127 / 135
Spanning Trees
9 Problems
Ly Anh Duong Chapter 8 Trees [email protected] 128 / 135
Spanning Trees
9 Problems
Ly Anh Duong Chapter 8 Trees [email protected] 129 / 135
Spanning Trees
9 Problems
Ly Anh Duong Chapter 8 Trees [email protected] 130 / 135
Spanning Trees
9 Problems
Ly Anh Duong Chapter 8 Trees [email protected] 131 / 135
Minimum Spanning Trees
9 Problems
Ly Anh Duong Chapter 8 Trees [email protected] 132 / 135
Minimum Spanning Trees
9 Problems
Ly Anh Duong Chapter 8 Trees [email protected] 133 / 135
Minimum Spanning Trees
9 Problems
Ly Anh Duong Chapter 8 Trees [email protected] 134 / 135
Q&A
Thank you for listening!