0% found this document useful (0 votes)
600 views

Discrete Mathematics: Trees

Here are the steps to find a spanning tree of the given graph using BFS: 1. Choose a starting vertex, say 'a'. Mark it visited and enqueue it. 2. Dequeue the vertex 'a'. Consider its unvisited neighbors 'b' and 'd' and enqueue them. Mark 'b' and 'd' visited. 3. Dequeue 'b'. Consider its unvisited neighbor 'c' and enqueue it. Mark 'c' visited. Dequeue 'd'. Consider its unvisited neighbor 'e' and enqueue it. Mark 'e' visited. 4. Dequeue 'c'. It has no unvisited neighbors. Dequeue 'e'. Consider its

Uploaded by

Sahithi Athkuri
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
600 views

Discrete Mathematics: Trees

Here are the steps to find a spanning tree of the given graph using BFS: 1. Choose a starting vertex, say 'a'. Mark it visited and enqueue it. 2. Dequeue the vertex 'a'. Consider its unvisited neighbors 'b' and 'd' and enqueue them. Mark 'b' and 'd' visited. 3. Dequeue 'b'. Consider its unvisited neighbor 'c' and enqueue it. Mark 'c' visited. Dequeue 'd'. Consider its unvisited neighbor 'e' and enqueue it. Mark 'e' visited. 4. Dequeue 'c'. It has no unvisited neighbors. Dequeue 'e'. Consider its

Uploaded by

Sahithi Athkuri
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 36

Discrete

Mathematics

Trees
1. Introduction to Trees
Def 1 A Tree is a connected undirected graph with no circuits.

Example 1. Which of the graphs are trees?

Sol: G1, G2 ,G4


Theorem 1. Any undirected graph is a tree if and only if
there is a unique simple path between any two of its
vertices.
Def 2. A Rooted tree is a tree in which one vertex has been designed
as the root and every edge is directed away from the root.

Example
Definitions: a is the parent of b, b is the child of a,
a c, d, e are siblings,
a, b, d are ancestors of f
b c, d, e, f, g are descendants of b
c, e, f, g are leaves of the tree (deg=1)
c d e a, b, d are internal vertices of the tree
(at least one child)
f g
d
subtree with d as its root:
f g
Def 3: 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.

Example 3

full binary tree full 3-ary tree full 5-ary tree not full 3-ary tree
Def:
a

b c
left child of a

d e f
right child of c
left subtree of a

right subtree of a
Theorem 2. A tree with n vertices has exactly n-1 edges.

Proof. (by induction on n)


n = 1 : K1 is the only tree of order 1, |E(K1)| = 0. ok!
Assume the result is true for every tree of order n = k. w
Let T be a tree of order n = k+1, v be a leaf of T,
V=2
and w be the parent of v. E=1
v
Let T ’ be the tree T- {v}.
∴|V(T ’)| = k, and |E(T ’)| = k-1 by the induction
hypothesis.
 |E(T)| = k
By induction, the result is true for all trees.
Theorem 3. A full m-ary tree with i internal vertices
contains n = mi + 1 vertices.
Proof. Every vertex, except the root, is the child of an internal vertex.
Each internal vertex has m children.  there are mi +1 vertices in the tree.
if a tree has i=3,m=3,then it has n= mi+1 vertices
i.e, n = 3*3+1=10 vertices

Corollary. A full m-ary tree with n vertices contains (n-1)/m


internal vertices, and hence n - (n-1)/m = ((m-1)n+1)/m leaves.
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.

Example level
0

1
Height of the tree = 4
2
3

4
Def: A rooted m-ary tree of height h is balanced if all
leaves are at levels h or h-1.

Example 11 Which of the rooted trees shown below are balanced?

Sol. T1, T3

Theorem 5. There are atmost mh leaves in an m-ary tree of height h.


Def: A complete m-ary tree is a full m-ary tree, where every leaf
is at the same level.

Ex How many vertices and how many leaves does a complete m-ary
tree of height h have?

Sol.
# of vertices = 1+m+m2+…+mh = (mh+1-1)/(m-1)

