0% found this document useful (0 votes)
24 views17 pages

Greedy

The document describes the greedy method for solving optimization problems, focusing on the Fractional Knapsack problem and Prim's algorithm for minimum spanning trees. It includes algorithms, C program implementations, and discusses time and space complexities for both methods. The conclusion emphasizes maximizing profit and minimizing weight in the Fractional Knapsack problem while also detailing the process for constructing a minimum spanning tree using Prim's algorithm.

Uploaded by

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

Greedy

The document describes the greedy method for solving optimization problems, focusing on the Fractional Knapsack problem and Prim's algorithm for minimum spanning trees. It includes algorithms, C program implementations, and discusses time and space complexities for both methods. The conclusion emphasizes maximizing profit and minimizing weight in the Fractional Knapsack problem while also detailing the process for constructing a minimum spanning tree using Prim's algorithm.

Uploaded by

thanaitpooja09
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Page no:

EXP 2 GREEDY METHOD


DATE:

THEORY: The greedy method suggests that one can devise an algorithm
that works in stages, considering one input at a time. At each stage, a
decision is made regarding whether a particular input is an optimal
solution. This is done by considering the inputs in an order determined by
some selection procedure.
Most of these problems have n inputs and require us to obtain a subset
that satisfies some constraints. Any subset that satisfies these constraints
is called a feasible solution. A feasible solution is found out that either
maximises or minimises a given objective function. A feasible solution that
does this is called an optimal solution.
The selection procedure is based on some optimisation measure. This
measure may be an objective function. This version of greedy technique is
called the subset paradigm. For problems that do not call for the selection
of an optimal subset,in the greedy method we make decisions by
considering the inputs in some order. Each decision is made using an
optimization criterion that can be computed using decisions already
made. This version of the greedy method is called the ordering paradigm.
Fractional knapsack, Prim’s Algorithm, Kruskal’s algorithm are ordering
paradigm.
The function Select selects an input from a[ ] and removes it.The selected
input's value is assigned to x. Feasible is a Boolean-valued function that
determines whether x can be included into the solution vector.The
Function Union combines x with the solution and updates the objective
function.
Algorithm Greedy(a,n)
// a[l:n] contains the n inputs.{
solution := 0; // Initialize the solution.
for i := 1 to n do
{
x := Select(a); // Select an element from the input set.

if Feasible(solution, x) then
{
solution := Union(solution, x); // Merge x into the current solution.
}

POOJA THANAIT 23B-CO-042 PR NO: 202311426


Page no:

return solution;
}
AIM : Write a C Program to find minimum cost using Fractional
Knapsack .

PROBLEM STATEMENT: Given n objects and a knapsack bag. Object i


has a weight wi and the knapsack has a capacity m. If a fraction xi, 0 <xi
< 1,of object i is placed into the knapsack, then a profit of pixi is earned.
The objective is to obtain a filling of the knapsack that maximizes the total
profit earned. Since the knapsack capacity is m, we require the total
weight of all chosen objects to be at most m.
ALGORITHM :
Algorithm Greedyknapsack (m,n) {
for i:=1 to n do
x[i]:= 0;
u: =m;
for i:=1 to n do
{ if (w[i]> u) then break;
x[i]:= 1.0;
u:=u-w[i];
}
if (i<=n) then x[i]:= u/w[i];
}

TIME COMPLEXITY:
Sorting Step: The algorithm first sorts items based on their value/weight
ratio in descending order. Using an efficient sorting method (like Merge
Sort or Quick Sort), this step takes O(n log n) time.
Selection Step: After sorting, the algorithm iterates through the items and
picks them one by one, either fully or fractionally, until the knapsack is
full. This iteration runs in O(n) time.
SPACE COMPLEXITY:
If an in-place sorting algorithm like Quick Sort is used, the space required
is O(1) (excluding recursive stack space). However, if an extra data
structure is used for sorting (like Merge Sort), it may take O(n) space.

POOJA THANAIT 23B-CO-042 PR NO: 202311426


Page no:

