kruskal’s algorithm

25

Upload: abdul-moiz-lakhani

Post on 21-Feb-2017

8 views

Category:

Education


0 download

TRANSCRIPT

Page 1: Kruskal’s algorithm
Page 2: Kruskal’s algorithm

BENAZIR BHUTTO SHAHEED UNVERSITY

Department of Computer Science

Under the guidance of:Sir Ali Aurangzeb

Page 3: Kruskal’s algorithm

Kruskal’s Algorithm

PRESENTED BY:ABDUL MOIZ KHATRI

3rd SEMESTER – Batch 6th

BECHALORS OF COMPUTER SCIENCE

PRESENTATION ON:

Page 4: Kruskal’s algorithm

JOSEPH KRUSKAL• Joseph Kruskal was an American Mathematician, Statistician and Computer Scientist.• He was born in January 29, 1928.• He was a student at the University of Chicago earning a Bachelor of Science in Mathematics in the year of 1948 and a Master of Science in Mathematics in the following year 1949.• After his time at the University of Chicago, Kruskal attended Princeton University, where he completed his Ph.D. in Mathematics in the year of 1954.• In Statistics, Kruskal's most influential work is his seminal contribution to the

formulation of Multidimensional Scaling.• In Computer Science, his best known work is Kruskal's Algorithm for computing

the Minimal Spanning Tree (MST) of a weighted graph.• He died in September 19, 2010.

Page 5: Kruskal’s algorithm

WHAT IS AN ALGORITHM?

An Algorithm is a step-by-step procedure to solve a given problem.

Page 6: Kruskal’s algorithm

KRUSKAL’S ALGORITHM

Page 7: Kruskal’s algorithm

Kruskal's Algorithm is an Algorithm for Computing the Minimal Spanning

Tree (MST) of a Weighted Graph.

KRUSKAL’S ALGORITHM

A Minimal Spanning Tree is a Spanning Tree of a connected, undirected graph which connects all the vertices together with the Minimal total weightage for its edges and it always have V-1

Edges.

A

B

C

D1 32

Page 8: Kruskal’s algorithm

Kruskal's Algorithm is an Algorithm for Computing the Minimal Spanning

Tree (MST) of a Weighted Graph.

KRUSKAL’S ALGORITHM

A weighted graph is a graph whose vertices or edges

have been assigned weights.

A

B

C

D

1 32

2

5

Page 9: Kruskal’s algorithm

LETS SEE A GRAPH…!

A

B

C

D

1 32

2

5VerticesEdge

Weight of an Edge

Page 10: Kruskal’s algorithm

HOW TO FIND MINIMAL SPANNING TREE (MST) BY USING KRUSKAL’S ALGORITHM?

We will always start from the smallest weight edge and keep selecting edges that does not

form any circuit with the previously selected edges.

REMEMBER….

Page 11: Kruskal’s algorithm

A

B

C

D

1 32

2

5

We will always start from the smallest weight edge and keep selecting edges that does not form any circuit with the previously selected edges.

We have 5 edges.So our edge table will have 5 columns.Create the edge table.

(An edge table will have name of all the edges along with their

weight in ascending order)

Edge

Weight

STEPS TO FIND MINIMAL SPANNING TREE (MST) BY USING KRUSKAL’S ALGORITHM

Page 12: Kruskal’s algorithm

Edge

Weight

Page 13: Kruskal’s algorithm

A

B

C

D

1 32

2

5

We will always start from the smallest weight edge and keep selecting edges that does not form any circuit with the previously selected edges.

Edge

Weight

Now look at the graph and fill the 1st column with the edge of minimum weight.

In this case edge BC is of least weight so we will select it.

BC

1

Now look at the graph again and find the edge of next minimum weight.

In this case edge AB and AC are having the minimum weight so we will select them both.

Note! In case we have two or more edges with same weight then we can write them in any order in the edge table.

AB

2

AC

2

Page 14: Kruskal’s algorithm

A

B

C

D

1 32

2

5

We will always start from the smallest weight edge and keep selecting edges that does not form any circuit with the previously selected edges.

Edge

WeightBC

1

Now look at the graph again and find the edge of next minimum weight.

In this case edge AB and AC are having the minimum weight so we will select them both.

