MST Algorithm Review - PowerPoint PPT Presentation

Loading...

PPT – MST Algorithm Review PowerPoint presentation | free to download - id: 270ecc-ZDc1Z



Loading


The Adobe Flash plugin is needed to view this content

Get the plugin now

View by Category
About This Presentation
Title:

MST Algorithm Review

Description:

Create a forest of n trees. Loop while (there is 1 tree in the forest) ... Find the smallest edge e = (u,v), in the edge list with u in Ti and v in Tj ... – PowerPoint PPT presentation

Number of Views:33
Avg rating:3.0/5.0
Slides: 63
Provided by: csU73
Learn more at: http://www.cs.ucf.edu
Category:

less

Write a Comment
User Comments (0)
Transcript and Presenter's Notes

Title: MST Algorithm Review


1
MST Algorithm Review
2
Minimal Cost Spanning Trees
  • Minimal Cost Spanning Tree (MST) Problem
  • Input An undirected, connected graph G.
  • Output The subgraph of G that
  • 1) has minimum total cost as measured by summing
    the weight of all the edges in the subset, and
  • 2) keeps the vertices connected.

3
Partition Property
  • Partition Property
  • Consider a partition of the vertices of G into
    subsets U and V
  • Let e be an edge of minimum weight across the
    partition
  • There is a minimum spanning tree of G containing
    edge e

U
V
7
f
4
9
5
2
8
3
8
e
7
4
Prims MST Algorithm
  • As with Dijkstras algorithm, uses a priority
    queue.
  • Running time is identical to Dijkstras algorithm
    implementations.

B
5
A
7
C
6
1
2
9
D
2
F
E
1
5
Prims MST Algorithm
6
Prims MST Algorithm
(?)
(?)
B
Step 1
5
A
7
C
(?)
6
1
2
9
D
2
(?)
F
E
(0)
1
(?)
7
Prims MST Algorithm
(6,F)
(?)
B
Step 2
5
A
7
C
(2,F)
6
1
2
9
D
2
(2,F)
F
E
(0)
1
(1,F)
8
Prims MST Algorithm
(6,F)
(?)
B
Step 3
5
A
7
C
(2,F)
6
1
2
9
D
2
(2,F)
F
E
(0)
1
(1,F)
9
Prims MST Algorithm
(6,F)
(9,E)
B
Step 3a
5
A
7
C
(2,F)
6
1
2
9
D
2
(2,F)
F
E
(0)
1
(1,F)
10
Prims MST Algorithm
(6,F)
(9,E)
B
Step 4
5
A
7
C
(2,F)
6
1
2
9
D
2
(2,F)
F
E
(0)
1
(1,F)
11
Prims MST Algorithm
(5,C)
(7,C)
B
Step 4a
5
A
7
C
(2,F)
6
1
2
9
D
2
(1,C)
F
E
(0)
1
(1,F)
12
Prims MST Algorithm
(5,C)
(7,C)
B
Step 5
5
A
7
C
(2,F)
6
1
2
9
D
2
(1,C)
F
E
(0)
1
(1,F)
13
Prims MST Algorithm
(5,C)
(7,C)
B
Step 5a
5
A
7
C
(2,F)
6
1
2
9
D
2
(1,C)
F
E
(0)
1
(1,F)
14
Prims MST Algorithm
(5,C)
(7,C)
B
Step 6
5
A
7
C
(2,F)
6
1
2
9
D
2
(1,C)
F
E
(0)
1
(1,F)
15
Prims MST Algorithm
(5,C)
(7,C)
B
Step 6a
5
A
7
C
(2,F)
6
1
2
9
D
2
(1,C)
F
E
(0)
1
(1,F)
16
Prims MST Algorithm
(5,C)
(7,C)
B
Step 7
5
A
7
C
(2,F)
6
1
2
9
D
2
(1,C)
F
E
(0)
1
(1,F)
17
Kruskals MST Algorithm
B
5
A
7
C
6
1
2
9
D
2
F
E
1
  • Initially, each vertex is in its own MST.
  • Merge two MSTs that have the shortest edge
    between them.
  • Use a priority queue to order the unprocessed
    edges. Grab the minimum one at each step.
  • How to tell if an edge connects two vertices
    already in the same MST?
  • Use parent-pointer representation.

