chapter23.ppt

16
Introduction to Algorithms Second Edition by Cormen, Leiserson, Rivest & Stein Chapter 23

Upload: tareq-hasan

Post on 10-May-2015

1.245 views

Category:

Documents


3 download

TRANSCRIPT

Page 1: chapter23.ppt

Introduction to AlgorithmsSecond Edition

byCormen, Leiserson, Rivest & Stein

Chapter 23

Page 2: chapter23.ppt

Minimum Spanning Tree

We then wish to find an acyclic subset T є E that connects all of the vertices and whose total weight is minimized.

Page 3: chapter23.ppt

Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.

Page 4: chapter23.ppt

Minimum Spanning Tree

Assume that we have a connected, undirected graph G = (V, E) with a weight function w : E → R, and we wish to find a minimum spanning tree for G.

At each step, we determine an edge (u, v) that can be added to A without violating this invariant, in the sense that A U {(u, v)} is also a subset of a minimum spanning tree.

Page 5: chapter23.ppt

Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.

Page 6: chapter23.ppt

Minimum Spanning Tree

A cut (S, V - S) of an undirected graph G = (V, E) is a partition of V.

We say that an edge (u, v) ε E crosses the cut (S, V - S) if one of its endpoints is in S and the other is in V - S.

Page 7: chapter23.ppt

Minimum Spanning Tree

We say that a cut respects a set A of edges if no edge in A crosses the cut.

An edge is a light edge crossing a cut if itsweight is the minimum of any edge crossing the cut.

Page 8: chapter23.ppt

Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.

Page 9: chapter23.ppt

Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.

Page 10: chapter23.ppt

Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.

Page 11: chapter23.ppt

Minimum Spanning Tree

It finds a safe edge to add to the growing forest by finding, of all the edges that connect any two trees in the forest, an edge (u, v) of least weight.

Page 12: chapter23.ppt

Kruskal’s Algorithm

It uses a disjoint-set data structure to maintain several disjointsets of elements. Each set contains the vertices in a tree of the current forest. The operation FIND-SET(u) returns a representative element from the set that contains u. Thus, we can determine whether two vertices u and v belong to the same tree by testing whether FIND-SET(u) equals FIND-SET(v). The combining of trees is accomplished by the UNIONprocedure.

Page 13: chapter23.ppt

Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.

Page 14: chapter23.ppt

Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.

Page 15: chapter23.ppt

Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.

Page 16: chapter23.ppt

Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.