You are on page 1of 17

UNIT-III

Flow-Networks: Maxflow-mincut theorem, Ford-Fulkerson Method


to compute maximum flow, Edmond-Karp maximum-flow algorithm.
Matrix Computations: Strassen's algorithm and introduction to
divide and conquer paradigm, inverse of a triangular matrix,
relation between the time complexities of basic matrix
operations, LUP-decomposition.

FLOW NETWORKS:

Flow: flow can be imagined as a physical flow of a fluid through the network that moves
from source to sink through the directed edges. Each edge will have a flow that cannot be
greater than the edge’s capacity.
Cut: An s-t cut is partitioning the graph into two disjoint subsets, with the source in one part
and sink in another.

Example:

Let's look at an example of how to find a minimum cut in a network graph.

Solution:

1
2
Flow network Definition: A Flow Network is a directed graph G = (V, E) such that
1. For each edge (u, v) ∈ E, we associate a nonnegative weight capacity c (u, v) ≥ 0. If
(u, v) ∉ E, we assume that c (u, v) = 0.
2. There are two distinguishing points, the source s, and the sink t;
3. For every vertex v ∈ V, there is a path from s to t containing v.

THE MAX-FLOW AND MIN-CUT THEOREM:

The maximum flow problem is the problem of finding the maximum allowable flow through
a single source, single sink flow network. In any flow network with source s and target t, the value
of the maximum (s, t)-flow is equal to the capacity of the minimum (s, t)-cut. Examples: Ford
Fulkerson algorithm, Edmonds-Krap algorithm and Dinic’s algorithm

1 Ford-Fulkerson algorithm:

This algorithm finds the maximum flow of a network or graph. The max-flow min-cut
theorem states that the maximum flow through any network from a given source to a given
sink is exactly equal to the minimum sum of a cut.

The Ford-Fulkerson algorithm is based on the three important concepts: the residual network
augmented path and cut. 

 Residual Capacity: The residual capacity for a flow network N and


flow f is r(e)=c(e)−f(e) for all e∈E
 Augmenting Paths: An augmenting path is a directed path in the residual network
with unused capacity for every edge in that path

Example:

3
4
2 Edmonds–Karp algorithm:
5
This is an optimized implementation of the Ford–Fulkerson method for computing the
maximum flow in a flow network.

Algorithm:

Example:

Solution:
Initially, we build, which fully matches   as there’s no flow in yet. Below, we can see on
the left and on the right. For the edges of, we depict the current flow on them followed by
their capacity:

Next, we find the first shortest path from to using BFS. The path consists of three edges and
is shown on below. The flow increases by 8 along the augmenting path. We parallelly change
the flow across the edges of as the algorithm progresses:

6
As the flow changes, new reverse edges may appear in. Below, we can see new reverse
edges, along with the second shortest path from to consisting of four edges. The flow
increases by 5 this time:

Next, we find another augmenting path consisting of four edges. The path increases the flow
by 2:

We’re in a situation now where there’re no augmenting paths left in. It’s the indication that
the algorithm has finished and we’ve found the maximum flow from to:

The maximum flow value may be fetched by either adding the flows on the outgoing edges
of or by adding the flows on the incoming edge of . In either case, the maximum flow value is
15 for our example.

STRASSEN'S ALGORITHM

Strassen’s Matrix Multiplication is the divide and conquers approach to solve the matrix
multiplication problems. Strassen’s Matrix multiplication can be performed only on square
matrices where n is a power of 2. In Strassen’s method, the four sub-matrices of result are
calculated using following formulae.

7
Now the resultant matrix can be obtained in the following way:

Algorithm:
Algorith
m
strassen
(x, y,
z, n)
{

if n = threshold then compute


z = x * y is a conventional matrix.
else
Partition x into four sub matrices a, b, c, d
Partition y into four sub matrices e, f, g, h
p1 = strassen(a, f - h)
p2 = strassen(a + b, h)
p3 = strassen(c + d, e)
p4 = strassen(d, g - e)
p5 = strassen(a + d, e + h)
p6 = strassen(b - d, g + h)
p7 = strassen(a - c, e + f)
z11 = p5 + p4 - p2 + p6
z12 = p1 + p2
z21 = p3 + p4
z22 = p1 + p5 - p3 - p7
return z
}

