Ada Report 2
Ada Report 2
1. INTRODUCTION
2. ALGORITHM AND FLOWCHART
3. PROGRAM
4. MATHEMATICAL ANALYSIS
5. INPUT AND OUTPUT SPECIFICATION
6. CODE DEMONTRATION
DIJKSTRA algorithm
INTRODUCTION:
Dijkstra’s Algorithm is a fundamental graph traversal technique used to find the shortest path
between a source vertex and all other vertices in a weighted graph with non-negative edge
weights. Developed by Edsger W. Dijkstra in 1956, this algorithm is widely used in routing and
navigation systems, network optimization, and AI pathfinding.
In the context of Analysis and Design of Algorithms, Dijkstra’s Algorithm is classified as a
greedy algorithm because it makes the locally optimal choice at each step by selecting the node
with the minimum tentative distance. It gradually builds the shortest path tree by updating the
shortest distance from the source to all other nodes.
Its importance lies in its efficiency and practical relevance for problems modeled as weighted
graphs, such as road networks, data routing, and scheduling.
The single-source shortest-paths problem:
for a given vertex called the source in a weighted connected graph, find shortest paths to all its
other vertices. It is important to stress that we are not interested here in asingle shortest path that
starts at the source and visits all the other vertices. This would have been a much more difficult
problem .The single-source shortest-paths problem asks for a family of paths, each leading from
the source to a different vertex in the graph, though some paths may, of course, have edges in
common.
A variety of practical applications of the shortest-paths problem have made the problem a very
popular object of study. The obvious but probably most widely used applications are
transportation planning and packet routing in communication networks, including the Internet.
Multitudes of less obvious applications include finding shortest paths in social networks, speech
recognition, document formatting, robotics, compilers, and airline crew scheduling. In the world
of entertainment , one can mention pathfinding in video games and finding best solutions to
puzzles using their state-space graphs .
This algorithm is applicable to undirected and directed graphs with nonnegative weights only.
Since in most applications this condition is satisfied, the limitation has not impaired popularity of
Dijkstra’s algorithm.
ALGORITHM:
//Dijkstra’s algorithm for single-source shortest paths
//Input: A weighted connected graph G = V,Ewith nonnegative weigh// and its vertex s
//Output: The length dv of a shortest path from s to v
// and its penultimate vertex pv for every vertex v in V
Initialize(Q) //initialize priority queue to empty
for every vertex v in V
dv ← ∞; pv ← null
Insert(Q, v, dv) //initialize vertex priority in the priority queue
ds ← 0; Decrease(Q, s, ds) //update priority of s with ds
VT ← ∅
for i ← 0 to |V | − 1 do
u∗ ← DeleteMin(Q) //delete the minimum priority element
VT ← VT ∪ {u∗}
for every vertex u in V − VT that is adjacent to u∗ do
if du∗ + w(u∗, u) < du
du ← du∗ + w(u∗, u); pu ← u∗
Decrease(Q, u, du)
PROBLEM:
PROGRAM:
#include <stdio.h>
d[i] = c[s][i];
v[i] = 0;
v[s] = 1;
min = 999;
min = d[j];
u = j;
}v[u] = 1;
}
}
int main() {
scanf("%d", &n);
scanf("%d", &c[i][j]);
scanf("%d", &s);
dijkstra(c, n, s, d);
return 0;
}
OUTPUT:
Enter n values:
4
Enter the graph data:
0 1 999 3
1 0 1 999
999 1 0 1
3 999 1 0
Code Demonstration:
🧮 Step-by-Step Execution:
o Update:
o Update:
MATHEMATICAL ANALYSIS:
Mathematical Formula:
Relaxation: O(m)O(m)O(m)