PROGRAM :
#include <stdio.h> index = j;
#include <limits.h> }}
if (w[index] > u) break;
void knapsack(int m, int n) { x[index] = 1.0;
float x[n], wixi = 0.0, pixi = 0.0, u; u -= w[index];
float w[n+1], p[n+1], f[n+1], }
op[n+1]; if (i <= n) x[index] = u / w[index];
int max, min, index, i, j; for (i = 1; i <= n; i++) printf("%.1f
", x[i]);
printf("Enter the weights of the wixi = pixi = 0;
items (1 to %d):\n", n); for (i = 1; i <= n; i++) {
for (i = 1; i <= n; i++) { wixi += (x[i] * w[i]);
printf("Weight of item %d: ", i); pixi += (x[i] * p[i]);
scanf("%f", &w[i]); }
} printf("%.2f %.2f\n", wixi, pixi);
printf("Enter the profits of the
items (1 to %d):\n", n); printf("Least weight:\t");
for (i = 1; i <= n; i++) { for (i = 1; i <= n; i++) x[i] = 0.0;
printf("Profit of item %d: ", i); u = m;
scanf("%f", &p[i]); for (i = 1; i <= n; i++) {
} min = INT_MAX;
printf("Enter the fractions of the for (j = 1; j <= n; j++) {
items (1 to %d):\n", n); if (w[j] < min && x[j] != 1) {
for (i = 1; i <= n; i++) { min = w[j];
printf("Fraction of item %d: ", i); index = j;
scanf("%f", &f[i]); }
} }
if (w[index] > u) break;
for (i = 1; i <= n; i++) { x[index] = 1.0;
wixi += (f[i] * w[i]); u -= w[index];
pixi += (f[i] * p[i]); }
} if (i <= n) x[index] = u / w[index];
printf("\t\tx1 x2 x3 x4 x5 x6 for (i = 1; i <= n; i++) printf("%.1f
x7 x8 x9 x10 wixi pixi\n"); ", x[i]);
printf("\t\t1/2 1/2 1/3 1/3 1/4 wixi = pixi = 0;
1/5 1/6 1/7 1/8 1/9 %.2f %.2f\n", for (i = 1; i <= n; i++) {
wixi, pixi); wixi += (x[i] * w[i]);
pixi += (x[i] * p[i]);
printf("Maximum profit:\t"); }
for (i = 1; i <= n; i++) x[i] = 0.0; printf("%.2f %.2f\n", wixi, pixi);
u = m;
for (i = 1; i <= n; i++) { printf("pi/wi:\t\t");
max = INT_MIN; for (i = 1; i <= n; i++) {
for (j = 1; j <= n; j++) { op[i] = p[i] / w[i];
if (p[j] > max && x[j] != 1) { x[i] = 0.0;
max = p[j]; }

POOJA THANAIT 23B-CO-042 PR NO: 202311426


Page no:

u = m; }
for (i = 1; i <= n; i++) { printf("%.2f %.2f\n", wixi, pixi);
max = INT_MIN; }
for (j = 1; j <= n; j++) {
if (op[j] > max && x[j] != 1) { int main() {
max = op[j]; int m, n;
index = j;
} printf("Enter the capacity of the
} knapsack: ");
if (w[index] > u) break; scanf("%d", &m);
x[index] = 1.0;
u -= w[index]; printf("Enter the number of items:
} ");
if (i <= n) x[index] = u / w[index]; scanf("%d", &n);
for (i = 1; i <= n; i++) printf("%.1f
", x[i]); knapsack(m, n);
wixi = pixi = 0;
for (i = 1; i <= n; i++) { return 0;
wixi += (x[i] * w[i]); }
pixi += (x[i] * p[i]);

OUTPUT :

POOJA THANAIT 23B-CO-042 PR NO: 202311426


Page no:

CONCLUSION:- The program implements the Fractional Knapsack


problem, where it calculates the optimal solution by maximizing profit,
minimizing weight, and selecting items based on the profit-to-weight ratio.
It demonstrates three strategies: maximizing profit, minimizing weight,
and optimizing the profit-to-weight ratio.
AIM : Write a C Program to find minimum cost using Prim’s
algorithm.
PROBLEM STATEMENT: E is the set of edges in graph G. cost[1:n , 1:n]
is the cost adjacency matrix of an n vertex graph such that cost[i,j] is
either a positive real number or infinity if no edge (i,j) exists. A minimum
spanning tree is computed and stored as a set of edges in the array t. The
final cost is returned.

ALGORITHM :

Algorithm Prim (E, cost, n, t)


{ let (k, l) be an edge of min cost
mincost:= cost [k,l];
t[1,1]:=k; t[1,2]:=l;
for i:=1 to n do
if (cost [i,l] <cost[i,k]) then
near[i]=l;
else near[i]:=k;
near[k]:= 0;
near[l]:= 0;
for i:=2 to n-ı do
{ let j be index such that
near [j] !=0 cost [j, near[j]] is min;
t[i,1]:=j;
t[i, 2]:= near [j] ;
mincost :=mincost + cost [j, near [j]];
near [j]:=0;
for k=1 to n do{
if (near [k] !=0 and (Cost [k, near[k] > Cost [k, j]) then
near [k]: =j;
}
return mincost;
}

TIME COMPLEXITY:
The time complexity of Prim’s algorithm is O(n²) using an adjacency matrix or
O(E log n) using a priority queue.
SPACE COMPLEXITY:
The space complexity is O(n²) for an adjacency matrix or O(n + E) for an
adjacency list.

POOJA THANAIT 23B-CO-042 PR NO: 202311426


Page no:

PROGRAM :
#include <stdio.h> printf("The cost matrix is:\n");
#define MAX 20 for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
int* getSmallestEdge(int E[14][3], int if (cost[i][j] == 99999)
edgeCount) { printf("%5s", "inf");
int min = 99999; else
int minIndex = -1; printf("%5d", cost[i][j]);
for (int i = 0; i < edgeCount; i++) }
if (E[i][2] < min && E[i][2] != - printf("\n");}
1) { printf("\n");
min = E[i][2]; }
minIndex = i; void printPrims(int near[], int
} cost[MAX][MAX]) {
return E[minIndex]; printf(" %10s %10s\n",
} "near[j]", "cost[j][near[j]]");
for (int i = 1; i <= 8; i++)
void printT(int t[MAX][2], int printf("near[%d]: %5d %9d\n",
currentSize) { i, near[i], near[i] == 0 ? 0 : cost[i]
printf("\nT matrix status (edges in [near[i]]);
MST):\n"); printf("\n");
printf("Index\t1\t2\n"); }
for (int i = 1; i <= currentSize; i+ int prims(int E[14][3], int cost[MAX]
+) [MAX], int n, int t[MAX][2], int
printf("%d\t%d\t%d\n", i, t[i][0], edgeCount) {
t[i][1]); int near[MAX];
} int mincost = 0;
createGraph(E, cost, n,
void createGraph(int E[14][3], int edgeCount);
cost[MAX][MAX], int n, int int* minEdge =
edgeCount) { getSmallestEdge(E, edgeCount);
for (int i = 1; i <= n; i++) { t[1][0] = minEdge[0];
for (int j = 1; j <= n; j++) t[1][1] = minEdge[1];
cost[i][j] = 99999; } mincost = cost[minEdge[0]]
for (int i = 1; i <= n; i++) [minEdge[1]];
cost[i][i] = 0; for (int i = 1; i <= n; i++) {
for (int i = 1; i <= edgeCount; i+ if (cost[i][minEdge[0]] < cost[i]
+) { [minEdge[1]])
int origin = E[i-1][0]; near[i] = minEdge[0];
int destination = E[i-1][1]; else
int weight = E[i-1][2]; near[i] = minEdge[1];
cost[origin][destination] = }
weight; near[minEdge[0]] =
cost[destination][origin] = near[minEdge[1]] = 0;
weight; printPrims(near, cost);
} printT(t, 1);

POOJA THANAIT 23B-CO-042 PR NO: 202311426


Page no:

for (int i = 2; i <= n-1; i++) { int main() {


int min = 99999; int E[14][3];
int j = 0; int cost[MAX][MAX];
for (int k = 1; k <= n; k++) int n = 8;
if (near[k] != 0 && cost[k] int t[MAX][2];
[near[k]] < min) { int edgeCount;
min = cost[k][near[k]]; printf("Enter the number of edges:
j = k; } ");
t[i][0] = j; scanf("%d", &edgeCount);
t[i][1] = near[j];
mincost += cost[j][near[j]]; printf("Enter the edges in the
printf("Mincost: %d\n\n", format (u v cost):\n");
mincost); for (int i = 0; i < edgeCount; i++)
near[j] = 0; {
for (int k = 1; k <= n; k++) printf("Edge %d: ", i + 1);
if (near[k] != 0 && cost[k][j] scanf("%d %d %d", &E[i][0],
< cost[k][near[k]]) &E[i][1], &E[i][2]);
near[k] = j; } int result = prims(E, cost, n, t,
printPrims(near, cost); edgeCount);
printT(t, i); printf("\nFinal minimum spanning
} tree cost: %d\n", result);
return mincost; }
}

OUTPUT:

POOJA THANAIT 23B-CO-042 PR NO: 202311426


Page no:

POOJA THANAIT 23B-CO-042 PR NO: 202311426


Page no:

CONCLUSION: The program implements Prim's Algorithm to find the


Minimum Spanning Tree (MST) of a graph. It takes as input the number of
vertices and the edges of the graph, including the cost of each edge. The
algorithm progressively selects the minimum cost edges to connect all the
vertices, ensuring no cycles are formed, and computes the MST.

POOJA THANAIT 23B-CO-042 PR NO: 202311426


Page no:

AIM : Write a C Program to find minimum cost using Kruskal’s


algorithm.
PROBLEM STATEMENT:
Given an undirected, weighted graph with n vertices and a set of edges E
with their respective weights, the task is to determine the Minimum
Spanning Tree (MST) using Kruskal’s Algorithm. The algorithm employs a
heap structure to efficiently extract the smallest edge, while a union-find
data structure helps prevent cycles and maintain connectivity. The goal is
to select n-1 edges that connect all vertices with the minimum possible
total weight. If a spanning tree cannot be formed, the algorithm returns
"No spanning tree"
ALGORITHM :

Algorithm kruskals (E, cost, n, t){ while (j<=n) do


construct a heap out of edge using { if ((j<n) & (a[j]>a[j+1] )then
Heapify. j = j + 1;
for i:=1 to n do } if(item<=a[j]) then break;
{ parent[i]:=-1; A[j/2]:=a[j];
i:=0; mincost := 0.0; J:=2j;
while ((i<=n-1) and (heap not }
empty)) do A[j/2]:=item;
{ }
Delete mincost edge (u,v), from
heap & reheapify using adjust. algorithm delmin( a, n, x) {
j=Find (u); if (n = 0) then
k=find (v); write("heap is empty");
if (j!=k) then { i:=i+1; return false;
t[I,1]: =u; t[I,2]: = v; }
mincost: = mincost + cost [u,v], X: = a[1];
} union (j, k); a[1]: = a[n];
} if (i!=n-1) then adjust(a, 1, n - 1);
write ("No spanning tree"), return true;
else }
return mincost;
} Algorithm find( i) {
while (parent[i] >= 0)
Algorithm heapify (a, n) i = parent[i];
{ for i := n/2 to step-1 do return i;
Adjust (a,i,n); }
}
Algorithm union( i, j) {
Algorithm Adjust (a, i,n) parent[i] = j;
{ j:=2i ; item:=a[i]; }

TIME COMPLEXITY:
The time complexity of Kruskal’s Algorithm is O(E log E), where E is the
number of edges

SPACE COMPLEXITY:

POOJA THANAIT 23B-CO-042 PR NO: 202311426


Page no:

The space complexity is O(E + V) for storing edges and union-find data.

PROGRAM :
#include <stdio.h> smallest = right;
#define MAX 20 if (smallest == index)
break;
typedef struct { Edge temp = heap[index];
int u, v, cost; heap[index] = heap[smallest];
} Edge; heap[smallest] = temp;
index = smallest;
Edge heap[MAX], t[MAX]; }
int parent[MAX], heapSize = 0; }
int cost[MAX][MAX];
Edge DeleteMin() {
int Find(int u) { Edge minEdge = heap[0];
while (parent[u] >= 0) heapSize--;
u = parent[u]; heap[0] = heap[heapSize];
return u; Adjust(0);
} return minEdge;
}
void Union(int u, int v) {
parent[v] = u; int Kruskal(Edge E[], int cost[][MAX],
} int n, Edge t[]) {
int i, j, k, mincost = 0;
void InsertHeap(Edge edge) { printf("%8s", " ");
heap[heapSize] = edge; for (i = 0; i < n; i++) {
int i = heapSize, p; printf("%5d", i + 1);
while (i > 0) { }
p = (i - 1) / 2; printf("%5s %5s", "j", "k");
if (heap[p].cost <= heap[i].cost) printf("\nparent: ");
break; for (i = 0; i < n; i++) {
Edge temp = heap[i]; parent[i] = -1;
heap[i] = heap[p]; printf("%5d", parent[i]);
heap[p] = temp; }
i = p; printf("\n");
} i = 0;
heapSize++; while ((i < n - 1) && (heapSize >
} 0)) {
Edge edge = DeleteMin();
void Adjust(int index) { j = Find(edge.u);
int smallest, left, right; k = Find(edge.v);
while (1) { if (j != k) {
left = 2 * index + 1; i++;
right = 2 * index + 2; t[i - 1] = edge;
smallest = index; mincost += edge.cost;
if (left < heapSize && Union(j, k);
heap[left].cost < }
heap[smallest].cost) printf("\nparent: ");
smallest = left; for (int h = 0; h < n; h++) {
if (right < heapSize && printf("%5d", parent[h]);
heap[right].cost < }
heap[smallest].cost)

POOJA THANAIT 23B-CO-042 PR NO: 202311426


Page no:

printf("%5d %5d", edge.u,


edge.v); Edge E[e];
printf("\n"); for (int i = 0; i < e; i++) {
printf("Mincost: %d\n", printf("Enter edge %d (u v cost):
mincost); ", i + 1);
} scanf("%d %d %d", &E[i].u,
if (i != n - 1) { &E[i].v, &E[i].cost);
printf("No spanning tree\n");
return -1; InsertHeap(E[i]);
} else { }
return mincost;
} for (int i = 0; i < MAX; i++)
} for (int j = 0; j < MAX; j++)
cost[i][j] = 0;
void printT(int n, Edge t[]) { for (int i = 0; i < e; i++) {
printf("Edge\t1\t2\n"); cost[E[i].u - 1][E[i].v - 1] =
for (int i = 0; i <= n - 2; i++) { E[i].cost;
printf("%d\t%d\t%d\n", i + 1, cost[E[i].v - 1][E[i].u - 1] =
t[i].u, t[i].v); E[i].cost;
} }
}
int minCost = Kruskal(E, cost, n,
int main() { t);
int n, e; if (minCost != -1) {
printf("\nMinimum Cost: %d\n",
printf("Enter the number of minCost);
vertices: "); printT(n, t);
scanf("%d", &n); }
printf("Enter the number of edges:
"); return 0;
scanf("%d", &e); }

OUTPUT :

POOJA THANAIT 23B-CO-042 PR NO: 202311426


Page no:

CONCLUSION:
Kruskal’s algorithm efficiently finds the Minimum Spanning Tree (MST) by
selecting edges in increasing order of weight while ensuring no cycles are
formed using the union-find data structure. By leveraging a heap-based
approach for edge selection, it maintains an optimal time complexity of
O(E log E), making it well-suited for large graphs. If a valid MST exists, the
algorithm returns its minimum cost; otherwise, it confirms that no
spanning tree can be formed. This approach is widely used in network
design, clustering, and optimization problems, proving its effectiveness in
various real-world applications

POOJA THANAIT 23B-CO-042 PR NO: 202311426


Page no:

AIM : Write a C Program to find minimum cost using shortest path


algorithm.
PROBLEM STATEMENT: Given a directed graph G = (V,E),a weighting
function cost for the edges of G, and a source vertex q. The problem is to
determine the shortest paths from v0 to all the remaining vertices of G. It
is assumed that all the weights are positive. The shortest path between vo
and some other node v is an ordering among subset of the edges.

ALGORITHM :
Algorithm shortestpath (v, cost, dist, n)
{ for i:=1 to n do
{ s[i] = false;
dist [i]:= cost [v, i]; }
dist [v]:= 0;
S[v] = true;
for i:= 2 to n do
{ choose u from among those vertices not in s such that dist [u] is min
s[u]:= true;
for each w adjacent to u with s[w]:=false do
{ if( dist [w]> dist [u] + cost [u,w] ) then
dist [w]= dist [u] + cost [u,w] ;}
}
}

TIME COMPLEXITY:
The time complexity of this Dijkstra-based algorithm is O(n²) using an adjacency
matrix, and can be improved to O(E log n) with a priority queue.

SPACE COMPLEXITY:
The space complexity is O(n²) due to the adjacency matrix representation.

PROGRAM :

POOJA THANAIT 23B-CO-042 PR NO: 202311426


Page no:

#include <stdio.h> if (!s[w] && cost[u][w] != INF &&


#include <stdbool.h> dist[u] + cost[u][w] < dist[w]) {
#define INF 100 dist[w] = dist[u] + cost[u][w];
int n = 8; parent[w] = u;
}
void shortestPath(int v, int cost[n][n], }
int dist[n], int parent[8]) { printf("Iteration %d: , u = %d\n", i +
bool s[n]; 1, u + 1);
int i, u, w; for (int j = 0; j < n; j++) { if
for (i = 0; i < n; i++) { (s[j] == true)
s[i] = false; printf("s[%d]: ", j + 1);
dist[i] = cost[v][i]; } printf("True\n");
parent[i] = (cost[v][i] == INF) ? -1 : for (int j = 0; j < n; j++) {
v; if (s[j] == false)
} dist[v] = 0; printf("s[%d]: ", j + 1);
s[v] = true; } printf("False\n");
parent[v] = -1; printf("\n");
for (i = 1; i < n; i++) { int for (int j = 0; j < n; j++) {
minDist = INF; if (dist[j] != INF && (s[j] == true &&
u = -1; s[u] == true)){
for (w = 0; w < n; w++) { printf("\033[1;31mdist [%d]: %d\
if (!s[w] && dist[w] < minDist) { 033[0m\n", j + 1, dist[j]);
continue;
minDist = dist[w]; } if (dist[j] == INF)
u = w; printf("dist [%d]: INF\n", j + 1);
} else
} printf("dist [%d]: %d\n", j + 1,
if (u == -1) break; dist[j]);
if (i ==1) { } printf("\n\n"); }
printf("Iteration %d: , v = %d\n", i,
u); }
for (int j = 0; j < n; j++) {
if (s[j] == true) void printPath(int parent[], int j) {
printf("s[%d]: ", j + 1); if (parent[j] == -1) {
} printf("True\n"); printf("%d", j + 1);
for (int j = 0; j < n; j++) { return;
if (s[j] == false) }
printf("s[%d]: ", j + 1); } printPath(parent, parent[j]);
printf(" -> %d", j + 1);
printf("False\n\n"); }
for (int j = 0; j < n; j++) { int main() { int v = 0;
if (dist[j] != INF && s[j] == true){ int dist[8], parent[8];
printf("\033[1;31mdist [%d]: %d\ int cost[8][8] = {
033[0m\n", j + 1, dist[j]); {INF, 40, 20, 10, 50, INF, 60, INF},
continue; {INF, INF, 1, INF, 5, INF, INF, INF},
} if (dist[j] == INF) {INF, INF, INF, INF, 2, 10, 2, INF},
printf("dist [%d]: INF\n", j + 1); {INF, INF, 5, INF, INF, INF, 5, INF},
else printf("dist [%d]: {INF, INF, INF, INF, INF, 3, INF, 5},
%d\n", j + 1, dist[j]); {INF, INF, INF, INF, INF, INF, 3, 5},
} {INF, INF, INF, INF, INF, INF, INF, 3},
printf("\n\n"); {INF, 2, 1, 5, INF, INF, INF, INF}
} s[u] = true; };
for (w = 0; w < n; w++) { shortestPath(v, cost, dist, parent);

POOJA THANAIT 23B-CO-042 PR NO: 202311426


Page no:

printf("Shortest paths from vertex else { printPath(parent, i);


%d:\n", v + 1); printf(" = %d\n", dist[i]);
for (int i = 0; i < n; i++) { }
if (i == v) continue; }
if (dist[i] == INF)
printf("%d -> %d = INF\n", v + 1, i +
1);

OUTPUT:

POOJA THANAIT 23B-CO-042 PR NO: 202311426


Page no:

CONCLUSION:-
The program implements Dijkstra's Algorithm to find the shortest path
from a source vertex to all other vertices in a weighted graph. The graph
is represented by an adjacency matrix, and the algorithm uses a greedy
approach to iteratively select the closest unvisited vertex to the source,
updating the shortest path estimates.

REFERENCES:
Fundamentals of Computer Algorithms by Ellis Horowitz, Sartaj Sahni,
Sanguthevar Rajasekaran, 2nd Edition, Publication: Universities Press.
Referred page nos:261,264.

POOJA THANAIT 23B-CO-042 PR NO: 202311426

You might also like