Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
44 views21 pages

The Design and Analysis of Algorithms

Uploaded by

wwilderness15
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
44 views21 pages

The Design and Analysis of Algorithms

Uploaded by

wwilderness15
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 21

NETWORK ALGORITHMS

Maximal Flow, Work Assignment, Minimal


Flow Cut, Network cloning

Teacher: Samir Guliyev


Student: Jabrayilov Mayil, Rzayev Khayal
Group; 606.23E
Subject : The design and analysis of
algorithms
Chapter Topics

 Network Components

 The Maximal Flow

 The Work Assignment

 The Minimal Flow Cut

 The Network Cloning


Network Components(1 of
3)

 A network is an arrangement of paths (branches) connected at


various points (nodes) through which one or more items move from
one point to another

 The network is drawn as a diagram providing a picture of the system


, thus enabling visual representation and enhanced understanding

 A large number of real-life systems can be modeled as networks


which are relatively ease to conceive and construct
Network Components(2 of
3)

 Network diagrams consists of nodes and branches.

 Nodes (circles) , represent junction points or locations.

 Branches (lines), connect nodes and represent flow.


Network Components(3 of
3)
 Four nodes, four branches in figure.
 “Baku” , node 1,termed the origin ; any of others, destination.
 Branches identified by beginning and ending node numbers.
 Value assigned to each branch( distance, time, cost etc.)

6
2
7
1
Baku
3
4

3 5
Maximal Flow (1 of 5)
 In the maximal flow problem, the goal is to assign flows to the links to maximize
the total flow from a designated source node to a designated sink node.
 For example, consider the networks shown in Figure 1. The numbers on a link show
the link’s flow and capacity. For example, the link between nodes B and C in the left
network has a flow of 1 and a capacity of 2.

3/ 1/ 3/ 2/
A 3 B 2 C A 3 B 2 C
1/ 2/ 1/ 2/ 2/
1/
2 2 3 2 3
2

D 1/ E 3/
F D 2/
E 3/
F
2 3 2 3
Figure 1: In the maximal flow problem, the goal is to
maximize the flow from a source node to a sink node
Maximal Flow (2 of 5)

 The network on the left has a total flow of 4 from node A to node F. The total amount of flow
leaving the source node A in the network on the left is 1 unit along the A → D link plus 3 units
along the A → B link for a total of 4. Similarly the total flow into the sink node F is 3 units along
the E → F link plus 1 unit along the C → F link for a total of 4 units. (If no flow is gained or lost in
the network, then the total flow out of the sink node is the same as the total flow into the sink
node.)
 You cannot increase the total flow by simply adding more flow to some of the links. In this
example you can’t add more flow to the A → B link because that link is already used at full
capacity. You also can’t add more flow to the A → D link because the E → F link is already used at
full capacity, so the extra flow wouldn’t have anywhere to go
 You can improve the solution, however, by removing 1 unit of flow from the path B → E → F and
moving it to the path B → C → F. That gives the E → F link unused capacity so you can add a new
unit of flow along the path A → D → E → F. The network on the right in Figure 14-7 shows the new
flows, giving a total flow of 5 from node A to node F.
Maximal Flow (3 of 5)
 The algorithm for finding maximal flows is fairly simple at a high level but figuring out how it works can be
hard.
 The Ford-Fulkerson Algorithm:
Step 1: Find an augmenting path from the source node to the sink node in the residual capacity network.
Step 2: Determine the smallest residual capacity along the augmenting path.
Step 3: Update the flows in the network by adding the determined flow to the forward links in the path
and subtracting it from the backlinks.
Repeat: Continue this process until no augmenting path can be found in the residual capacity network.
 Edmonds-Karp Algorithm:
Step 1:The Edmonds-Karp algorithm is a specific implementation of the Ford-Fulkerson method.
Step 2:It always selects the shortest augmenting path (in terms of the number of edges) using Breadth-
First Search (BFS) in the residual graph.
Step 3:By systematically selecting shortest paths, it ensures that each edge's capacity is used
efficiently, avoiding redundant iterations
 You don’t need to actually build the residual capacity network. You can use the original network and calculate