# of leaves = mh
Cut-edge, Cut-vertex

 Cut edge(G-e or G-M) : The subgraph obtained by deleting an edge e or set of


edges M.
 Cut vertex(G-v or G-S) : The subgraph obtained by deleting a vertex v or set of
vertices S
 Example:

12 Graph Theory
Cut-edge, Cut-vertex

 A cut-edge or cut-vertex of a graph is an edge or vertex


whose deletion increases the number of components
 Example:

Cut-edge Not a Cut-


vertex

Cut-edge

Cut-vertex

13 Graph Theory
 Trivial Tree: A Tree T with only one vertex ;other wise T is a nontrivial tree .
 Directed Tree: A rooted tree is a directed tree if there is root from which there is a
directed path to each vertex.
 Example:
Properties of Trees:

 A simple non-directed graph G is a tree iff G is connected and


contains no cycles.
 In every non-trivial tree there is atleast one vertex of degree 1.
 A tree with n vertices has exactly n-1 edges.
 If G is a non-trivial tree then G contains atleast 2 vertices of a
degree 1.
 If 2 non adjacent vertices of a tree T are connected by adding b
an edge, then the resulting graph will contain a cycle. a
 A Graph G is a tree if and only if G has no cycles and
│E │= │V│-1. b c
Spanning Trees
Def. 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.
Example: Find a spanning tree of G.

Sol.
Remove an edge from any circuit.
(repeat until no circuit exists)
Four spanning trees of G:

Thm 1 A simple graph G is connected if and only if it has


a spanning tree.
Circuit Rank of G: If G is a connected graph with n vertices and
m edges, a spanning tree of G must have n-1 edges. Hence, the
number of edges that must be removed before a spanning tree is
obtained must be m-(n-1)=m-n+1.This number is called the circuit
rank of G. i
a d f j
e
h
b c g k
No. of vertices(n)=11
No. of edges(m)=15
Circuit rank=m-n+1
=15-11+1=5
i The no. of edges that can be
d f j
a removed to get a spanning tree is 5.
e Therefore the total number of edges
h in the spanning tree is10
b c k
g
Ch10-18
Spanning Trees
Efficient algorithms for finding a spanning tree of a connected
graph.
• Breadth First Search
• Depth First Search
BFS: Visit all the vertices sequentially on a given level before
going onto the next level.
DFS: proceeds successively to higher levels at the first
opportunity.

Ch10-19
Breadth First Search
Algorithm:
Input: A connected graph G with vertices labeled V1,V2,-----Vn.
Output: A spanning tree T for G.
Method:
1.Let V1 be the root of T. Form the set V={v1}.
2.(Add new edges) Consider the vertices of v in order consistent with the
original labelling. Then for each vertex xєV, add the edge {x,vk} to T where k
is the minimum index such that adding the edge {x,vk} to T does not produce
a cycle. If no edge can be added, then stop; T is a spanning tree for G. After
all the vertices of V have been considered in order, go to step3.
3.(Update V) Replace V by all the children v in T of the vertices x of V
where the edges {x,v} were added in step2.Go back and repeat step2 for the
new set v.

Ch10-20
BFS Example:
i
a d f j
e
h
b c g k

Solution:
a d a d a d a d f
e
b b c b c e
b c
g
i
a d f d f j
a
e h e
h
b c b c k
g g

Ch10-21

BFS:
BFS partitions the edges of the graph G into two sets i.e, tree
edges and cross edges.
Tree edges: The edges that were included in the Breadth First
search spanning tree.
Cross edges: The edges that were rejected in the breadth first
search spanning tree.

Theorem: A non-directed graph G is connected if and only if G


contains a spanning tree. Indeed, if we successively delete edges
of cycles until no further cycles remain, then the result is a
spanning tree of G.

Ch10-22
Breadth-First Search (BFS)

Example : Use Breadth-first search to find a spanning tree for the