Example:
INTRODUCTION TO DIVIDE AND CONQUER
Divide and Conquer is one of the important algorithmic pattern. Using divide and conquer
approach, the problem is divided into smaller sub-problems and then each problem is solved
independently.

Divide and Conquer algorithm consists of the following three steps.


1. Divide the original problem into a set of subproblems.
2. Conquer: Solve every subproblem individually, recursively.
3. Combine: put together the solutions of the subproblems to get the solution to the
whole problem.

8
Examples:

 Merge Sort
 Quick Sort
 Binary Search
 Fibonacci Search
 Strassen's Matrix Multiplication

General Algorithm or Control Abstraction of Divide and Conquer: The control


abstraction for divide and conquer technique is DANDC(P), where P is the problem to be
solved.
Algorithm DANDC (P){

if SMALL (P)

then return S (p);

else

{ divide p into smaller instances p1, p2, …. Pk, k > 1;

apply DANDC to each of these sub problems;

return (COMBINE (DANDC (p1) , DANDC (p2),…., DANDC (pk));

SMALL (P) is a Boolean valued function which determines whether the input size is small or
not. If small the answer will be computed without splitting otherwise, the problem ‘p’ into

9
smaller sub problems. These sub problems p1, p2, . . . , pk are solved by recursive application
of DANDC.

INVERSE OF A TRIANGULAR MATRIX:

 triangular matrix is a special kind of square matrix.


 A square matrix is said to be a lower triangular matrix if all the elements above its
main diagonal are zero.
 A square matrix is said to be an upper triangular matrix if all the elements below the
main diagonal are zero.

10
RELATION BETWEEN THE TIME COMPLEXITIES OF BASIC MATRIX
OPERATIONS:

Matrix: A matrix is a two-dimensional array that has a fixed number of rows and columns
and contains a number at the intersection of each row and column. If a matrix has m rows
andn columns, we say that it has dimension m X n or it is a m X n matrix.

Example:

Vectors: If a matrix has only one row or only one column it is called a vector. A matrix
having only one row is called a row vector. A matrix having only one column is called
column vector.

row vector : column vector :

Addition: it is one of the basic operations in matrices. It is used to add 2 matrices or add
a scalar to a vector.

11
Multiplications: it is used to perform product operation.

12
13
Summary:

Examples:

LU DECOMPOSITION:

LU decomposition (where ‘LU’ stands for ‘lower upper’, and also called LU factorization)
factors a matrix as the product of a lower triangular matrix and an upper triangular matrix.
Definition: The LU decomposition of a matrix A is the pair of matrices L and U such that:

1. A=LU
2. L is a lower-triangular matrix with all diagonal entries equal to 1
3. U is an upper-triangular matrix

14
Let A be a square matrix. An LU factorization refers to the factorization of A, with proper
row and/or column orderings or permutations, into two factors, a lower triangular matrix L
and an upper triangular matrix U, A=LU.

It is always possible to factor a square matrix into a lower triangular matrix and an upper
triangular matrix. That is, [A] = [L][U]
LUP Decomposition algorithm:

Example:

15
The above matrix implies that:

u11 = 8

u12 = -6

u13 = 2

I21u11 = -6 ⇒ I21 * 8 = -6 ⇒ I21 = -3/4

I21u12 + u22 = 7 ⇒ (-3/4) * (-6) + u22 = 7 ⇒ u22 = 5/2

I21u13 + u23 = -4 ⇒ (-3/4) × 2 + u23 = -4 ⇒ u23 = -5/2

l31u11 = 2 ⇒ l31 × 8 = 2 ⇒ l31 = 1 / 4

l31u12 + l32u22 = -4 ⇒ 1/4 × (-6) + l32 × 5/2 = -4 ⇒ l32 = -1

l31u13 + l32u23 + u33 = 3 ⇒ 1/4 × 2 + (-1) × (-5/2) + u33 = 3 ⇒ u33 = 0

A = L * U = LU

16
17

You might also like