application of greedy method prim

40
Application of greedy method: Prim’s Algorithm

Upload: techmx

Post on 14-Jun-2015

1.464 views

Category:

Technology


1 download

TRANSCRIPT

Page 1: Application of greedy method prim

Application of greedy method: Prim’s Algorithm

Page 2: Application of greedy method prim

Greedy Method ???

A greedy method is an method that follows the problem solving technique of making the locally optimal choice at each stage with the hope of finding a global optimum. 

Page 3: Application of greedy method prim

Prim’s Algorithm

Prim's algorithm is a greedy algorithm that finds a minimum spanning tree for a connected weighted undirected graph. This means it finds a subset of the edges that forms a tree that includes every vertex, where the total weight of all the edges in the tree is minimized.

Page 4: Application of greedy method prim

Spanning Tree ???

A spanning tree of a connected graph G can be defined as a maximal set of edges of G that contains no cycle, or as a minimal set of edges that connect all vertices.

Page 5: Application of greedy method prim
Page 6: Application of greedy method prim

Minimum Spanning Tree ???

• it is a tree (i.e., it is acyclic)• it covers all the vertices V

– contains |V| - 1 edges

• the total cost associated with tree edges is the minimum among all possible spanning trees

• not necessarily unique

A minimum spanning tree is a subgraph of an undirected weighted graph G, such that

Page 7: Application of greedy method prim
Page 8: Application of greedy method prim

Algorithm

Page 9: Application of greedy method prim
Page 10: Application of greedy method prim
Page 11: Application of greedy method prim

Example 1

Page 12: Application of greedy method prim

C

FE

A B

D

5

64

3

4

2

1 2

3

2

Page 13: Application of greedy method prim

C

FE

A B

D

5

64

3

4

2

1 2

3

2

Page 14: Application of greedy method prim

C

FE

A B

D

5

64

3

4

2

1 2

3

2

Page 15: Application of greedy method prim

C

FE

A B

D

5

64

3

4

2

1 2

3

2

Page 16: Application of greedy method prim

C

FE

A B

D

3

4

2

1 2

3

2

Page 17: Application of greedy method prim

C

FE

A B

D

3

2

1 2

3

2

Page 18: Application of greedy method prim

C

FE

A B

D

3

2

1 2

2

3

Page 19: Application of greedy method prim

C

FE

A B

D

3

2

1 2

2

Page 20: Application of greedy method prim

C

FE

A B

D

3

2

1 2

2

Page 21: Application of greedy method prim

C

FE

A B

D

3

2

1 2

2

minimum- spanning tree

Page 22: Application of greedy method prim

Example 2

Page 23: Application of greedy method prim

Prim’s Algorithm

a

ce

d

b2

45

9

6

4

5

5

Page 24: Application of greedy method prim

Prim’s algorithm

a

ce

d

b2

45

9

6

4

5

5

The MST initially consists of the vertex e

Page 25: Application of greedy method prim

Prim’s algorithm

a

ce

d

b2

45

9

6

4

5

5

Page 26: Application of greedy method prim

Prim’s algorithm

a

ce

d

b2

45

9

6

4

5

5

Page 27: Application of greedy method prim

Prim’s algorithm

a

ce

d

b2

45

9

6

4

5

5

Page 28: Application of greedy method prim

Prim’s algorithm

a

ce

d

b2

45

9

6

4

5

5

The final minimum spanning tree

Page 29: Application of greedy method prim

Example 3

Page 30: Application of greedy method prim
Page 31: Application of greedy method prim
Page 32: Application of greedy method prim
Page 33: Application of greedy method prim
Page 34: Application of greedy method prim
Page 35: Application of greedy method prim
Page 36: Application of greedy method prim

Weight (T) = 23 + 29 + 31 + 32 + 47 + 54 + 66 = 282

Page 37: Application of greedy method prim

Problem: Laying Telephone Wire

Central office

Page 38: Application of greedy method prim

Wiring: Normal Approach

Central office

Expensive!

Page 39: Application of greedy method prim

Wiring: Better Approach

Central office

Minimize the total length of wire connecting the customers

Page 40: Application of greedy method prim

Thank You