Note! In case we have two or more edges with same weight then we can write them in any order in the edge table.

AB

2

AC

2

Page 15: Kruskal’s algorithm

A

B

C

D

1 32

2

5

We will always start from the smallest weight edge and keep selecting edges that does not form any circuit with the previously selected edges.

Edge

WeightBC

1

AB

2

AC

2

Now look at the graph again and find the edge of next minimum edge.

In this case edge DC has the minimum weight so we will select it.

DC

2

Now look at the graph again and find the edge of next minimum edge.

In this case edge BD has the minimum weight so we will select it.

BD

5

Page 16: Kruskal’s algorithm

A

B

C

D

1 32

2

5

We will always start from the smallest weight edge and keep selecting edges that does not form any circuit with the previously selected edges.

TIME TO FIND MINIMAL SPANNING TREE (MST) BY USING KRUSKAL’S ALGORITHM

Edge

WeightBC

1

AB

2

AC

2

DC

2

BD

5

Note! Our graph has 4 vertices.So, our MST will have 3 edges.

Page 17: Kruskal’s algorithm

We will always start from the smallest weight edge and keep selecting edges that does not form any circuit with the previously selected edges.

TIME TO FIND MINIMAL SPANNING TREE (MST) BY USING KRUSKAL’S ALGORITHM

Edge

WeightBC

1

AB

2

AC

2

DC

2

BD

5

1 is the smallest weight.So we will select edge BC. B

C

1

A

B

C

D

1 32

2

5

Page 18: Kruskal’s algorithm

A

2

A

B

C

D

1 32

2

5

We will always start from the smallest weight edge and keep selecting edges that does not form any circuit with the previously selected edges.

TIME TO FIND MINIMAL SPANNING TREE (MST) BY USING KRUSKAL’S ALGORITHM

Edge

WeightBC

1

AB

2

AC

2

DC

2

BD

5

2 is the next smallest weight and edge AB does not form a circuit with the previously selected edges.

So we will select it.

B

C

1

Page 19: Kruskal’s algorithm

A

2

A

B

C

D

1 32

2

5

We will always start from the smallest weight edge and keep selecting edges that does not form any circuit with the previously selected edges.

TIME TO FIND MINIMAL SPANNING TREE (MST) BY USING KRUSKAL’S ALGORITHM

Edge

WeightBC

1

AB

2

AC

2

DC

2

BD

5

2 is the smallest weight.But if we select edge AC

then it will form a circuit. Sowe are going to reject edge AC.

B

C

1

Page 20: Kruskal’s algorithm

D

3

A

2

A

B

C

D

1 32

2

5

We will always start from the smallest weight edge and keep selecting edges that does not form any circuit with the previously selected edges.

TIME TO FIND MINIMAL SPANNING TREE (MST) BY USING KRUSKAL’S ALGORITHM

Edge

WeightBC

1

AB

2

AC

2

DC

2

BD

5

3 is the next smallest weight andedge DC does not form a circuit

with the previously selected edges. So we will select it.

B

C

1

Page 21: Kruskal’s algorithm

D

3

A

2

A

B

C

D

1 32

2

5

We will always start from the smallest weight edge and keep selecting edges that does not form any circuit with the previously selected edges.

TIME TO FIND MINIMAL SPANNING TREE (MST) BY USING KRUSKAL’S ALGORITHM

Edge

WeightBC

1

AB

2

AC

2

DC

2

BD

5

3 is the next smallest weight andedge DC does not form a circuit

with the previously selected edges. So we will select it.

B

C

1

Page 22: Kruskal’s algorithm

D

3

A

2

A

B

C

D

1 32

2

5

We will always start from the smallest weight edge and keep selecting edges that does not form any circuit with the previously selected edges.

TIME TO FIND MINIMAL SPANNING TREE (MST) BY USING KRUSKAL’S ALGORITHM

Edge

WeightBC

1

AB

2

AC

2

DC

2

BD

5

B

C

1

Since we have got the 3 edges.So we will stop here.

Page 23: Kruskal’s algorithm

THEREFORE, OUR REQUIRED MINIMUM SPANNING TREE IS

D

3

A

2

B

C

1

Page 24: Kruskal’s algorithm

QUERIES SESSION

Page 25: Kruskal’s algorithm

THANKS ALOT…..