Kruskal MST: initialized the graph and sorted the edges ... · Kruskal MST: initialized the graph...

28
Kruskal MST: initialized the graph and sorted the edges. Disjoint sets: [H] [J] [M] [F] [G] [L] [T] [K] Weight of red edges = = 0 F G 5 H 3 L 3 T 32 J 2 K 7 10 4 23 5 M 1 6 8

Transcript of Kruskal MST: initialized the graph and sorted the edges ... · Kruskal MST: initialized the graph...

Page 1: Kruskal MST: initialized the graph and sorted the edges ... · Kruskal MST: initialized the graph and sorted the edges. Disjoint sets: [H] [J] [M] [F] [G] [L] [T] [K] Weight of red

Kruskal MST: initialized the graph and sorted the edges.Disjoint sets: [H] [J] [M] [F] [G] [L] [T] [K]

Weight of red edges = = 0

F

G

5

H

3

L

3 T

32

J

2

K

710 4

235

M

1

6

8

Page 2: Kruskal MST: initialized the graph and sorted the edges ... · Kruskal MST: initialized the graph and sorted the edges. Disjoint sets: [H] [J] [M] [F] [G] [L] [T] [K] Weight of red

Considering edge (L, M)Disjoint sets: [H] [J] [M] [F] [G] [L] [T] [K]

Weight of red edges = = 0

F

G

5

H

3

L

3 T

32

J

2

K

710 4

235

M

1

6

8

Page 3: Kruskal MST: initialized the graph and sorted the edges ... · Kruskal MST: initialized the graph and sorted the edges. Disjoint sets: [H] [J] [M] [F] [G] [L] [T] [K] Weight of red

Edge (L, M) spans disconnected components: OK.Disjoint sets: [H] [J] [F] [G] [L, M] [T] [K]

Weight of red edges = 1 = 1

F

G

5

H

3

L

3 T

32

J

2

K

710 4

235

M

1

6

8

Page 4: Kruskal MST: initialized the graph and sorted the edges ... · Kruskal MST: initialized the graph and sorted the edges. Disjoint sets: [H] [J] [M] [F] [G] [L] [T] [K] Weight of red

Considering edge (H, J)Disjoint sets: [H] [J] [F] [G] [L, M] [T] [K]

Weight of red edges = 1 = 1

F

G

5

H

3

L

3 T

32

J

2

K

710 4

235

M

1

6

8

Page 5: Kruskal MST: initialized the graph and sorted the edges ... · Kruskal MST: initialized the graph and sorted the edges. Disjoint sets: [H] [J] [M] [F] [G] [L] [T] [K] Weight of red

Edge (H, J) spans disconnected components: OK.Disjoint sets: [H, J] [F] [G] [L, M] [T] [K]

Weight of red edges = 1 + 2 = 3

F

G

5

H

3

L

3 T

32

J

2

K

710 4

235

M

1

6

8

Page 6: Kruskal MST: initialized the graph and sorted the edges ... · Kruskal MST: initialized the graph and sorted the edges. Disjoint sets: [H] [J] [M] [F] [G] [L] [T] [K] Weight of red

Considering edge (F, H)Disjoint sets: [H, J] [F] [G] [L, M] [T] [K]

Weight of red edges = 1 + 2 = 3

F

G

5

H

3

L

3 T

32

J

2

K

710 4

235

M

1

6

8

Page 7: Kruskal MST: initialized the graph and sorted the edges ... · Kruskal MST: initialized the graph and sorted the edges. Disjoint sets: [H] [J] [M] [F] [G] [L] [T] [K] Weight of red

Edge (F, H) spans disconnected components: OK.Disjoint sets: [F, H, J] [G] [L, M] [T] [K]Weight of red edges = 1 + 2 + 3 = 6

F

G

5

H

3

L

3 T

32

J

2

K

710 4

235

M

1

6

8

Page 8: Kruskal MST: initialized the graph and sorted the edges ... · Kruskal MST: initialized the graph and sorted the edges. Disjoint sets: [H] [J] [M] [F] [G] [L] [T] [K] Weight of red

Considering edge (F, L)Disjoint sets: [F, H, J] [G] [L, M] [T] [K]Weight of red edges = 1 + 2 + 3 = 6

F

G

5

H

3

L

3 T

32

J

2

K

710 4

235

M

1

6

8

Page 9: Kruskal MST: initialized the graph and sorted the edges ... · Kruskal MST: initialized the graph and sorted the edges. Disjoint sets: [H] [J] [M] [F] [G] [L] [T] [K] Weight of red

Edge (F, L) spans disconnected components: OK.Disjoint sets: [F, H, J, L, M] [G] [T] [K]

Weight of red edges = 1 + 2 + 3 + 3 = 9

F

G

5

H

3

L

3 T

32

J

2

K

710 4

235

M

1

6

8

Page 10: Kruskal MST: initialized the graph and sorted the edges ... · Kruskal MST: initialized the graph and sorted the edges. Disjoint sets: [H] [J] [M] [F] [G] [L] [T] [K] Weight of red

Considering edge (T, J)Disjoint sets: [F, H, J, L, M] [G] [T] [K]

Weight of red edges = 1 + 2 + 3 + 3 = 9

F

G

5

H

3

L

3 T

32

J

2

K

710 4

235

M

1

6

8

Page 11: Kruskal MST: initialized the graph and sorted the edges ... · Kruskal MST: initialized the graph and sorted the edges. Disjoint sets: [H] [J] [M] [F] [G] [L] [T] [K] Weight of red

Edge (T, J) spans disconnected components: OK.Disjoint sets: [G] [F, H, J, L, M, T] [K]

Weight of red edges = 1 + 2 + 3 + 3 + 4 = 13

F

G

5

H

3

L

3 T

32

J

2

K

710 4

235

M

1

6

8

Page 12: Kruskal MST: initialized the graph and sorted the edges ... · Kruskal MST: initialized the graph and sorted the edges. Disjoint sets: [H] [J] [M] [F] [G] [L] [T] [K] Weight of red

Considering edge (J, L)Disjoint sets: [G] [F, H, J, L, M, T] [K]

Weight of red edges = 1 + 2 + 3 + 3 + 4 = 13

F

G

5

H

3

L

3 T

32

J

2

K

710 4

235

M

1

6

8

Page 13: Kruskal MST: initialized the graph and sorted the edges ... · Kruskal MST: initialized the graph and sorted the edges. Disjoint sets: [H] [J] [M] [F] [G] [L] [T] [K] Weight of red

Edge (J, L) would introduce a cycle. Forget it.Disjoint sets: [G] [F, H, J, L, M, T] [K]

Weight of red edges = 1 + 2 + 3 + 3 + 4 = 13

F

G

5

H

3

L

3 T

32

J

2

K

710 4

235

M

1

6

8

Page 14: Kruskal MST: initialized the graph and sorted the edges ... · Kruskal MST: initialized the graph and sorted the edges. Disjoint sets: [H] [J] [M] [F] [G] [L] [T] [K] Weight of red

Considering edge (F, G)Disjoint sets: [G] [F, H, J, L, M, T] [K]

Weight of red edges = 1 + 2 + 3 + 3 + 4 = 13

F

G

5

H

3

L

3 T

32

J

2

K

710 4

235

M

1

6

8

Page 15: Kruskal MST: initialized the graph and sorted the edges ... · Kruskal MST: initialized the graph and sorted the edges. Disjoint sets: [H] [J] [M] [F] [G] [L] [T] [K] Weight of red

Edge (F, G) spans disconnected components: OK.Disjoint sets: [F, G, H, J, L, M, T] [K]

Weight of red edges = 1 + 2 + 3 + 3 + 4 + 5 = 18

F

G

5

H

3

L

3 T

32

J

2

K

710 4

235

M

1

6

8

Page 16: Kruskal MST: initialized the graph and sorted the edges ... · Kruskal MST: initialized the graph and sorted the edges. Disjoint sets: [H] [J] [M] [F] [G] [L] [T] [K] Weight of red

Considering edge (M, H)Disjoint sets: [F, G, H, J, L, M, T] [K]

Weight of red edges = 1 + 2 + 3 + 3 + 4 + 5 = 18

F

G

5

H

3

L

3 T

32

J

2

K

710 4

235

M

1

6

8

Page 17: Kruskal MST: initialized the graph and sorted the edges ... · Kruskal MST: initialized the graph and sorted the edges. Disjoint sets: [H] [J] [M] [F] [G] [L] [T] [K] Weight of red

Edge (M, H) would introduce a cycle. Forget it.Disjoint sets: [F, G, H, J, L, M, T] [K]

Weight of red edges = 1 + 2 + 3 + 3 + 4 + 5 = 18

F

G

5

H

3

L

3 T

32

J

2

K

710 4

235

M

1

6

8

Page 18: Kruskal MST: initialized the graph and sorted the edges ... · Kruskal MST: initialized the graph and sorted the edges. Disjoint sets: [H] [J] [M] [F] [G] [L] [T] [K] Weight of red

Considering edge (H, K)Disjoint sets: [F, G, H, J, L, M, T] [K]

Weight of red edges = 1 + 2 + 3 + 3 + 4 + 5 = 18

F

G

5

H

3

L

3 T

32

J

2

K

710 4

235

M

1

6

8

Page 19: Kruskal MST: initialized the graph and sorted the edges ... · Kruskal MST: initialized the graph and sorted the edges. Disjoint sets: [H] [J] [M] [F] [G] [L] [T] [K] Weight of red

Edge (H, K) spans disconnected components: OK.Disjoint sets: [F, G, H, J, K, L, M, T]

