Download presentation

Presentation is loading. Please wait.

Published byKenia Bolson Modified about 1 year ago

1
Minimum cost spanning tree and activity networks Data structure 2002/12/2

2
Minimum-cost spanning trees (MST) in a given graph (6.3) A minimum-cost spanning tree is a spanning tree of least cost A minimum-cost spanning tree is a spanning tree of least cost Design strategy – greedy method Design strategy – greedy method –Kruskal ’ s algorithm Edge by edge Edge by edge –Prim ’ s algorithm Span out from one vertex Span out from one vertex –Sollin ’ s algorithm Hint: Construct from connected components Hint: Construct from connected components Leave as a homework Leave as a homework

3
An MST example

4
Kruskal ’ s algorithm Edge by edge Edge by edge O(e log e) O(e log e) Algorithm: Algorithm: T={}; While ((T contains less than n-1 edges) &&(E not empty)){ choose an edge (v,w) from E of lowest cost; delete (v,w) from E; if((v,w) does not create a cycle in T) add(v,w) to T; else discard(v,w); } If(T contains fewer than n – 1 edges) printf( “ No spanning tree\n ” );

5
Prim ’ s algorithm Begins from a vertex Begins from a vertex O(n 2 ) O(n 2 ) Algorithm: Algorithm: T={}; TV = {0}; /* start with vertex 0 and no edges */ While (T contains fewer than n-1 edges){ let(u,v) be a least cost edge s.t. u in TV and v not in TV; if (there is no such edge) break; add v to TV; add (u,v) to T; } If (T contains fewer than n-1 edges) printf( “ No spanning tree\n ” );

6
Activity networks (6.5) Definition: Definition: –Vertex i is a predecessor of j Iff there is a directed path from i to j Iff there is a directed path from i to j –Vertex i is an immediate predecessor of j Iff is an edge in G Iff is an edge in G –Successor, immediate successor –Precedence relation, is a partial order relation Transitive Transitive Irreflexive Irreflexive Can be represented by a Directed Acyclic Graph (DAG)? Can be represented by a Directed Acyclic Graph (DAG)? –Topological order is a linear ordering of the vertices of a graph s.t. if i is a predecessor of j, then i precedes j in the linear ordering is a linear ordering of the vertices of a graph s.t. if i is a predecessor of j, then i precedes j in the linear ordering

7
An example of activity network Activity on Vertex networks Activity on Edge networks 計概 資結 邏設 組語計結 OS1 A topological order: 計概, 邏設, 組語, 計結, 資結,OS start finish Earliest time Latest time Critical activites

Similar presentations

© 2016 SlidePlayer.com Inc.

All rights reserved.

Ads by Google