graph.
Depth First Search
Algorithm:
Input: A connected graph G with vertices labeled V1,V2,-----Vn.
Output: A spanning tree T for G.
Method:
1.(Visit a vertex) Let V1 be the root of T, and set L=V1.(The name ‘L’
stands for the vertex last visited).
2.(Find an unexamined edge and an unvisited vertex adjacent to
L) For all vertices adjacent to L, Choose the edge {L,Vk}, where k is the
minimum index such that adding {L,Vk}to T does not create a cycle. If no
such edge exists, go to step3;otherwise,add edge {L,Vk}, to T and set L=Vk;
repeat step2 at the new value for L.
3.(Backtrack or Terminate) If x is the parent of L in T, set L=x and
apply step2 at the new value of L. If, on the other hand, L has no parent in
T(so that L=V1) then the DFS terminates and T is a spanning tree for G.

Ch10-24
DFS Example:
a d f i j
e
h
b c g k
a d
a a f
a d a d

c e
b
b b c b c b
c e i
j
a d f a d f
a d f h
h
k
b e b c e c e
c g g b g

Ch10-25
DFS:
Tree edges: The edges selected by DFS of a graph.
Back edges: The edges which are rejected in the DFS.

Example:

The tree edges (red)


and back edges (black)
Find the BFS and DFS for the following graphs:

a b c d

e f g

Ch10-27
Minimal Spanning Trees
Let G be the graph of all possible links between the cities with the non negative
cost of construction C(e) assigned to each edge e in G. Then if H is any sub
graph of G with edges e1,e2----,em the total cost of constructing the network H is
C(H)=Σi=1 to m C(ei).
A spanning tree T where C(T) is minimal is called a minimal spanning tree of G.

There are two methods to construct a minimum cost spanning tree


1.Kruskal’s algorithm
2.Prim’s algorithm

Kruskal’s algorithm is an example of a Greedy algorithm that does, lead


to an optimal solution.
Weighted Graph:
It is a graph in which each edge is given a numerical weight.
The weight of an edge is often referred to as the "cost" of the
edge.

Ch10-29
Kruskal’s Algorithm for finding Minimum Cost
Spanning Tree
Input: A connected graph G with non negative values assigned to each edge.
Output: A minimum cost spanning tree for G.
Method:
1.Select any edge of minimal value that is not a loop. This is the first edge of
T.(If there is more than one edge of minimal value, arbitrarily choose one of
these edges).
2.Select any remaining edge of G having minimal value that does not form a
circuit with the edges already included in T.
3.Continue step2 until T contains n-1 edges, where n is the number of vertices
of G.

Ch10-30
Q) For the given graph, find the minimum cost spanning tree using Kruskal’s
algorithm.
Collect the lengths of edges in ascending order.
Edge Cost
{b,c} 3 Add the first edge in
a 15 b {d,f} 4 the spanning tree with
{a,g} 5 the least cost
5 15 3
5 {c,d} 5 a 15 b
g d c {c,e} 5
15 18 4 5 {a,b} 15 5
3
h {a,d} 15 g 5
15 f e {f,h} 15
15 c
{g,h} 15 d
{e,f} 15 4 5
{f,g} 18
h 15 f e

The minimum cost for the construction of the spanning tree is = 3+4+5+5+5+15+15
= 52

Ch10-31
Example: Use Kruskal’s algorithm to find a minimum
spanning tree of G.

Sol.

The minimum cost for the construction of the spanning tree is=24
Find the minimum cost spanning tree for the following
graphs using Kruskal’s algorithm

Ch10-33
Prim’s Algorithm

Prim(G: connected weighted undirected graph with n vertices)


T := a minimum-weight edge
for i := 1 to n2
begin
e := an edge of minimum weight incident to a vertex in T and not
forming a simple circuit in T if added to T
T := T with e added
end {T is a minimum spanning tree of G}

Ch10-34
Prim’s Algorithm
Example:

a b
a 15 b
5 15 3
5 15 3 g
5 d c
g c
d 5
15 18 4 5 15 4
h e h e
15 f 15 f 15

The minimum cost for the construction of the spanning tree is=3+5+15+4+15+5+15
= 62

Ch10-35
Example Use Prim’s algorithm to find a minimum
spanning tree of G.

Sol.

The minimum cost for the construction of the spanning tree is=24

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy