Chapter 11
Chapter 11
Chapter 11
11.1 Introduction to TREE
and its Terminologies
Graph VS TREE
• Trees were introduced by the mathematician Cayley in 1857 in his work counting
the number of isomers of saturated hydrocarbons. The two isomers of butane are: .
Solution:
(ii) The parent of c is b. The children
of g are h, i, and j. The siblings of
h are i and j. The ancestors of e
are c, b, and a. The descendants
of b are c, d, and e.
Solution:
Example: Are the following rooted trees full m-ary trees for some
positive integer m?
5-ary tree.
• In T3 each internal vertex has five children, so T3 is a full
• T4 is not a full m-ary tree for any m because some of its internal
vertices have two children and others have three children.
FREE: For Complete Playlist: https://www.youtube.com/c/FahadHussaintutorial/playlists
For Code, Slide and Books: https://fahadhussaincs.blogspot.com/
Balanced m-Ary Trees
levels h or h − 1.
Definition: A rooted m-ary tree of height h is balanced if all leaves are at
levels 2, 3, and 4.
Solution: T1 and T3 are balanced, but T2 is not because it has leaves at
• A binary tree for the expression can be built from the bottom
up, as is illustrated here.
Prefix Notation
(1878-1956)
is + ↑ + x y 2 / − x 4 3.
• Prefix expressions are evaluated by working from right to left. When
we encounter an operator, we perform the corresponding operation
with the two operations to the right.
FREE: For Complete Playlist: https://www.youtube.com/c/FahadHussaintutorial/playlists
For Code, Slide and Books: https://fahadhussaincs.blogspot.com/
Prefix Notation
• Example: We show the steps used to evaluate a particular prefix
expression:
4)/3).
• A binary operator follows its two operands. So, to evaluate an
expression one works from left to right, carrying out an operation
represented by an operator on its preceding operands.
• Prim’s algorithm
• Kruskal’s Algorithm
PRIM’S ALGORITHM
MST COST = 23
KRUSKAL’S ALGORITHM
MST COST = 23
11.4 Spanning Trees
Depth-First Search | Breadth-First Search |
Backtracking Applications | Depth-First
Search in Directed Graphs