18
Kruskals MST Algorithm
Step 1
E
D
F
B
C
A
19
Kruskals MST Algorithm
Step 2
B
5
A
E
D
F
B
C
A
7
C
6
1
2
9
D
2
F
E
1
20
Kruskals MST Algorithm
Step 3
B
5
A
E
D
F
B
C
A
7
C
6
1
2
9
D
2
F
E
1
21
Kruskals MST Algorithm
Step 4
B
5
A
E
D
F
B
C
A
7
C
6
1
2
9
D
2
F
E
1
22
Kruskals MST Algorithm
Step 5
B
5
A
E
D
F
B
C
A
7
C
6
1
2
9
D
2
F
E
1
23
Kruskals MST Algorithm
Step 6
B
5
A
E
D
F
B
C
A
7
C
6
1
2
9
D
2
F
E
1
24
Kruskals MST Algorithm
Step 7
B
5
A
E
D
F
B
C
A
7
C
6
1
2
9
D
2
F
E
1
25
Kruskals MST Algorithm
  • Cost is dominated by the time to remove edges
    from the heap.
  • Can stop processing edges once all vertices are
    in the same MST
  • Total cost Q((n m) log m).

26
Baruvkas MST Algorithm
B
5
A
7
C
6
1
2
9
D
2
F
E
1
  • Create a forest of n trees
  • Loop while (there is gt 1 tree in the forest)
  • For each tree Ti in the forest
  • Find the smallest edge e (u,v), in the edge
    list with u in Ti and v in Tj ?Ti
  • connects 2 trees from the forest in to one.
  • end loop

27
Baruvkas MST Algorithm
Step 1
E
D
F
B
C
A
28
Baruvkas MST Algorithm
Step 2
B
5
A
E
D
F
B
C
A
7
C
6
1
2
9
D
2
F
E
1
29
Baruvkas MST Algorithm
Step 3
B
5
A
E
D
F
B
C
A
7
C
6
1
2
9
D
2
F
E
1
30
Baruvkas MST Algorithm
Step 4
B
5
A
E
D
F
B
C
A
7
C
6
1
2
9
D
2
F
E
1
31
Baruvkas MST Algorithm
Step 5
B
5
A
E
D
F
B
C
A
7
C
6
1
2
9
D
2
F
E
1
32
Baruvkas MST Algorithm
Step 6
B
5
A
E
D
F
B
C
A
7
C
6
1
2
9
D
2
F
E
1
33
Baruvkas Algorithm
  • Similar to Kruskals Algorithm, but no Priority
    queueS.
  • Each iteration of the while-loop halves the
    number of connected compontents in T.
  • The running time is O(m log n).

Algorithm BaruvkaMST(G) T ? V just the
vertices of G while T has fewer than n-1 edges
do for each connected component C in T
do Let edge e be the smallest-weight edge from
C to another component in T. if e is not
already in T then Add edge e to T return T
34
Network Flow Problem
35
Flow Network
  • A network N consists of
  • A weighted digraph G with nonnegative integer
    edge weights, where the weight of an edge e is
    called the capacity c(e) of e
  • Two distinguished vertices, s and t of G, called
    the source and sink or target, respectively, such
    that s has no incoming edges and t has no
    outgoing edges.
  • Example

36
Flow
  • A flow f for a network N is an assignment of an
    value f(e) to each edge e that satisfies the
    following properties
  • Capacity Rule For each edge e, 0 ? f (e) ? c(e)

37
Flow
  • A flow f for a network N is an assignment of an
    value f(e) to each edge e that satisfies the
    following properties
  • Capacity Rule For each edge e, 0 ? f (e) ? c(e)
  • Conservation Rule For each vertex v ? s,t

38
Flow
  • The value of a flow f , denoted f, is
  • the total flow from the source
  • which is the same as,
  • the total flow into the sink

39
Maximum Flow
  • A flow for a network N is said to be maximum if
    its value is the largest of all flows for N
  • The maximum flow problem consists of finding a
    maximum flow for a given network N
  • Applications
  • Hydraulic systems
  • Electrical circuits
  • Traffic movements
  • Freight transportation

40
Maximum Flow
v
1/3
2/6
1/1
t
3/7
3/3
s
w
2/9
4/5
1/1
3/5
z
u
2/2
Flow 2 3 3 1 3 4 8
41
A Simple Flow Algorithm
  • Initialize all edges of the flow graph with zero
    flow
  • Loop while ? a path in Gr from s to t
  • find a path in Gr from s to t (augmenting path)
  • Add to the flow graph the minimum residual
    capacity
  • from this path
  • Reduce the residual capacity of the edges
  • end Loop

Flow Graph (Gf)
42
A Simple Flow Algorithm
  • Initialize all edges of the flow graph with zero
    flow
  • Loop while ? a path in Gr from s to t
  • find a path in Gr from s to t (augmenting path)
  • Add to the flow graph the minimum residual
    capacity
  • from this path
  • Reduce the residual capacity of the edges
  • end Loop

Residual Graph (Gr)
Flow Graph (Gf)
43
A Simple Flow Algorithm
  • Initialize all edges of the flow graph with zero
    flow
  • Loop while ? a path in Gr from s to t
  • find a path in Gr from s to t (augmenting path)
  • Add to the flow graph the minimum residual
    capacity
  • from this path
  • Reduce the residual capacity of the edges
  • end Loop

