Minimum spanning trees Kruskals algorithm April 01 2020

  • Slides: 11
Download presentation
Minimum spanning trees Kruskal’s algorithm April 01, 2020 Cinda Heeren / Andy Roth /

Minimum spanning trees Kruskal’s algorithm April 01, 2020 Cinda Heeren / Andy Roth / Geoffrey Tien 1

Announcements • HW 3 released, due 23: 59, Thursday Apr. 09 – Several errors

Announcements • HW 3 released, due 23: 59, Thursday Apr. 09 – Several errors found and corrected already, check Piazza April 01, 2020 Cinda Heeren / Andy Roth / Geoffrey Tien 2

Spanning trees • d c b d c h a d c i b

Spanning trees • d c b d c h a d c i b h Cinda Heeren / Andy Roth / Geoffrey Tien e g f a April 01, 2020 i g f h b a e e i Spanning trees 3

Minimum spanning trees The supreme ruler of Boolesville is a cheapskate • Problem: installing

Minimum spanning trees The supreme ruler of Boolesville is a cheapskate • Problem: installing power lines in Boolesville to supply all the residential/commercial/etc. districts – but it costs $5 per unit distance to construct the power line – Find a configuration of minimal cost that connects all the districts – This is a minimal spanning tree April 01, 2020 Cinda Heeren / Andy Roth / Geoffrey Tien 4

Minimal spanning tree Algorithmic requirements • A B A 8 2 4 7 C

Minimal spanning tree Algorithmic requirements • A B A 8 2 4 7 C 1 2 3 E 9 4 D 5 F A C B 2 D 1 3 E 2 5 F Weight = 15 April 01, 2020 Cinda Heeren / Andy Roth / Geoffrey Tien C B 2 3 E D 1 5 F Weight = 13 5

Kruskal's algorithm for minimum spanning trees • April 01, 2020 Cinda Heeren / Andy

Kruskal's algorithm for minimum spanning trees • April 01, 2020 Cinda Heeren / Andy Roth / Geoffrey Tien 6

Kruskal's algorithm Data types for implementation • We need ADTs that support our required

Kruskal's algorithm Data types for implementation • We need ADTs that support our required operations efficiently • How do we find the minimum weight edge? – Priority queue! • How can we check for cycles and perform union? – Disjoint sets! April 01, 2020 Cinda Heeren / Andy Roth / Geoffrey Tien 7

Kruskal's algorithm Example A B 2 6 16 3 C 8 D 7 17

Kruskal's algorithm Example A B 2 6 16 3 C 8 D 7 17 E 13 12 9 5 F G 16 11 10 4 13 A H E B C F pr. Q cost pr. Q MST weight: 38 heap D G H ordered array build Overall cost? remove. Min Note that no insertions performed after build April 01, 2020 Note: only one edge direction listed in pr. Q for compactness in this slide Cinda Heeren / Andy Roth / Geoffrey Tien 8

A slight tangent – maze construction What makes a good maze? • A bunch

A slight tangent – maze construction What makes a good maze? • A bunch of adjacent rooms – Each room is a vertex – Open wall between rooms form edge in – Unpredictable, not easily solved – Highly branching, many dead ends – Just enough walls to get from any room to any other room • Especially start and finish April 01, 2020 Cinda Heeren / Andy Roth / Geoffrey Tien out 9

Maze under construction • So far, a number of walls have been knocked down,

Maze under construction • So far, a number of walls have been knocked down, while others remain • Now we consider the wall between rooms A and B – Should we knock it down? • If A and B are otherwise connected • If A and B are not otherwise connected A B This is a lot like Kruskal's algorithm! Solve it using disjoint sets and random edge selection April 01, 2020 Cinda Heeren / Andy Roth / Geoffrey Tien 10

Readings for this lesson • Carrano & Henry – Chapters 20. 4. 2 –

Readings for this lesson • Carrano & Henry – Chapters 20. 4. 2 – 20. 4. 3 (Spanning trees, minimum spanning trees) • Next class: – Minimum spanning trees, continued April 01, 2020 Cinda Heeren / Andy Roth / Geoffrey Tien 11