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

chapitre 4 - Tree and Spanning Tree Problem

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

chapitre 4 - Tree and Spanning Tree Problem

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

1

2
3


4

G1 G2 G3

Figure 1 : Three Trees examples


5


6

Figure 2 : A forest example.


7


8

(a) Graph G. (b) a spanning tree of G


Figure 3 : a graph and an example spanning tree.
9
10


11
12

  2  

 G,p
13

Figure4 : Example of weighted graphs.


14
15
16
17

Figure 5 : Weighted graph .

Figure 6 : Tow MST of G.


18

T
19

*

20
21

Algorithm Kruskal
Inputs: A connected graph G=(V,E)with weights p(e)on the edges.
Outputs: A spanning tree T of G with minimum weight.
X : a subset of E;
Sort the edges of E={e1,..., em} in ascending order of their weights;
X  ;
i 1; P(T) 0 ;
While |X| < |V|-1 do
If (V, X{ei}) is acyclic then
X  X {ei} ;
P(T) P(T)+P(ei) ;
EndIf
i i + 1;
EndWhile
Return T=(V, X); P(T) ;
End.
22

1 2 3 4 5 6 7 8

i
23


 
 1    1  
 2    2  
 3    3  
 4 
 5 
 6 
 7    7  
1 2 3 7  
24

(a) (b)

Figure 7 : a graph and a corresponding MSP.


25
26

Algorithm Prim
Inputs: A connected graph G=(V,E)with weights p(e)on the edges.
Outputs: A spanning tree T of G with minimum weight.
X : a subset of E;
Choose an initial vertex a;
S {a} ; P(T) 0 ;
X  ;
While S ≠ V do
Choose an edge uv E such that u S and v V S, with P(uv) being the
minimum.
X  X {uv} ;
P(T) P(T)+P(uv) ;
S S{v} ;
EndWhile
Return T=(S, X); P(T) ;
End.
27

(a) Weighted graph G=(V,E) (b) MST of the graph G

Figure 8 : Graph G and its MST.


28

  
 
 
 
 
 

You might also like