each link’s and backlink’s residual capacity by comparing its flow to its capacity.
Maximal Flow (4 of 5)

Ford-Fulkerson Algorithm O(F⋅E) Edmonds-Karp Algorithm O(V⋅ )


 Best Case:  Best Case:
The best-case scenario occurs if the algorithm
In the best-case scenario, the algorithm finds the
maximum flow in just one iteration of an augmenting finds the maximum flow in just one V BFS
path. operations, where each BFS explores all edges
O(E)
This happens if the first path saturates all bottlenecks,
giving O(E) for a single DFS or BFS.
This gives O(V⋅E)
 Average Case:  Average Case:
Typically, the algorithm requires multiple iterations, On average, the algorithm performs a number
with the time depending on the structure of the graph of BFS operations proportional to V⋅E with
and the distribution of edge capacities. each BFS costing O(E).
On average, finding paths takes O(E), and the number
of iterations is proportional to the maximum flow F This results in O(V⋅) for a typical graph.
resulting in O(F⋅E)  Worst Case:
 Worst Case: In the worst-case scenario, each augmenting
In the worst case, each augmenting path adds only 1
path involves many iterations, and the
unit to the flow, requiring F iterations. algorithm takes O(V⋅ )
Since each iteration involves finding a path in O(E),
This happens in dense graphs where the
the total time is O(F⋅E)
number of edges is close to O()and many BFS
Maximal Flow (5 of 5)

 Pseudocode of the maximal flow algorithm Explanation of the Pseudocode:


1.Residual Graph:
Algorithm MaximalFlow(graph, source, sink): •Residual capacities are calculated as capacity -
Input:
graph - adjacency list or matrix with capacities for all edges
flow for forward edges and flow for backward
source- the source node edges (backlinks).
sink - the sink node •The algorithm operates on this residual graph.
Output: 2.Augmenting Path:
maxFlow - the maximum flow from source to sink •An augmenting path is a path from the source
Initialize flow for all edges to 0 to the sink in the residual graph where every
maxFlow ← 0 edge has a positive residual capacity.
•This can be found using BFS (Breadth-First
While there exists an augmenting path from source to sink in the
residual graph: Search) or DFS (Depth-First Search).
pathFlow ← ∞ 3.Flow Update:
•The flow along the augmenting path is updated
For each edge (u, v) in the augmenting path:
by the smallest residual capacity in the path.
pathFlow ← min(pathFlow, residualCapacity(u, v))
For each edge (u, v) in the augmenting path: 4.Termination:
flow(u, v) ← flow(u, v) + pathFlow
•The algorithm stops when no augmenting path
flow(v, u) ← flow(v, u) - pathFlow can be found in the residual graph, indicating
residualCapacity(u, v) ← capacity(u, v) - flow(u, v) that the maximum flow has been reached.
residualCapacity(v, u) ← flow(u, v)

maxFlow ← maxFlow + pathFlow


Work Assignment (1 of 3)

 Suppose you have a workforce of 100 employees, each with a set of specialized skills, and you have a
set of 100 jobs that can only be done by people with certain combinations of skills. The work
assignment problem asks you to assign employees to jobs in a way that maximizes the number of
jobs that are done.
 At first this might seem like a complicated combinatorial problem. You could try all the possible
assignments of employees to jobs to see which one results in the most jobs being accomplished.
There are 100! ≈ 9.3 × 10157 permutations of employees, so that could take a while.
 The maximal flow algorithm gives you an easy solution. Create a work assignment network with one
node for each employee and one node for each job. Create a link from an employee to every job the
employee can do. Create a source node connected to every employee, and connect every job to a sink
node. Give all the links a capacity of 1.
 Figure 2 shows a work assignment network with five employees represented by letters and five jobs
represented by numbers. All the links are directional-pointing right and have a capacity of 1. The
arrowheads and capacities are not shown to keep the picture simple
Work Assignment (2 of 3)

 Now find the maximal flow