Residual Graph (Gr)
Flow Graph (Gf)
v
3
6
1
t
7
3
s
w
9
5
1
5
z
u
2
44
A Simple Flow Algorithm
  • Initialize all edges of the flow graph with zero
    flow
  • Loop while ? a path in Gr from s to t
  • find a path in Gr from s to t (augmenting path)
  • Add to the flow graph the minimum residual
    capacity
  • from this path
  • Reduce the residual capacity of the edges
  • end Loop

Residual Graph (Gr)
Flow Graph (Gf)
v
3
6
1
t
7
3
s
w
9
3
1
3
z
u
45
A Simple Flow Algorithm
  • Initialize all edges of the flow graph with zero
    flow
  • Loop while ? a path in Gr from s to t
  • find a path in Gr from s to t (augmenting path)
  • Add to the flow graph the minimum residual
    capacity
  • from this path
  • Reduce the residual capacity of the edges
  • end Loop

Residual Graph (Gr)
Flow Graph (Gf)
v
3
6
1
t
7
3
s
w
9
3
1
3
z
u
46
A Simple Flow Algorithm
  • Initialize all edges of the flow graph with zero
    flow
  • Loop while ? a path in Gr from s to t
  • find a path in Gr from s to t (augmenting path)
  • Add to the flow graph the minimum residual
    capacity
  • from this path
  • Reduce the residual capacity of the edges
  • end Loop

Residual Graph (Gr)
Flow Graph (Gf)
v
3
6
1
t
7
s
w
6
1
3
z
u
47
A Simple Flow Algorithm
  • Initialize all edges of the flow graph with zero
    flow
  • Loop while ? a path in Gr from s to t
  • find a path in Gr from s to t (augmenting path)
  • Add to the flow graph the minimum residual
    capacity
  • from this path
  • Reduce the residual capacity of the edges
  • end Loop

Residual Graph (Gr)
Flow Graph (Gf)
v
3
6
1
t
7
s
w
6
1
3
z
u
48
A Simple Flow Algorithm
  • Initialize all edges of the flow graph with zero
    flow
  • Loop while ? a path in Gr from s to t
  • find a path in Gr from s to t (augmenting path)
  • Add to the flow graph the minimum residual
    capacity
  • from this path
  • Reduce the residual capacity of the edges
  • end Loop

Residual Graph (Gr)
Flow Graph (Gf)
v
3
1
t
7
s
w
6
1
3
z
u
49
A Simple Flow Algorithm
  • Initialize all edges of the flow graph with zero
    flow
  • Loop while ? a path in Gr from s to t
  • find a path in Gr from s to t (augmenting path)
  • Add to the flow graph the minimum residual
    capacity
  • from this path
  • Reduce the residual capacity of the edges
  • end Loop

Residual Graph (Gr)
Flow Graph (Gf)
v
3
1
t
7
s
w
6
1
3
z
u
50
A Simple Flow Algorithm
  • Initialize all edges of the flow graph with zero
    flow
  • Loop while ? a path in Gr from s to t
  • find a path in Gr from s to t (augmenting path)
  • Add to the flow graph the minimum residual
    capacity
  • from this path
  • Reduce the residual capacity of the edges
  • end Loop

Residual Graph (Gr)
Flow Graph (Gf)
v
3
1
t
6
s
w
6
2
z
u
51
A Simple Flow Algorithm
  • Initialize all edges of the flow graph with zero
    flow
  • Loop while ? a path in Gr from s to t
  • find a path in Gr from s to t (augmenting path)
  • Add to the flow graph the minimum residual
    capacity
  • from this path
  • Reduce the residual capacity of the edges
  • end Loop

Residual Graph (Gr)
Flow Graph (Gf)
v
3
1
t
6
s
w
6
2
z
u
52
A Simple Flow Algorithm
  • Initialize all edges of the flow graph with zero
    flow
  • Loop while ? a path in Gr from s to t
  • find a path in Gr from s to t (augmenting path)
  • Add to the flow graph the minimum residual
    capacity
  • from this path
  • Reduce the residual capacity of the edges
  • end Loop

Residual Graph (Gr)
Flow Graph (Gf)
v
2
t
5
s
w
6
2
z
u
53
A Simple Flow Algorithm
  • Initialize all edges of the flow graph with zero
    flow
  • Loop while ? a path in Gr from s to t
  • find a path in Gr from s to t (augmenting path)
  • Add to the flow graph the minimum residual
    capacity
  • from this path
  • Reduce the residual capacity of the edges
  • end Loop

