Document 1
Document 1
the set of
elements already covered from X is E. E phi.3 .repeat steps 4 and 5 while E!=X. 4.Select a
set Si that contains maximum numer of uncovered elements. add this set to set cover
C.CCUSi5. The set of uncovered elements from X is added to E each time a set is
selected.EEUSi6. Return C and exit Vertex Cover Problem :Find Vertex cover of
minimum size.Algorithm:1.Initialize the vertex cover C to be null. Cphi 2.The set of edges in
G is E. 3. Repeat steps 4 to 6 till the set of edges E is empty .4. Choose an arbitrary edge
(u,v) of E. 5.Add the endpoints u, v to vertex cover C. 6. Remove every edge incident on either
u or v from the set of edges E. 7.return C and Exit.
Knapsack Problem Statement A thief robbing a store and can carry a maximal weight of
w into their knapsack. There are n items and ith item weigh w, and is worth v, dollars. What
items should thief take?• There are two versions of problem. Objects(0)1,2,3,4,5,6,7Profits
(P)10,5,15,7,6,18,3Weight (W),2,3,5,7,1,4.1
Ford Fulkerson algorithm: 1)for each edge (u, v) in E[G]. 2).do f[u, v] = 0. 3)
f[v, u] = 0. 4) while there exists a path p from s to t in the residual network Gf 5) do Cf(p) =
min [ Cf(u, v) |(u,v) is in p}. 6) for each edge (u, v) in p. 7)do f[u, v] = f[u, v] + c_{f}(p)8)f[v,
u] =- hat f [u,v] pseudo code 1)iniitlaoze flow f to0 .2)while there exits an augmenting path
p 3)do augment flow f along p. 4)return f. Introduction network Practical examples of
a network- liquids flowing through pipes- parts through assembly lines current through
electrical network- information through communication network - goods transported on the
road...1.Sink:node with net inflow consumption point.2.capecity:maximum flow on an
edge.3.sporce: node with net outflow production pointFlow propertiesFlow in G = (V, E)
f / V * V -> R with 3 properties:1) Capacity constraint: For all u .v belong to V: f(u, v) <= c(u,
v)2) Skew symmetry:For all u ,v beong to V f(u, v) = - f (v, u)3) Flow conservation: For all u
belong to V backslash\ s.t\ \ s .t\ : Sigma f(u, v) = 0The max-flow problemInformal
definition of the max-flow problem:What is the greatest rate at which material can be shipped
from the source to the sink without violating any capacity contraints?Formal definition of the
max-flow problem:The max-flow problem is to find a valid flow for a given weighted directed
graph G, that has the maximum value over all valid flows.
Bubble Sort Algorithm :Input is the array A with n elementsStep 1. Read the
array AStep 2. Repeat steps 3 to 4 for i = 1 to n-1Step 3. Repeat step 4 for j= 0 to n-i-
1Step 4. If A [j] > A[j+1] then interchange A[j] and A[j+1] using temporary variable.Step 5.
Return A and Exit
SELECTION SORT Algorithm :Input is the array A of n elements.Step 1. Read the array A
Step 2. Repeat steps 3 to 6 for i = 0 to n-1Step 3. Set min = A[i] and set loc = I
Step 4. Repeat step 5 for j = i + 1 to N – 1, Step 5. If min > A[J] then, set min = A[J], set loc =
JStep 6. Interchange A[i] and A[loc] using temporary variable Step 7. Return A and exit
ALGORITHM
code obtained from http://www.geeksforgeeks.org/radix-sort/ */static void countSort(int arr[],
int n, int exp){int output[] = new int[n]; int i;int count[] = new int[10]; Arrays.fill(count,0); for (i
= 0; i < n; i++) count[ (arr[i]/exp)%10 ]++; for (i = 1; i < 10; i++)count[i] += count[i - 1]; for (i =
n - 1; i >= 0; i--) {
HEAPSORT
ALGORITHM:BUILD-MAX-HEAP(A)2.for i<-length downto 2 3.do exchange A[i]<->A[i]
4.heap-size[A]<-heap-size[A]-1. 5.Max-heapify(A,1)