Daa All Algorithm
Daa All Algorithm
Step 1 - Begin
Step 2 - If N = 0 OR C = 0 Then
(ii) Go to Step 7
(v) Go to Step 7
Step 5 - Else
(iii) Go to Step 7
Step 6 - Print "No solution" (This won’t typically happen with valid inputs)
Step 7 – Exit
Step 2 - If N = 1 Then
(ii) Go to Step 7
(iii) CurrentCost = Cost1 + Cost2 + (P[0] * P[i + 1] * P[N]) (Total cost with split at i)
(vi) i = i + 1
Step 7 – Exit
3) PRIMS ALGORITHM-
Step 1 - Begin
Step 3 - Create Visited array, set Visited[i] = 1 (mark vertex 0 as visited), all others = 0
MinWeight = G[j][k]
u=j
v=k
(a) Print "Edge ", u, " - ", v, " with weight ", MinWeight
Step 8 – Exit
4) KRUSKAL ALGORITHM-
Step 1 - Begin
Step 4 - Create Parent array, set Parent[j] = j for j from 0 to N-1 (each vertex is its own set)
(i) Print "Edge ", G[i][0], " - ", G[i][1], " with weight ", G[i][2]
(v) i = i + 1
Step 10 – Exit
5) DIJKSTRA ALGORITHM-
Step 1 - Begin
MinDist = Distance[j]
Step 7 - i = i + 1
Step 9 – Exit
6) GRAPH COLORING-
Step 1 - Begin
Step 5 - (i) Create Available array of size N, set all Available[c] = 1 (all colors available)
Step 6 - i = i + 1
Step 7 – Exit
Step 3 - Create Visited array, set Visited[i] = 1 (mark vertex 0 as visited), all others = 0
MinDist = G[i][j]
(c) Visited[Next] = 1
Step 10 – Exit
(b) Go to Step 8
(ii) MinCost = ∞
Step 7 - i = i + 1
Step 8 - Print "Minimum distance = ", DP[1][0] (Mask = 1 means only 0 visited initially)
Step 9 – Exit
9) FLOYD WARSHALL-
Step 1 - Begin
For v = 0 to N-1:
Step 6 - i = i + 1
For v = 0 to N-1:
Step 9 - Exit
10) N-QUEEN METHOD-
Step 1 - Begin
Step 3 - Create Board array of size N, set all Board[i] = -1 (no queen placed)
Step 5 - (i) col = Board[i] + 1 if Board[i] ≠ -1, else col = 0 (Start or continue column search)
Else
(c) Else
Go to Step 8
Step 9 - Exit
Step 4 - MaxDeadline = 0
Step 7 - i = i + 1
Step 8 - Create Slot array of size MaxDeadline, set all Slot[i] = -1 (no job scheduled)
Step 9 - TotalProfit = 0, i = 0
Step 11 - (i) slot = J[i][1] - 1 (Start from latest slot before deadline)
If Slot[slot] = -1 Then
(c) Go to Step 12
Else
Step 12 - i = i + 1
Step 16 – Exit
Where:
Step 1 - begin
(i) lps[0] = 0
(ii) len = 0
(iii) k = 1
(3) k = k + 1
(b) else
(2) else
(i) lps[k] = 0
(ii) k = k + 1
(i) i = i + 1
(ii) j = j + 1
(iii) if j = M then
(b) j = lps[j - 1]
(i) if j ≠ 0 then
(a) j = lps[j - 1]
(ii) else
(a) i = i + 1
Step 8 – exit
Where:
V = number of vertices
S = source vertex
Step 1 - begin
(ii) distance[S] = 0
(2) go to step 7
Step 7 – exit
14) Ford-Fulkerson algorithm-
FordFulkerson(G, V, S, T)
Where:
V = number of vertices
S = source vertex
T = sink vertex
Step 1 - begin
Step 3 - max_flow = 0
(a) go to step 6
Step 7 – exit
15) BFS-
BFS(G, V, S)
Where:
G = graph (adjacency list or matrix)
V = number of vertices
S = source vertex
Step 1 - begin
Step 7 -
Step 8 – exit
16) DFS-
DFS(G, V, S)
Where:
V = number of vertices
S = source vertex
Step 1 - begin
Step 5 – exit
Where:
Step 1 - begin
Step 2 - i = 0
Step 4 -
(i) j = 0
(iv) j = j + 1
Step 5 - i = i + 1
Step 7 – exit
Where:
Step 2 - i = 1
Step 4 -
(ii) j = i - 1
(iii) repeat step (iv) while j >= 0 AND LA[j] > key
(iv)
(b) j = j - 1
Step 5 - i = i + 1
Step 7 – exit
Where:
Step 1 - begin
Step 2 - i = 0
Step 4 -
(i) min_idx = i
(ii) j = i + 1
(a) min_idx = j
(v) j = j + 1
Step 5 - i = i + 1
Step 7 – exit
Where:
Step 1 - begin
(i) go to step 7
Step 3 - mid = N / 2
Step 4 -
(2) i = i + 1
(b) else
(2) j = j + 1
(c) k = k + 1
(b) i = i + 1
(c) k = k + 1
(b) j = j + 1
(c) k = k + 1
Step 7 – exit
Where:
Step 1 - begin
(i) go to step 7
(ii) i = low - 1
(iii) j = low
(1) i = i + 1
(b) j = j + 1
(vi) return i + 1
Step 7 - exit