Residual Graph (Gr)
Flow Graph (Gf)
/2
2
w
v
w
v
/2
2
/3
3
s
s
/4
4
t
/1
t
1
/2
2
/3
3
z
z
u
u
/3
3
54
A Simple Flow Algorithm
  • Initialize all edges of the flow graph with zero
    flow
  • Loop while ? a path in Gr from s to t
  • find a path in Gr from s to t (augmenting path)
  • Add to the flow graph the minimum residual
    capacity
  • from this path
  • Reduce the residual capacity of the edges
  • end Loop

Residual Graph (Gr)
Flow Graph (Gf)
0/2
2
w
v
w
v
0/2
2
0/3
3
s
s
0/4
4
t
0/1
t
1
0/2
2
0/3
3
z
z
u
u
0/3
3
55
A Simple Flow Algorithm
  • Initialize all edges of the flow graph with zero
    flow
  • Loop while ? a path in Gr from s to t
  • find a path in Gr from s to t (augmenting path)
  • Add to the flow graph the minimum residual
    capacity
  • from this path
  • Reduce the residual capacity of the edges
  • end Loop

Residual Graph (Gr)
Flow Graph (Gf)
0/2
2
w
v
w
v
0/2
2
3/3
s
s
1
3/4
t
0/1
t
1
0/2
2
3/3
z
z
u
u
0/3
3
Algorithm terminates with an sub-optimal flow
solution
56
Ford-Fulkersons Algorithm
  • Initialize all edges of the flow graph with zero
    flow
  • Loop while ? a path in Gr from s to t
  • find a path in Gr from s to t (augmenting path)
  • Add to the flow graph the minimum residual
    capacity
  • from this path
  • Reduce the residual capacity of the edges
  • Add a reversed path in the residual graph
  • end Loop

Residual Graph (Gr)
Flow Graph (Gf)
0/2
2
w
v
w
v
0/2
2
0/3
3
s
s
0/4
4
t
0/1
t
1
0/2
2
0/3
3
z
z
u
u
0/3
3
57
Ford-Fulkersons Algorithm
  • Initialize all edges of the flow graph with zero
    flow
  • Loop while ? a path in Gr from s to t
  • find a path in Gr from s to t (augmenting path)
  • Add to the flow graph the minimum residual
    capacity
  • from this path
  • Reduce the residual capacity of the edges
  • Add a reversed path in the residual graph
  • end Loop

Residual Graph (Gr)
Flow Graph (Gf)
0/2
2
w
v
w
v
0/2
2
3/3
-3
s
s
3/4
1
t
0/1
t
1
-3
0/2
2
3/3
-3
z
z
u
u
0/3
3
58
Ford-Fulkersons Algorithm
  • Initialize all edges of the flow graph with zero
    flow
  • Loop while ? a path in Gr from s to t
  • find a path in Gr from s to t (augmenting path)
  • Add to the flow graph the minimum residual
    capacity
  • from this path
  • Reduce the residual capacity of the edges
  • Add a reversed path in the residual graph
  • end Loop

Residual Graph (Gr)
Flow Graph (Gf)
0/2
2
w
v
w
v
0/2
2
3/3
-3
s
s
3/4
1
t
0/1
t
1
-3
0/2
2
3/3
-3
z
z
u
u
0/3
3
59
Ford-Fulkersons Algorithm
  • Initialize all edges of the flow graph with zero
    flow
  • Loop while ? a path in Gr from s to t
  • find a path in Gr from s to t (augmenting path)
  • Add to the flow graph the minimum residual
    capacity
  • from this path
  • Reduce the residual capacity of the edges
  • Add a reversed path in the residual graph
  • end Loop

Residual Graph (Gr)
Flow Graph (Gf)
2/2
-2
w
v
w
v
2/2
-2
3/3
-3
s
s
1/4
3
t
0/1
t
1
-1
2/2
-2
3/3
-3
-2
z
z
u
u
2/3
1
60
Analysis
  • Each augmenting path increases the flow value by
    at least 1.
  • Let f is a maximum flow, then in the worst
    case, Ford-Fulkersons algorithm performs f
    flow augmentations.
  • Finding an augmenting path and augmenting the
    flow takes O(n m) time
  • The running time of Ford-Fulkersons algorithm is
    O(f(n m))

61
Analysis
v
50
50
Classic worst case example
s
1
t
50
50
u
Flow Graph (Gf)
Residual Graph (Gr)
v
v
50
49
1/50
0/50
-1
s
s
1/1
t
t
-1
-1
49
50
1/50
0/50
u
u
62
Analysis
v
50
50
Classic worst case example
s
1
t
50
50
u
Flow Graph (Gf)
Residual Graph (Gr)
v
v
49
49
1/50
1/50
-1
-1
s
s
1
0/1
t
t
-1
-1
49
49
1/50
1/50
u
u
About PowerShow.com