from the source node to the A 1
sink node. Each unit of flow
moves through an employee
to the job that should be
assigned to the employee. B 2
The total flow gives the
number of jobs that can be
performed
 In a bipartite network, the
Source C 3 Sink
nodes can be divided into two
groups A and B, and every link
connects a node in group A D 4
with a node in group B. If you
remove the source and sink
nodes in the network shown in
Figure 2, the result is a E 5
bipartite network. Bipartite
matching is the process of
matching the nodes in group A Figure 2: The maximal flow through a work
with those in group B. assignment network gives optimal assignments
Work Assignment (3 of 3)

 Best Case
Ford-Fulkerson : O(E)=O(n × m)
Edmonds-Karp : O(E)=O(n × m)
Both algorithms perform similarly in the best case, as finding the augmenting paths is the bottleneck. The
time complexity is linear in the number of edges, O(n × m).
 Worst Case
Ford-Fulkerson : O(n× )
Edmonds-Karp : O( x )
In the worst case, Ford-Fulkerson has a complexity of O(n× ) whereas Edmonds-Karp has a worse
complexity of O(× ) due to the guarantee of polynomial time through BFS. Therefore, Ford-Fulkerson tends
to perform better in the worst case.
 Average Case
Ford-Fulkerson : O(n× )
Edmonds-Karp : O(× )
In the average case, Edmonds-Karp will still have a higher time complexity than Ford-Fulkerson due to the
extra overhead of repeatedly applying BFS and its polynomial bounds on augmenting paths. Ford-Fulkerson
performs better in this case as well, especially when the number of augmenting paths is relatively low.
Minimal flow cut (1 of 5)

 In the minimal flow cut problem (also 4 4 0


called min flow cut, minimum cut, or A B C D
min-cut), the goal is to remove links 5 2 2 2
from a network to separate a source
2 0 2
node from a sink node while minimizing E F G H
the capacity of the links removed.
2 0 2 2
 For example, consider the network 2 2 2
