Single Source Shortest Path Problem
Single Source Shortest Path Problem
CONTENT
Introduction
Definition
Basic Concept
Methodology
Application
Complexity
Explication
Data stature
Advantage
Disadvantage
INTRODUCTION
The Single-Source Shortest Path (SSSP) problem consists of finding the shortest
paths between a given vertex v and all other vertices in the graph. Algorithms for
unweighted graphs or weighted graphs Dijkstra solve this problem. One can use the
Dijkstra algorithm to each vertex in the graph in order to solve the problem.
Dijkstra algorithm solves the shortest-path problem for any
✓ Weighted graphs,
✓ Directed graphs
✓ Having Non-Negative weights.
✓ It can handle graphs consisting of cycles, but negative weights will cause this algorithm
to produce incorrect results
INTRODUCTION
Dijkstra's algorithm works correctly, because all edge weights are non-negative, and
the vertex with the least shortest-path estimate is always chosen.
In the first iteration of the while loop, the source s is chosen and its adjacent vertices
have their est(v) set to
w((s, v)).
In the second iteration, the vertex u with minimal w((s, u)) will be selected; then
those edges incident from u will be relaxed. Clearly, there exists no shorter path
from s to u than the single edge (s, u), because all weights are not negative, and any
path traced that uses an intermediate vertex is longer.
Continuing this reasoning brings us to the conclusion that the algorithm, indeed,
computes the shortest paths.
DEFINITION
Now that you know more about this algorithm, let's see how it works behind the scenes with a a step-by-
step example.
We have this graph:
METHODOLOGY
METHODOLOGY
Set s as 0 and all others as ∞ because all other vertices are not visited yet.
Unvisited nodes: {0,1,2,3,4,5,6}
Since we are choosing to start at node 0 we can mark this node as visited. Equivalently, we cross it off
from the list of unvisited nodes and add a red border to the corresponding node.
Node 3 and 2 are both adjacent to nodes that are already in the path because they are directly
connected to node 0 and 1 respectively,
as you can see below. These are the nodes that we will analyze in the next
METHODOLOGY
To find the distance from the source node to another node (in this case, node 3.
we add the weights of all the edges that form the shortest path to reach that node:
METHODOLOGY
Now we need to repeat the process to find the shortest path from the source node to the new adjacent
node, which is node 3.
You can see that we have two possible paths
0 -> 1 -> 3 or
0 -> 2 -> 3.
METHODOLOGY
0 -> 2 -> 3,
we would need to follow two edges
•For node 4: the distance is 17 from the path 0 -> 1 -> 3 ->
4.
•For node 5: the distance is 22 from the path 0 -> 1 -> 3 ->
5.
METHODOLOGY
There are three different paths that we can take to reach node 5 from the
nodes that have been added to the path:
•Option 1: 0 -> 1 -> 3 -> 5 with a distance of 22 (2 + 5 + 15).
•Option 2: 0 -> 1 -> 3 -> 4 -> 5 with a distance of 23 (2 + 5 + 10 + 6).
•Option 3: 0 -> 1 -> 3 -> 4 -> 6 -> 5 with a distance of 25 (2 + 5 + 10 + 2 + 6).
EXAMPLE
u v
1
10
9
2 3
s 0 4 6
5 7
2
x y
EXAMPLE
u v
1
10
10
9
2 3
s 0 4 6
5 7
5
2
x y
EXAMPLE
u v
1
8 14
10
9
2 3
s 0 4 6
5 7
5 7
2
x y
EXAMPLE
u v
1
8 13
10
9
2 3
s 0 4 6
5 7
5 7
2
x y
EXAMPLE
u v
1
8 9
10
9
2 3
s 0 4 6
5 7
5 7
2
x y
EXAMPLE
u v
1
8 9
10
9
2 3
s 0 4 6
5 7
5 7
2
x y
SUMMARY
• Graphs are used to model connections between objects, people, or entities. They
have two main elements: nodes and edges. Nodes represent objects and edges
represent the connections between these objects.
• Dijkstra's Algorithm finds the shortest path between a given node (which is called the
"source node") and all other nodes in a graph.
• This algorithm uses the weights of the edges to find the path that minimizes the total
distance (weight) between the source node and all other nodes.
APPLICATIONS
Min Heap
Approach
Greedy Approach
ADVANTAGES