You are on page 1of 30

TREES

A connected graph without circuit or cycle is called a tree.

𝐺1 𝐺3 𝐺5

𝐺2 𝐺4 𝐺6
Terminal Node or Leaf :
That vertex whose degree one is Root

called terminal vertex or leaf.


Internal node or a branch node Internal Node
That vertex whose degree greater than
one is called Internal node or a
branch node. Terminal Node
Root :
A unique path start from that vertex to every other
vertex of tree is called the Root of the tree
Spanning Tree: Let G be a graph. A subgraph G’ of G is
called a spanning subgraph of if G and G’ have same
vertex . G is connected graph then spanning subgraph is
a tree is called spanning tree of G.
The above graph have 6 edges

1 2

4
3
Trees 1,2,3,4,5 are sapping tree of given graph .
2 and 3 are isomorphic trees.
Minimum Spanning Tree : If G is a connected weighted
graph , the spanning tree of G with the ( sum of the
weights of its edges) is called the minimum spanning tree
of G.
Kruskal’s Algorithm:
Step1: Name all the vertices and also list all the edges in
the increasing order of their weights.
Step2: Get the first edge by joining the vertices of mi
nimum weight.
Step 2: Get the second edge by joining the vertices of
next minimum weight.

Step 3: Consider the next minimum weight edge from the


list . If it does not form a cycle with already selected
edges then join the vertices to get the edge. If it forms a
cycle with the already selected edges, reject it.

Step4: repeat the above step till you get a spanning tree .
You have joined all the vertices.
Step1: Name all the vertices
and also list all the edges in the
increasing order of their weights

A
2 6
8 4
E B
6
4 8
7 6
C
D 3
Edge Weight Included in the spanning If not included circuit
tree or not formed
AE 2 YES -
CD 3 YES -
AC 4 YES -
CE 4 NO A-E-C-A
AB 6 YES -
BC 6 NO A-B-C-A
BE 6 - -
DE 7 - -
AD 8 - -
BD 8 - -
Weight 2 is minimum on edge AE , draw it. Next minimum
weight3 on CD, draw it. Again start next minimum weight
4 on edge AC, draw it. Next minimum weight 4 on edge
CE ,that is rejected because A-E-C-A makes a cycle.
Again selected weight 6 on AB ,draw it . All the vertices
have completed and minimum spanning tree constructed.
Total length=2+3+6+4=15
Other Alternating minimum spanning tree of total length
15 whose edges are listed below.
(1)AE,CD,AC,BC (2) AE, CD,AC,BE (3)AE,CD,CE,AB
(4)AE,CD,CE,BC (5)AE,CD,CE,BE
Q . Find the minimum spanning tree of following graph.
(a)

(b)
Kruskal’s algorithim:
First draw the given graph with the weights of the edge.
Step1: list all the edges in decreasing order of costs.
Step2: select the maximum cost and which forms a cycle .
Delete this edge say and get the graph G’-G. If G’ is a tree
the problem is solved . If G’ is a cycle go to the step two.
Step3: again select an edge which has maximum weight in
G’ and which form a cycle in G’. Delete this edge also say
and get the graph G”-G’. If G” is a tree the problem is
solved. If G’’ is not atree repeat the step till you get
Minimum spanning tree.
Q.Find the Minimum spanning tree.

Step1: list all the edges in decreasing order of costs


Edges DF CE BC DE AB AF AD FE DC
weight 6 6 5 4 3 3 2 2 1
Step2: select the maximum cost 6 and which forms a
cycle . Delete this edge say DF, CEand get the graph G’-
GDF,CE.G’ is a cycle go to the next step.

Step3:again select an edge which has maximum weight