shown in Figure 3. Try to find the best I J K L
links to remove to separate source node 2 2
0 2
A from sink node O. You could remove
0 2 0
the A → B and A → E links, which have a M N O P
combined capacity of 9. You can do
better if you remove the K → O, N → O,
and P → O links instead, because they Figure 3: Try to find the best links to remove
have a total capacity of only 6. (Take a from this network to separate node A from
minute to see how good a solution you node O.
can find.
Minimal flow cut (2 of 5)
 Exhaustively removing all possible combinations of links would be a huge task for
even a relatively small network. Each link is either removed or left in the network, so
if the network contains N links, there would be 2N possible combinations of
removing and leaving links. The relatively small network shown in Figure 3 contains
24 links, so there are 224 ≈ 16.8 million possible combinations to consider. In a
network with 100 links, which is still fairly small for many applications such as
modeling a street network, you would need to consider 2100 ≈ 1.3 × 1030
combinations. If your computer could consider 1 million combinations per second, it
would take roughly 4.0 × 1016 years to consider them all. You could undoubtedly
come up with some heuristics to make the search easier, but this would be a
daunting approach
 Fortunately, the maximal flow algorithm provides a much easier solution. The
following steps describe the algorithm at a high level:
1. Perform a maximal flow calculation between the source and
sink nodes.
2. Starting from the sink node, visit all the nodes you can using
only links and backlinks that have residual capacities greater than 0.
3. Place all the nodes visited in Step 2 in set A and all the other
nodes in set B.
Minimal flow cut (3 of 5)

4 4
 Why This Works: A B C D
If there were additional flow paths from A to O, 5 2 2
they would show up as residual capacity in the 2
2
graph, contradicting the max-flow calculation. E F G H
The cut ensures all flow from O to A is captured
2 2
without any "backflow," confirming the cut's
capacity equals the max flow 2 2 2
 In the given example, the max flow is 4. The
I J K L
min-cut, achieved by removing edges E →I , F 2 0 2 2
→J, F →G ,C →G , and C →D also has a total 0 2 0
capacity of 4. This aligns with the theorem. M N O P

Figure 4: This network shows a solution to the


min-flow-cut problem for the network shown in
Figure 3.
Minimal flow cut (4 of 5)
•Maximum Flow Calculation:
Algorithm MinimalCut(G, source, sink):
•Use a maximum flow algorithm like Ford-
Input:
Fulkerson or Edmonds-Karp to compute the
G - Flow network as adjacency list or matrix with
maximum flow in the network. This also gives the
capacities
residual capacities for all edges.
source - The source node
•Residual Graph and Reachable Nodes:
sink - The sink node
•Construct the residual graph based on the flow
Output:
values. A residual graph represents the remaining
cutEdges - Set of edges in the minimum cut
capacities for each edge.
// Step 1: Compute the Maximum Flow using an
•Perform a Depth-First Search (DFS) or Breadth-
algorithm like Ford-Fulkerson
First Search (BFS) from the source to find all nodes
maxFlow, flow = MaximalFlow(G, source, sink)
that are still reachable in the residual graph.
// Step 2: Identify reachable nodes in the residual
•Find Minimum Cut Edges:
graph
•An edge (u,v) belongs to the minimum cut if:
residualGraph = ComputeResidualGraph(G, flow)
•u is reachable from the source in the residual
visited = PerformDFS(residualGraph, source)
graph.
// Step 3: Find edges in the minimum cut
•v is not reachable from the source in the
cutEdges = [ ]
residual graph.
For each node u in G:
•The capacity of edge (u,v) is greater than 0 in
If u is visited:
the original graph.
For each neighbor v of u in G:
•Return Minimum Cut Edges:
If v is not visited and capacity(u, v) > 0:
•The set of edges identified in Step 3 forms the
Add edge (u, v) to cutEdges
minimum cut.
// Step 4: Return the edges forming the minimum cut
Minimal flow cut (5 of 5)

Time complexity for Minimal cut flow

 Best Case:
Time Complexity: O(E⋅log⁡(max flow))
Achieved when augmenting paths quickly saturate edges, and the flow increases
rapidly with fewer iterations.
 Average Case:
Time Complexity: O(E⋅max flow)
On average, augmenting paths are found in O(E) time, and the number of
augmentations is proportional to the maximum flow in the graph.
 Worst Case:
Time Complexity: O(E⋅max flow)
Occurs when the algorithm selects augmenting paths with small capacities,
leading to the maximum number of iterations.
Network Cloning(1 of 2)

 Network Cloning involves duplicating a network’s structure (nodes,


edges, and capacities) to simulate multiple processes, analyze
resource distribution, or optimize flow across identical copies of the
network
 Network cloning enables the study of flow algorithms such as
Maximal Flow (e.g., Ford-Fulkerson) and Min-Cut under different
conditions. By cloning the network:
1.You can simulate and test multiple scenarios without affecting the original structure.
2.It helps identify bottlenecks or critical edges by running flow algorithms on different
instances of the same network
 Cloned networks are especially useful for work assignment:
1.A cloned network represents the same tasks distributed across multiple workers or
systems.
2.By analyzing flows in the cloned networks, you can optimize task allocation, avoid
overloading resources, and ensure fairness.
Network Cloning(2 of 2)

 Fault Tolerance
If the main network fails, the cloned network acts as a backup to ensure the system
continues functioning.
Example: In a communication network, if a server goes down, a cloned network can
seamlessly take over.
 Parallel Processing
Cloning networks allows for parallel computation of flows in logistics or computing
systems.
 Example: Multiple cloned networks can analyze traffic flows simultaneously to find the
fastest routes or balance workload.
Cloning helps test the behavior of flow algorithms (e.g., Ford-Fulkerson) under different
scenarios.
 Example: Simulating network changes like increasing edge capacities or removing nodes to
observe the impact on Maximal Flow.
Thanks four
your attention

You might also like