Unit 3 & Half Unit 4 DS
Unit 3 & Half Unit 4 DS
wita
V7
Hhe Vertex as the parameter.
’ Jn the Des unon, martk of vestiet E9
he vertex as vibited and Commbute thein deree o the
erkvely eall the 3s meto
fox ale onvised nlshbors p the Here, indepee
verte
once ale the neishhors have DVes the
been wisitedpsh the vexter onto will be aA minimum
E11
3 V5
V1 E8
3
E5 3
E2 3
5
V3 E7 V7
E1 V3
E4 3
2 E6
E9
2
E3 V6
V2 4
E10
CUT 3
CUT 2
CUT 1
3
X1
X2
2 1
-2
X4 X3
Here all edges representaflow value, so the set or vector of flows in this
graph is
=(3, 3, -2, 2,)
These flow values satisfy the Kirchhoff law. For %, the sum of flows equal
to3for the outgoing edges. Similarly, the sum of flows equal to +=3 for
the incoming edges of x, which also equals the previously computed sum.
This can be checkedfor the other vertices.
Flowin a network or a graph follows some properties. In aflow graph, there
aretwo special vertices: source S and sink P. Each edge (u) in theflow
neWork has a capacity c(u)0,A flow in agraph Gis a
Aunction VV’R and it satisfies a capacity constraint: for each
edge (uv), fl4)<cuy) Net flow in the edges follows skew-symmetric
propert u ) - f ( , u)
Amaximum flow is defined as the maximum amount of flow that the
araph or network would allow to flow from the source node to its sink
node.
Max-FlowMin-Cut Theorem
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 acut. This theorem can be verified using the Ford
Fulkerson algorithm. This algorithm finds the maximum flow of a network or
graph.
Let's define the max-flow min-cut theorem formally. Let G=(X,A) be a flow
network, da flow on G. The value of the maximum flow from the source S to
the sink is equal tothe capacity of the minimum cut CT separating Sand P:
Mar( )= Min(e(C7))
Ford-Fulkerson Algorithm for Maximum Flow
Problem
The Ford-Fulkerson algorithm is a widely used algorithm to solve the
maximum flow problem in a flow network. The maximum flow problem
involves determiningthe maximum amount of flow that can be sent from a
Source vertex to a sink vertex in a directed weighted graph, subject to
capacity constraints on the edges.
The algorithm works by iteratively finding an augmenting path, which is a
path from the source to the sink in the residual graph, i.e., the graph
obtained by subtracting the current flowfrom the capacity of each edge. The
alaorithm then increases the flow along this path by
annount,which is the minimum capacity of the the maximum possible
Problem:
edges along the path.
Given a graph which represents a flow
capacity. Also, given two vertices sourcenetwork where every edge has a
's' and sink 't in the graph, find the
maximum possible flow fromsto t with the following constraints:
Flowon an edge doesn't exceed the given
capacity of the edge.
Incoming flow is equal to outgoing flow for every
For example, consider the following graph vertex exXcept s and t.
12 Source: 0
Sink: 5
16 20
10 4 7
13 4
14
12 4
11
Ford-Fulkerson Algorithm
The following is simple idea of Ford-Fulkerson algorithm:
1. Start with initial flow as 0.
2. While there exists an augmenting path from the source tothe sink:
Find an augmenting path using any path-finding algorithm, such as
breadth-first search or depth-first search.
" Determine the amount of flow that can be sent along the augmenting
path, which is the minimum residual capacity along the edges of the
path.
Increase the flow along the augmenting path by the
amount. determined
3. Return themaximum flow.
What ls Design
Methodology?
Design methodology refers to the
for a unique situation. development of a system or method
Today, the term is most often applied to
technological fields in reference to web design,software or
systems design. Various degree programs involve information
design methodology,
including those in the graphic and digital arts.
Travelling
Programming Salesman Problem using Dynamic
ravelling Salesman Problem (TSP):
Given a set of cities and the
shortestdistance
problem is to find the
once and returns to the possible between every pair of cities, the
route that visits every city
starting point. Note
between Hamiltonian Cycle the difference exactly
and
TSP. The
that visits every cityHamiltonian cycle problem is to
find if there exists a tour
t
Hamiltonian Tour
onysuch tours exist,exists (because the exactly once. Here we know
graph is
Cycle.
the problem is to complete) and in fact,
finda minimum weight Hamiltonian
20
10
15
25 30
35
Rules:
Goal:
Maximize the total value of the items in the knapsack.
method:
The above problem can be solved by using the following
X={1,0, 0, 1}
={0, 0, 0, 1}
={0, 1, 0, 1}
the possible combinations. 1 denotes that the item is completely picked and
The above are items so pOssible combinations will be:
item is picked. Since there are 4
Omeans that no
made by using the above
are 16 possible combinations that can be
2*= 16; So. There the combination that
Once all the combinations are made, we have to select
problem.
provides the maximum profit.
programming approach. In
Another approach to solve the problem is dynamicproblem is divided into sub-
programming approach, the complicated
dynamic sub-problem and the solution of the sub-
find the solution of a
problems, then we
problem will be used to
find the solution of a complex problem.
18
9
13
5
2
16
Source:0
Destination : 7
Shortest
Path :
0-3-6-7
|0 1 -3 2 -4
3 (0 -4 | -|
7 4 0 5 3
2
2 -1 -5 0 -2
8 5 1 6 0
036 o 00 0
3021 00
620142co
Co 1102 o 4
0 0 42 021
o 00 2co 201
o00 oo 4 110
shortest path.
Output - Matrix of all pair
0345677
3021344
4201323
5110233
633202I
742320|
743311I0
Algorithm
floydW arshal(cost)
Input - The cost matrix of given Graph.
Output - Matrix to for shortest path between any vertex to any vertex.
Begin
for k:=0 to n,do
for i :=0to n, do
for j :-0 to n, do
if cost[i,k] + cost[kj] < cost[i.j], then
cost[ij] = cost[i.k] + cost[kj]
done
done
done
display the current cost matrix
End
8queen problem
problem of placing eight queens on an 8x8
The eight queens problem is thethem
chessboard such that none of attack one another (no two are in the
generally, the n queens problem
same row, column, or diagonal). More There are different solutions for the
chessboard.
places n queens on an nxn
problem.
Explanation: backtracking algorithm to find a solution to
This pseudocode uses a
consists of placing 8 queens on a
the 8Queen problem, which queens threaten each other.
chessboard in such a way that no tWO then it
starts by placing a queen on the first column,
The algorithm
column and places aqueen in the first safe row of
proceeds to the next
that column.
If the algorithm
reaches the 8th column and al queens are placed in a
safe position, it prints the board and returns true.
If the alqorithm is unable to place a queen in asafe position in a certain
column, it backtracks to the previous column and triesa different row.
isSafe" function checks if it is safe to place aqueen on a certain row
The
andcolumn by checking if there are any queens in the same row,
diagonal or anti-diagonal.
It'sworth to notice that this is just a high-level pseudocode and it might
and
need to be adapted depending on the specific implementation
language you are using.
Complexity O((m q) log^2 n)
Time
Space Complexity : O((m + q) log n)