Docsity

Minimum Spanning Tree - Data Structures - Lecture Slides, Slides of Data Structures and Algorithms

Partial preview of the text

Download Minimum Spanning Tree - Data Structures - Lecture Slides and more Slides Data Structures and Algorithms in PDF only on Docsity!

Minimum Spanning Tree

A spanning tree of a graph is just a subgraph that

contains all the vertices and is a tree.

A graph may have many spanning trees.

or or or

Graph A Some Spanning Trees from Graph A

Spanning Trees

Minimum Spanning Trees

The Minimum Spanning Tree for a given graph is the Spanning Tree of

minimum cost for that graph.

Complete Graph Minimum Spanning Tree

Algorithms for Obtaining the Minimum Spanning Tree

  • Kruskal's Algorithm
  • Prim's Algorithm
  • Boruvka's Algorithm

The steps are:

  1. The forest is constructed - with each node in a separate tree.
  2. The edges are placed in a priority queue.
  3. Until we've added n-1 edges,
    1. Extract the cheapest edge from the queue,
    2. If it forms a cycle, reject it,
    3. Else add it to the forest. Adding it to the forest will join two

trees together.

Every step will have joined two trees in the forest together, so that at

the end, there will only be one tree in T.

A

B C

D

E

F

G

H

I

J

Complete Graph

A

B C

D

E

F

G

H

I

J

B

B

D

J

C

C

E

F

D

D H

J

E G

F

F

G

I

G

G

I

J

H J

I J

A D

B C

A B

Sort Edges

(in reality they are placed in a priority

queue - not sorted - but sorting them

makes the algorithm easier to visualize)

A

B C

D

E

F

G

H

I

J

B

B

D

J

C

C

E

F

D

D H

J

E G

F

F

G

I

G

G

I

J

H J

I J

A D

B C

A B

Add Edge

A

B C

D

E

F

G

H

I

J

B

B

D

J

C

C

E

F

D

D H

J

E G

F

F

G

I

G

G

I

J

H J

I J

A D

B C

A B

Add Edge

A

B C

D

E

F

G

H

I

J

B

B

D

J

C

C

E

F

D

D H

J

E G

F

F

G

I

G

G

I

J

H J

I J

A D

B C

A B

Add Edge

A

B C

D

E

F

G

H

I

J

B

B

D

J

C

C

E

F

D

D H

J

E G

F

F

G

I

G

G

I

J

H J

I J

A D

B C

A B

Cycle

Don’t Add Edge

A

B C

D

E

F

G

H

I

J

B

B

D

J

C

C

E

F

D

D H

J

E G

F

F

G

I

G

G

I

J

H J

I J

A D

B C

A B

Add Edge

A

B C

D

E

F

G

H

I

J

B

B

D

J

C

C

E

F

D

D H

J

E G

F

F

G

I

G

G

I

J

H J

I J

A D

B C

A B

Add Edge

A

B C

D

E

F

G

H

I

J

B

B

D

J

C

C

E

F

D

D H

J

E G

F

F

G

I

G

G

I

J

H J

I J

A D

B C

A B

Cycle

Don’t Add Edge