Graphs:Minimum Spanning Trees
and Maximum Flows
Jordi Cortadella and Jordi Petit
Department of Computer Science
Minimum Spanning Trees
Graphs: MST and Max Flow ยฉ Dept. CS, UPC 2
A
B
C
D
E
F
1
43 4
4
2 4 5
6
Nodes are computers Edges are links Weights are maintenance cost Goal: pick a subset of edges such that
โข the nodes are connectedโข the maintenance cost is minimum
A
B
C
D
E
F
1
4
2 4 5
The solution is not unique.Find another one !
Property:An optimal solution cannot contain a cycle.
Minimum Spanning Treeโข Given un undirected graph ๐บ = (๐, ๐ธ) with edge weights ๐ค๐, find a tree ๐ = (๐, ๐ธโฒ), with ๐ธโฒ โ ๐ธ, that minimizes
weight ๐ =
๐โ๐ธโฒ
๐ค๐ .
โข Greedy algorithm: repeatedly add the next lightest edge that does not produce a cycle.
Graphs: MST and Max Flow ยฉ Dept. CS, UPC 3
A
B
C
D
E
F
6
54 1
2
2 3 4
4
5A
B
C
D
E
F
4 1 2 3 4
Note: We will now see that this strategy guarantees an MST.
Properties of treesโข Definition: A tree is an undirected graph that is connected and acyclic.
โข Property: Any connected, undirected graph ๐บ = ๐, ๐ธ has๐ธ โฅ ๐ โ 1 edges.
โข Property: A tree on ๐ nodes has ๐ โ 1 edges.โ Start from an empty graph. Add one edge at a time making sure that it
connects two disconnected components. After having added ๐ โ 1edges, a tree has been formed.
โข Property: Any connected, undirected graph ๐บ = (๐, ๐ธ)with ๐ธ = ๐ โ 1 is a tree.โ It is sufficient to prove that ๐บ is acyclic. If not, we can always remove
edges from cycles until the graph becomes acyclic.
โข Property: Any undirected graph is a tree iff there is a unique path between any pair of nodes.โ If there would be two paths between two nodes, the union of the paths
would contain a cycle.
Graphs: MST and Max Flow ยฉ Dept. CS, UPC 4
The cut property
Suppose edges ๐ are part of an MST of ๐บ = ๐, ๐ธ . Pick any subset of nodes ๐ for which ๐ does not cross between ๐ and ๐ โ ๐, and let ๐ be the lightest edge across this partition. Then ๐ โช {๐} is part of some MST.
Proof (sketch): Let ๐ be an MST and assume ๐ is not in ๐. If we add ๐ to ๐, a cycle will be created with another edge ๐โฒ across the cut (๐, ๐ โ ๐). We can now remove ๐โฒ and obtain another tree ๐โฒ with weight ๐โฒ โค weight(๐). Since ๐ is an MST, then the weights must be equal.
Graphs: MST and Max Flow ยฉ Dept. CS, UPC 5
๐ ๐ โ ๐๐
๐โฒ
The cut property: example
Graphs: MST and Max Flow ยฉ Dept. CS, UPC 6
A
B
C
D
E
F
1
2 2
1
2 3 1
4
3A
B
C
D
E
F
1
2
1
1
3
MST ๐ป
A
B
C
D
1
2
๐
E
F
1
๐ โ ๐
A
B
C
D
E
F
1
2
1
13MST ๐ปโฒ3
Minimum Spanning Tree
Graphs: MST and Max Flow ยฉ Dept. CS, UPC 7
๐ฟ = // The set of edges of the MSTrepeat ๐ โ 1 times:
pick a set ๐ โ ๐ for which ๐ฟ has no edges between ๐ and ๐ โ ๐let ๐ โ ๐ธ be the minimum-weight edge between ๐ and ๐ โ ๐๐ฟ = ๐ฟ โช {๐}
Any scheme like this works (because of the properties of trees):
๐ ๐ โ ๐๐
๐
๐
MST: two strategies
Graphs: MST and Max Flow ยฉ Dept. CS, UPC 8
๐ ๐ โ ๐ Invariant:โข A set of nodes (๐) is in the tree.
Progress:โข The lightest edge with exactly
one endpoint in ๐ is added.
Primโs algorithm
Kruskalโs algorithm
Invariant:โข A set of trees (forest) has been
constructed.
Progress:โข The lightest edge between two
trees is added.
Primโs algorithm
Graphs: MST and Max Flow ยฉ Dept. CS, UPC 9
function Prim(๐ฎ, ๐)// Input: A connected undirected Graph ๐ฎ ๐ฝ, ๐ฌ// with edge weights ๐(๐).// Output: An MST defined by the vector prev.
for all ๐ โ ๐ฝ:visited(๐)= falseprev(๐)= nil
pick any initial node ๐๐visited(๐๐) = true๐ = 1
// ๐ธ: priority queue of edges using ๐(๐) as priority๐ธ = makequeue()for each (๐๐, ๐) โ ๐ฌ: ๐ธ.insert(๐๐, ๐)
while ๐ < ๐ฝ :(๐, ๐) = deletemin(๐ธ) // Edge with smallest weightif not visited(๐):
visited(๐) = trueprev(๐) = ๐๐ = ๐ + 1for each ๐, ๐ โ ๐ฌ:if not visited(๐): ๐ธ.insert(๐, ๐)
Complexity: O(|๐ฌ| ๐ฅ๐จ๐ |๐ฝ|)
visited
Primโs algorithm
Graphs: MST and Max Flow ยฉ Dept. CS, UPC 10
A
B
C
D
E
F
6
54 1
2
2 3 4
4
5A
B
C
D
E
F
4
2
1 3 4
(DB,2) (DC,2) (DF,4) (AB,5) (AC,6)
(BC,1) (DC,2) (DF,4) (AB,5) (AC,6)
(DC,2) (CF,3) (DF,4) (AB,5) (CE,5) (AC,6)
(AD,4) (AB,5) (AC,6)๐ธ:
(CF,3) (DF,4) (AB,5) (CE,5) (AC,6)
(DF,4) (FE,4) (AB,5) (CE,5) (AC,6)
(FE,4) (AB,5) (CE,5) (AC,6)
Kruskalโs algorithm
function Kruskal(๐ฎ, ๐)
// Input: A connected undirected Graph ๐ฎ ๐ฝ, ๐ฌ// with edge weights ๐๐.
// Output: An MST defined by the edges in ๐ฟ.
๐ฟ =sort the edges in ๐ฌ by weight
for all ๐, ๐ โ ๐ฌ, in ascending order of weight:if (๐ฟ has no path connecting ๐ and ๐):
๐ฟ = ๐ฟ โช { ๐, ๐ }
Graphs: MST and Max Flow ยฉ Dept. CS, UPC 11
Informal algorithm:โข Sort edges by weight.โข Visit edges in ascending order of weight and add them as long
as they do not create a cycle.
How do we know whether a new edge will create a cycle?
Disjoint sets
โข A data structure to store a collection of disjoint sets.
โข Operations:
โ makeset(๐ฅ): creates a singleton set containing just ๐ฅ.
โ find(๐ฅ): returns the identifier of the set containing ๐ฅ.
โ union(๐ฅ, ๐ฆ): merges the sets containing ๐ฅ and ๐ฆ.
โข Kruskalโs algorithm uses disjoint sets and calls
โ makeset: |๐| times
โ find: 2 โ |๐ธ| times
โ union: ๐ โ 1 timesGraphs: MST and Max Flow ยฉ Dept. CS, UPC 12
Kruskalโs algorithm
function Kruskal(๐ฎ, ๐)
// Input: A connected undirected Graph ๐ฎ ๐ฝ, ๐ฌ// with edge weights ๐๐.
// Output: An MST defined by the edges in ๐ฟ.
for all ๐ โ ๐ฝ: makeset(๐)
๐ฟ =sort the edges in ๐ฌ by weight
for all ๐, ๐ โ ๐ฌ, in ascending order of weight:if (find(๐) โ find(๐)):
๐ฟ = ๐ฟ โช { ๐, ๐ }union(๐,๐)
Graphs: MST and Max Flow ยฉ Dept. CS, UPC 13
Disjoint sets
โข The nodes are organized as a set of trees. Each tree represents a set.
โข Each node has two attributes:โ parent (๐): ancestor in the tree
โ rank: height of the subtree
โข The root element is the representative for the set: its parent pointer is itself (self-loop).
โข The efficiency of the operations depends on the height of the trees.
Graphs: MST and Max Flow ยฉ Dept. CS, UPC 14
E
B
H
C D F
G A
function makeset(๐):๐ ๐ = ๐rank ๐ = ๐
function find(๐):while ๐ฑ โ ๐ ๐ : ๐ = ๐ ๐return ๐
Disjoint sets
Graphs: MST and Max Flow ยฉ Dept. CS, UPC 15
E
B
H
C D F
G A
function makeset(๐):๐ ๐ = ๐rank ๐ = ๐
function find(๐):while ๐ฑ โ ๐ ๐ : ๐ = ๐ ๐return ๐
function union(๐, ๐):๐๐ = find(๐)๐๐ = find(๐)
if ๐๐ = ๐๐: return
if rank(๐๐) > rank(๐๐):
๐ (๐๐) = ๐๐else:๐ (๐๐) = ๐๐if rank(๐๐) = rank(๐๐):
rank(๐๐) = rank(๐๐) + 1
Disjoint sets
Graphs: MST and Max Flow ยฉ Dept. CS, UPC 16
๐ด0 ๐ต0 ๐ถ0 ๐ท0 ๐ธ0 ๐น0 ๐บ0
After makeset(๐ด),โฆ,makeset(๐บ):
After union(๐ด,๐ท), union(๐ต,๐ธ), union(๐ถ,๐น):
๐ด0 ๐ต0 ๐ถ0
๐ท1 ๐ธ1 ๐น1 ๐บ0
After union(๐ถ,๐บ), union(๐ธ,๐ด):
๐ด0
๐ต0
๐ท2
๐ธ1๐ถ0
๐น1
๐บ0 ๐ด0
๐ต0
๐ท2
๐ธ1
๐ถ0
๐น1
๐บ0
After union(๐ต,๐บ):
Property: Any root node of rank ๐ has at least 2๐ nodes in its tree.Property: If there are ๐ elements overall, there can be at most ฮค๐ 2๐ nodes of rank ๐.Therefore, all trees have height โค log๐.
Disjoint sets
Graphs: MST and Max Flow ยฉ Dept. CS, UPC 17
Property 1: Any root node of rank ๐ has at least 2๐ nodes in its tree.Property 2: If there are ๐ elements overall, there can be at most ฮค๐ 2๐ nodes of rank ๐.Therefore, all trees have height โค log๐.
rank ๐ rank ๐
โฅ 2๐ โฅ 2๐
โฅ 2๐+1
rank ๐ + 1For ๐ nodes, the tallest possibletree could have rank ๐, such that:
๐ โฅ 2๐
Property 1: proof by induction
๐ โค log2 ๐
Property 2:
Therefore, find(๐ฅ) is O(log๐)
Disjoint sets: path compression
โข Complexity of Kruskalโs algorithm: O(|๐ธ| log |๐|).
โ Sorting edges: O ๐ธ log ๐ธ = O(|๐ธ| log |๐|).
โ Find + union (2 โ |๐ธ| times): O( ๐ธ log ๐ ).
โข How about if the edges are already sorted or sorting can be done in linear time (weights are integer and small)?
โข Path compression:
Graphs: MST and Max Flow ยฉ Dept. CS, UPC 18
A
B C
D E
F G
A
B C
D G
E Fโก
A
B C D E F Gโก
Disjoint sets: path compression
Graphs: MST and Max Flow ยฉ Dept. CS, UPC 19
function find(๐):if ๐ฑ โ ๐ ๐ : ๐ (๐)= find(๐ ๐ )return ๐(๐)
๐ด3
๐ต0 ๐ถ1
๐ท0
๐ธ2
๐น1 ๐บ1 ๐ป0
๐ฝ0๐ผ0 ๐พ0
๐ด3
๐ต0 ๐ถ1
๐ท0
๐ธ2 ๐น1
๐บ1 ๐ป0 ๐ฝ0
๐ผ0
๐พ0
find(๐ผ)
๐ด3
๐ต0 ๐ถ1
๐ท0
๐ธ2 ๐น1 ๐บ1
๐ป0 ๐ฝ0
๐ผ0 ๐พ0Amortized cost of find: O(1)Kruskalโs cost: ๐( ๐ธ )(if sorting has linear cost)
Max-flow/min-cut problems
Graphs: MST and Max Flow ยฉ Dept. CS, UPC 20
OpenValve, by JAE HYUN LEE
How much water can you pumpfrom source to target?
What is the fewest number of greentubes that need to be cut so that nowater will be able to flow from thehydrant to the bucket?
Max-flow/Min-cut algorithm. Brilliant.org.https://brilliant.org/wiki/max-flow-min-cut-algorithm/
Max-flow/min-cut problems: applications
โข Networks that carry data, water, oil, electricity, cars, etc.โ How to maximize usage?โ How to minimize cost?โ How to maximize reliability?
โข Multiple application domains:โ Computer networksโ Image processingโ Computational biologyโ Airline schedulingโ Data miningโ Distributed computingโ โฆ
Graphs: MST and Max Flow ยฉ Dept. CS, UPC 21
Max-flow problem
Graphs: MST and Max Flow ยฉ Dept. CS, UPC 22
Model:โข A directed graph ๐บ = ๐, ๐ธ .โข Two special nodes ๐ , ๐ก โ ๐. โข Capacities ๐๐ > 0 on the edges.
Goal: assign a flow ๐๐ to each edge ๐ of the network satisfying:โข 0 โค ๐๐ โค ๐๐ for all ๐ โ ๐ธ (edge capacity not exceeded)โข For all nodes ๐ข (except ๐ and ๐ก), the flow entering the node
is equal to the flow exiting the node:
๐ค,๐ข โ๐ธ
๐๐ค๐ข =
๐ข,๐ง โ๐ธ
๐๐ข๐ง .
Size of a flow: total quantity sent from ๐ to ๐ก (equal to the quantity leaving ๐ ):
size ๐ =
๐ ,๐ข โ๐ธ
๐๐ ๐ข
a
b
c
d
t
e
s
3
2
3
4
5
110
3
1 1
5
2
1
4
11
2
2
5
50
0
Max-flow problem: intuition
Graphs: MST and Max Flow ยฉ Dept. CS, UPC 23
Find an augmenting path
An augmenting path may reversesome of the flow previously assigned
s
b
t
a
๐
0
๐ โ ๐
๐
After augmentingflow by ๐
Augmenting paths
Graphs: MST and Max Flow ยฉ Dept. CS, UPC 24
a
b
c
d
t
e
s
3
2
3
4
5
110
3
1 1
5
2
a
b
c
s
2
3
1 2
1
1
Flow
t
d
e
a
b
d
4
4
4
Augmenting path
c
t
e
s
Given a flow, an augmenting path represents a feasible additional flow from ๐ to ๐ก.
2
a
b
c
s
2
3
1 2
1
5
New flow
t
d
e4
4
Augmenting paths
Graphs: MST and Max Flow ยฉ Dept. CS, UPC 25
a
b
c
d
t
e
s
3
2
3
4
5
110
3
1 1
5
Augmenting paths can have forward and backward edges.
Flow
b
2
4
1
5
2
1
3
e
d
t
a
c
s
New flow
b
2
5
1
5
2
1
4
e
d
t
a
c
s
Augmenting path
a
b
1
1
1
1
e
s
c
d
t
bac
kwar
d
Augmenting paths
Given a flow ๐, an augmenting path is a directed path from ๐ to๐ก, which consists of edges from ๐ธ, but not necessarily in thesame direction. Each of these edges ๐ satisfies exactly one of thefollowing two conditions:
โข ๐ is in the same direction as in ๐ธ (forward) andfe < ๐๐. The difference ๐๐ โ ๐๐ is called the slack of the edge.
โข ๐ is in the opposite direction (backward) and ๐๐ > 0. Itrepresents the fact that some flow can be borrowed from thecurrent flow.
Graphs: MST and Max Flow ยฉ Dept. CS, UPC 26
Residual graph
Graphs: MST and Max Flow ยฉ Dept. CS, UPC 27
a
b
c
d
t
e
s
3
2
3
4
5
110
3
1 1
5
Flow
b
2
4
1
5
2
1
3
e
d
t
a
c
s
a
b
1
2
3
1
1
110
3
1 1
5
2
4e
s
c
3
d
t
Graph
Residual graph backward
forward
Ford-Fulkerson algorithm: example
Graphs: MST and Max Flow ยฉ Dept. CS, UPC 28
a
b t
e
s
2
1
3
4
4
110
3
1 1
41
1
1
1
d
c
a
b
c
d
t
e
s
3
2
3
4
5
110
3
1 1
5
Residuala
b
c
d
t
e
s
Flow
1a
b
c
d
t
e
s
1
1
1
1
a
b
c
d
t
e
s
2
1
1
2
2
1
a
b
1
2
3
4
4
110
3
1 1
3
2
2
c1
s t
e
d
Ford-Fulkerson algorithm: example
Graphs: MST and Max Flow ยฉ Dept. CS, UPC 29
a
b
c
d
t
e
s
2
4
1
5
2
1
3
a
b
1
2
3
1
1
110
3
1 1
5
2
4e
s
c
3
d
t
a
b
c
d
t
e
s
2
5
1
5
2
4
1
a
1
2
3
110
2
1 1
5
2
5 e
s
c4
d
t1
b
a
b
c
d
t
e
s
2
5
1
5
2
4
2
1
1
a
1
2
2
110
1
1 1
5
2
e
s
c4
d
t2
b1
5
Ford-Fulkerson algorithm
Graphs: MST and Max Flow ยฉ Dept. CS, UPC 30
function Ford-Fulkerson(๐ฎ,๐,๐)
// Input: A directed Graph ๐ฎ ๐ฝ, ๐ฌ with edge capacities ๐๐. // ๐ and ๐ and the source and target of the flow.// Output: A flow ๐ that maximizes the size of the flow.// For each ๐ข, ๐ฃ โ ๐ธ, ๐(๐ฃ, ๐ข) represents its flow.
for all ๐ข, ๐ฃ โ ๐ธ:๐ ๐ข, ๐ฃ = ๐ ๐ข, ๐ฃ // Forward edges๐ ๐ฃ, ๐ข = 0 // Backward edges
while there exists a path ๐ = ๐ โ ๐ก in the residual graph:๐ ๐ = min{๐ ๐ข, ๐ฃ : ๐ข, ๐ฃ โ ๐}for all ๐ข, ๐ฃ โ ๐:๐ ๐ข, ๐ฃ = ๐ ๐ข, ๐ฃ โ ๐(๐)๐ ๐ฃ, ๐ข = ๐ ๐ฃ, ๐ข + ๐(๐)
Ford-Fulkerson algorithm: complexity
โข Finding a path in the residual graph requires O( ๐ธ ) time (using BFS or DFS).
โข How many iterations (augmenting paths) are required?
โ The worst case is really bad: O(๐ถ โ ๐ธ ), with ๐ถ being the largest capacity of an edge (if only integral values are used).
โ By selecting the path with fewest edges (using BFS) the maximum number of iterations is O( ๐ โ ๐ธ ).
โ By carefully selecting fat augmenting paths (using some variant of Dijkstraโs algorithm), the number of iterations can be reduced.
โข Ford-Fulkerson algorithm is ๐(|๐| โ ๐ธ 2) if BFS is used to select the path with fewest edges (Edmonds-Karp algorithm).
Graphs: MST and Max Flow ยฉ Dept. CS, UPC 31
Max-flow problem
Graphs: MST and Max Flow ยฉ Dept. CS, UPC 32
t
e
3
2
3
4
5
110
3
1 1
5
๐ณ ๐น
The augmenting-path theorem:
A flow is maximum iff it admits no augmenting path.
Cut: An (๐ , ๐ก)-cut partitions the nodes into two disjointgroups, ๐ฟ and ๐ , such that ๐ โ ๐ฟ and ๐ก โ ๐ .
For any flow ๐ and any (๐ , ๐ก)-cut (๐ฟ, ๐ ):
size ๐ โค capacity ๐ฟ, ๐ .
The max-flow min-cut theorem:
The size of the maximum flow equals the capacityof the smallest (๐ , ๐ก)-cut.
a d
bs
c
Min-cut algorithm
Graphs: MST and Max Flow ยฉ Dept. CS, UPC 33
a
b
c
d
t
e
s
2
5
1
5
2
4
2
1
1
a
1
2
2
110
1
1 1
5
2
e
s
c4
d
t2
b1
5
Finding a cut with minimum capacity:
1. Solve the max-flow problem with Ford-Fulkerson.2. Compute ๐ฟ as the set of nodes reachable from ๐ in
the residual graph.3. Define ๐ = ๐ โ ๐ฟ.4. The cut (๐ฟ, ๐ ) is a min-cut.
Graph Residual graph
Bipartite matching
Graphs: MST and Max Flow ยฉ Dept. CS, UPC 34
Aleix
Bernat
Carles
David Duna
Cristina
Berta
Aida
BOYS GIRLS
There is an edge between a boy and a girl if they like each other.
Can we pick couples so that everyone has exactly one partner that he/she likes?
Bad matching: if we pick (Aleix, Aida) and (Bernat, Cristina), then we cannot findcouples for Berta, Duna, Carles and David.
A perfect matching would be: (Aleix, Berta), (Bernat, Duna), (Carles, Aida) and (David, Cristina).
Bipartite matching
Graphs: MST and Max Flow ยฉ Dept. CS, UPC 35
Aleix
Bernat
Carles
David
Cristina
Duna
Berta
Aida
s t
Reduced to a max-flow problem with ๐๐ = 1.
Question: can we always guarantee an integer-valued flow?
Property: if all edge capacities are integer, then the optimal flow found byFord-Fulkersonโs algorithm is integral. It is easy to see that the flow of theaugmenting path found at each iteration is integral.
Extensions of Max-Flow
โข Max-Flow with Edge Demandsโ Each edge ๐ has a demand ๐(๐). The flow ๐ must satisfy ๐ ๐ โค ๐ ๐ โค ๐(๐).
โข Node Supplies and Demandsโ An extra flow ๐ฅ(๐ฃ) can be injected (positive) or extracted (negative) at every
vertex ๐ฃ. The flow must satisfy:
๐ขโ๐
๐ ๐ข โ ๐ฃ โ
๐คโ๐
๐ ๐ฃ โ ๐ค = ๐ฅ ๐ฃ .
โข Min-cost Max-Flowโ Each edge ๐ has a weight ๐ค๐. Compute a max-flow of minimum cost:
cost ๐ =
๐โ๐ธ
๐ค๐ โ ๐(๐)
โข Max-Weight Bipartite Matchingโ Each edge ๐ has a weight ๐ค๐. Find a maximum cardinality matching with
maximum total weight.
Graphs: MST and Max Flow ยฉ Dept. CS, UPC 36
EXERCISES
Graphs: MST and Max Flow ยฉ Dept. CS, UPC 37
Minimum Spanning Trees
โข Calculate the shortest path tree from node A using Dijkstraโs algorithm.
โข Calculate the MST using Primโs algorithm. Indicate the sequence of edges added to the tree and the evolution of the priority queue.
โข Calculate the MST using Kruskalโsalgorithm. Indicate the sequence of edges added to the tree and the evolution of the disjoint sets. In case of a tie between two edges, try to select the one that is not in Primโs tree.
Graphs: MST and Max Flow ยฉ Dept. CS, UPC 38
A
BC
D E F
G
H
I
K
J 10
10
10
10
12
128
5
9
13
6 8
7
36
3
7 98
2
๐-clustering of maximum spacingWe want to classify a set of points into ๐ clusters. We define the distance between two points as the Euclidean distance. We define the spacing of the clustering as the minimum distance between any pair of points in different clusters.
Describe an algorithm such that, given an integer ๐, finds a ๐-clustering such that spacing is maximized. Argue about the complexity of the algorithm.
Graphs: MST and Max Flow ยฉ Dept. CS, UPC 39
spacing
๐ = 4
Note: ๐-clustering of maximum spacing is the basis for the construction of dendograms.
Flow network (from [DVP2008])
โข Find the maximum flow from S to T. Give a sequence of augmenting paths that lead to the maximum flow.
โข Draw the residual graph after finding the maximum flow.
โข Find a minimum cut between S and T.
Graphs: MST and Max Flow ยฉ Dept. CS, UPC 40
S
A
B
C
D
T
G
F
E
6
1
10
2
2
20
5
6
12
4
4
1
5
102
Contagious diseaseThe island of Sodor is home to a large number of towns and villages, connected by an extensive rail network. Recently, several cases of a deadly contagious disease (Covid 19) have been reported in the village of Ffarquhar. The controller of the Sodor railway plans to close down certain railway stations to prevent the disease from spreading to Tidmouth, his home town. No trains can pass through a closed station. To minimize expense (and public notice), he wants to close down as few stations as possible. However, he cannot close the Ffarquhar station, because that would expose him to the disease, and he cannot close the Tidmouth station, because then he couldnโt visit his favorite pub.Describe and analyze an algorithm to find the minimum number of stations that must be closed to block all rail travel from Ffarquhar to Tidmouth. The Sodor rail network is represented by an undirected graph, with a vertex for each station and an edge for each rail connection between two stations. Two special vertices F and T represent the stations in Ffarquhar and Tidmouth.For example, given the following input graph, your algorithm should return the number 2.
Graphs: MST and Max Flow ยฉ Dept. CS, UPC 41
F T
Source: Jeff Erickson, Algorithms, UIUC, 2015.
Blood transfusion
Enthusiastic celebration of a sunny day at a prominent northeastern university has resulted in the arrival at the university's medical clinic of 169 students in need of emergency treatment. Each of the 169 students requires a transfusion of one unit of whole blood. The clinic has supplies of 170 units of whole blood. The number of units of blood available in each of the four major blood groups and the distribution of patients among the groups is summarized below.
Type A patients can only receive type A or O; type B patients can receive only type B or O; type O patients can receive only type O; and type AB patients can receive any of the four types.
Give a maxflow formulation that determines a distribution that satisfies the demands of a maximum number of patients.
Can we have enough blood units for all the students?
Source: Sedgewick and Wayne, Algorithms, 4th edition, 2011.
Graphs: MST and Max Flow ยฉ Dept. CS, UPC 42
Blood type A B O AB
Supply 46 34 45 45
Demand 39 38 42 50
Edge-disjoint paths
Given a digraph ๐บ = (๐, ๐ธ) and vertices ๐ , ๐ก โ ๐, describe an algorithm that finds the maximum number of edge-disjoint paths from ๐ to ๐ก.
Note: two paths are edge-disjoint if they do not share any edge.
Graphs: MST and Max Flow ยฉ Dept. CS, UPC 43