5 in G’ BC and which form a cycle in G’. Delete this edge
also BC say and get the graph G”-G’BC. If G” is not a
tree . So go to next step.
Step3:again select an edge which has maximum weight
4 in G’ DE and which form a cycle in G’’. Delete this edge
also DE say and get the graph G”’-G’’DE. If G”’ is a tree
problem is solved
Q.
Prim’s algorithms :
Step 1 : Choose any vertex say v1 as tree root .
Step2 : find edge e1=(v1,v2) in E such that one end vertex
v1 is in tree and its weight is minimum join the v1 to v2.
Step3: select the next edge ei=(vi,vj) such that its one
vertex vi is in tree and other end vertex vj is not in Tree(ej
should not form a circuit) and also the weight of the edge
ej as small as possible. Join the edge ei and the vertex vj
to tree.
Step4 : repeat the step 3 until all the vertices of g are in T
T is required minimum spanning tree.
Q. Find the minimum spanning tree using prims
algorithms .

Step 1:select an arbitrary vertex v1


Step 2: incident edge on v1 is (v1, v2),(v1, v3),(v1, v4) with
weight 2,4,1 min is 2 (v1, v4) draw edge v1 to v4.
𝑣1

𝑣4

Step 3 : incident edge on v4 is (v4, v3)(v4, v6)(v4, v2)(v4, v5)


(v4, v7) with weight 2,8,3,7,4 min is 2 (v4, v3) draw edge v4
to v3
Step3: If we start with v3 then (v3 to v1) makes a cycle and
(v3 to v6) weight is 5 hence if we start with v4 vertex (v4 to
v2) makes a cycle, (v4, v6) weight 8 ,( v4, v3)weight 7,(v4,
v7) weight 4 ,minimum is (v4 to v7) draw it.

Step4: Now start with v7 then (v7,v6) weight 1, (v7, v5)


weight 6 , minimum is (v7,v6) 1 draw it
Step5 :Now start with v7 then (v7, v5) weight 6 draw it.

Total cost=1+2+2+4+1+6=16
Rooted tree: A particular vertex is selected as the root
and every egde is directed away from the root, “so a
directed graph with root is called root tree.

a
a e
x: is the root
d c
d,c: are the leaves
a,e: are internal vertex
a is the parent of d , e is the parent of c
Properties :
(1)In a tree there is one and only one path between every
pair of vertices.
(2)A tree with n vertices has (n-1)edges .

V=2 V=3 V=4 V=5


E=1 E=2 E=3 E=4
Q:A tree has 2n vertices of degree 1, 3n vertices of
degree 2and n vertices of degree 3 ,find the no of
vertices and edges.
Ans.Let tree has n vertices and E edges. By the given
condition tre has n+2n+3n vertices
V=6n
Total no of degrees in tree .
=(2n)1+(3n) 2+(n) 3=11n………………..(1)
acording to the number of edges in a tree is one less
then the number of vertices
E=6n-1
we know that total degree is twice of its edges
=2E=2(6n-1)=12n-2…………………………..(2)
From 1&2 11n=12n-2
n=2 so vertex =2 6=12 edge =11
Binary Tree: A tree in which one and only one vertex has
degree two and the remaining vertices are of degree one or
three is called a binary tree
Q.Construct the tree of [(3)-(2y)]-(z-3)
Ans. The central operator of the whole expression is – so
we have root with – sign. On the left is [(3)-(2y)]. The
central sign is -. On the left of this is the (3) .
The central sign is .On the left of this is the vertex 3.
On the right argument has central sign and its
two offsprings are 2 and y.

In the right argument, the central sign is -. And two


offsprings are z and 3
÷
Preorder: Root-Left-Right ,In order: Left-Root-Right
Post order: Left-Right-Root
Q. Find the order in which the trees are traversed in
preorder, in order, post order.
Ans. To find the pre order, in order, post order fist of all
we introduce two dummy children of each vertex
Start with root vertex draw a parallel line pass from each
vertex if it one time cross the vertex then it comes in pre
order. If comes second time then it comes in In order.
Pre order: a,b,d,c,e,f
In order: b,d,a,e,c,f
Post order : d,b,e,f,c,a

You might also like