0% found this document useful (0 votes)
13 views11 pages

Shortest Path Modeling

The document discusses shortest path modeling, focusing on algorithms such as Dijkstra's, Bellman-Ford, and Floyd-Warshall for finding efficient routes in graphs. Dijkstra's algorithm is highlighted for its simplicity and effectiveness in graphs with non-negative edge weights. The document also covers algorithm steps, a sample program implementation, and real-life applications like navigation and network routing.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views11 pages

Shortest Path Modeling

The document discusses shortest path modeling, focusing on algorithms such as Dijkstra's, Bellman-Ford, and Floyd-Warshall for finding efficient routes in graphs. Dijkstra's algorithm is highlighted for its simplicity and effectiveness in graphs with non-negative edge weights. The document also covers algorithm steps, a sample program implementation, and real-life applications like navigation and network routing.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 11

SHORTEST PATH

MODELING
- BY SUSHMITHA Y S
INTRODUCTIO
N
o Shortest path modeling
involves finding the most
efficient route between
two points in a network.
o Shortest path algorithm
operates on graphs ,
which consist of
nodes(representing
locations) and
edges(representing
connections or routes).
o Edges can have weights ,
representing the cost or
distance associated with
that edge.
ALGORITHMS FOR SHORTEST PATH MODELING :
 Dijkstra’s Algorithm: Finds the shortest paths from a starting node
to all other reachable nodes in a graphs with non negative edge
weights.

 Bellman-Ford Algorithm: Can handle graphs with negative edge


weights and detects negative cycles.

 Floyd-Warshall Algorithm: Finds Shortest paths between all pairs


of nodes in a graph.
DIJKSTRA’S ALGORITHM :
 Dijkstra’s Algorithm is often the first choice due to its simplicity and
efficiency for graphs with non-negative edges weights.

 It is used to solve Optimization problem involves finding the best


solution(minimum or maximum) .

 Dijkstra’s Algorithm uses a Greedy Approach to find the shortest


paths in a weighted graph from a starting node to all other nodes.
ALGORITHM STEPS :
1. Initialize:
set the distance to the source as 0 and all other vertices as infinity.
mark all vertices as unvisited.

2. Choose the unvisited vertex with the smallest distance.

3. Update distance of its neighboring vertices:


if the new distance(current distance + edge weight) is less than
the previously known
distance, update it.

4. Mark the current node as visited.

5. Repeat steps 2-4 until all vertices are visited.


PROGRAM:
#include<stdio.h> if(v[j]==0 && d[j]<min)
#define INF 999 {
void dijkstra(int c[10][10],int n,int s,int d[10]) min=d[j];
{ u=j;
int v[10],min,u,i,j; }
for(i=1;i<=n;i++) v[u]=1;
{ for(j=1;j<=n;j++)
d[i]=c[s][i]; if(v[j]==0 && (d[u]+c[u]
v[i]=0; [j])<d[j])
} d[j]=d[u]+c[u][j];
v[s]=1; }
for(i=1;i<=n;i++) }
{
min=INF; int main()
for(j=1;j<=n;j++) {
int c[10][10],d[10],i,j,s,sum,n;
printf("\nEnter n value:"); Output:
scanf("%d",&n); Enter n value:6
printf("\nEnter the graph data:\n"); Enter the graph data:
for(i=1;i<=n;i++) 0 15 10 999 45 999
for(j=1;j<=n;j++) 999 0 15 999 20 999
scanf("%d",&c[i][j]); 20 999 0 20 999 999
printf("\nEnter the souce node:"); 999 10 999 0 35 999
scanf("%d",&s); 999 999 999 30 0 999
dijkstra(c,n,s,d); 999 999 999 4 999 0
for(i=1;i<=n;i++) Enter the souce node:2
printf("\nShortest distance from %d to %d is Shortest distance from 2 to 1 is 35
%d",s,i,d[i]); Shortest distance from 2 to 2 is 0
return 0; Shortest distance from 2 to 3 is 15
} Shortest distance from 2 to 4 is 35
Shortest distance from 2 to 5 is 20
Shortest distance from 2 to 6 is 999
ANALYSIS :
1.Input: A weighted connected graph with non negative weights and its vertex s

2.Output : A shortest path from s to v and penultimate vertex pv for every vertex v

3.Time Efficiency (Time Complexity):


Key Parameters:
•V = number of vertices
•E = number of edges
• For array or list : O(V^2)
• For adjacency list: O((V+E)log⁡V)

4. Space Efficiency (Space Complexity):


•Adjacency List Implementation: O(V+E)
•Adjacency Matrix Implementation:O(V^2)
REAL LIFE EXAMPLES

Navigation and GPS Game


system Development
Network Routing
CONCLUSION:

Dijkstra’s algorithm is a reliable and efficient


technique for modeling shortest paths in weighted
graphs with non-negative edges. Its simplicity and
guaranteed optimality make it a cornerstone of
many real-world systems, although for very large or
dynamic graphs, more advanced variations or
heuristics may offer better performance.
THANK YOU!

You might also like