Weight of red edges = 1 + 2 + 3 + 3 + 4 + 5 + 7 = 25

F

G

5

H

3

L

3 T

32

J

2

K

710 4

235

M

1

6

8

Page 20: Kruskal MST: initialized the graph and sorted the edges ... · Kruskal MST: initialized the graph and sorted the edges. Disjoint sets: [H] [J] [M] [F] [G] [L] [T] [K] Weight of red

Considering edge (M, T)Disjoint sets: [F, G, H, J, K, L, M, T]

Weight of red edges = 1 + 2 + 3 + 3 + 4 + 5 + 7 = 25

F

G

5

H

3

L

3 T

32

J

2

K

710 4

235

M

1

6

8

Page 21: Kruskal MST: initialized the graph and sorted the edges ... · Kruskal MST: initialized the graph and sorted the edges. Disjoint sets: [H] [J] [M] [F] [G] [L] [T] [K] Weight of red

Edge (M, T) would introduce a cycle. Forget it.Disjoint sets: [F, G, H, J, K, L, M, T]

Weight of red edges = 1 + 2 + 3 + 3 + 4 + 5 + 7 = 25

F

G

5

H

3

L

3 T

32

J

2

K

710 4

235

M

1

6

8

Page 22: Kruskal MST: initialized the graph and sorted the edges ... · Kruskal MST: initialized the graph and sorted the edges. Disjoint sets: [H] [J] [M] [F] [G] [L] [T] [K] Weight of red

Considering edge (T, G)Disjoint sets: [F, G, H, J, K, L, M, T]

Weight of red edges = 1 + 2 + 3 + 3 + 4 + 5 + 7 = 25

F

G

5

H

3

L

3 T

32

J

2

K

710 4

235

M

1

6

8

Page 23: Kruskal MST: initialized the graph and sorted the edges ... · Kruskal MST: initialized the graph and sorted the edges. Disjoint sets: [H] [J] [M] [F] [G] [L] [T] [K] Weight of red

Edge (T, G) would introduce a cycle. Forget it.Disjoint sets: [F, G, H, J, K, L, M, T]

Weight of red edges = 1 + 2 + 3 + 3 + 4 + 5 + 7 = 25

F

G

5

H

3

L

3 T

32

J

2

K

710 4

235

M

1

6

8

Page 24: Kruskal MST: initialized the graph and sorted the edges ... · Kruskal MST: initialized the graph and sorted the edges. Disjoint sets: [H] [J] [M] [F] [G] [L] [T] [K] Weight of red

Considering edge (J, K)Disjoint sets: [F, G, H, J, K, L, M, T]

Weight of red edges = 1 + 2 + 3 + 3 + 4 + 5 + 7 = 25

F

G

5

H

3

L

3 T

32

J

2

K

710 4

235

M

1

6

8

Page 25: Kruskal MST: initialized the graph and sorted the edges ... · Kruskal MST: initialized the graph and sorted the edges. Disjoint sets: [H] [J] [M] [F] [G] [L] [T] [K] Weight of red

Edge (J, K) would introduce a cycle. Forget it.Disjoint sets: [F, G, H, J, K, L, M, T]

Weight of red edges = 1 + 2 + 3 + 3 + 4 + 5 + 7 = 25

F

G

5

H

3

L

3 T

32

J

2

K

710 4

235

M

1

6

8

Page 26: Kruskal MST: initialized the graph and sorted the edges ... · Kruskal MST: initialized the graph and sorted the edges. Disjoint sets: [H] [J] [M] [F] [G] [L] [T] [K] Weight of red

Considering edge (H, T)Disjoint sets: [F, G, H, J, K, L, M, T]

Weight of red edges = 1 + 2 + 3 + 3 + 4 + 5 + 7 = 25

F

G

5

H

3

L

3 T

32

J

2

K

710 4

235

M

1

6

8

Page 27: Kruskal MST: initialized the graph and sorted the edges ... · Kruskal MST: initialized the graph and sorted the edges. Disjoint sets: [H] [J] [M] [F] [G] [L] [T] [K] Weight of red

Edge (H, T) would introduce a cycle. Forget it.Disjoint sets: [F, G, H, J, K, L, M, T]

Weight of red edges = 1 + 2 + 3 + 3 + 4 + 5 + 7 = 25

F

G

5

H

3

L

3 T

32

J

2

K

710 4

235

M

1

6

8

Page 28: Kruskal MST: initialized the graph and sorted the edges ... · Kruskal MST: initialized the graph and sorted the edges. Disjoint sets: [H] [J] [M] [F] [G] [L] [T] [K] Weight of red

Kruskal minimum spanning treeGenerated by $Id: kruskal.py 90 2010-11-16 01:33:02Z fms27 $

(c) 2006-2010 Frank StajanoUniversity of Cambridge Computer Laboratory