Download as pdf or txt
Download as pdf or txt
You are on page 1of 1

Graph algorithms

Your name here


November 12, 2020

1 The Dijkstra’s algorithm


The Dijkstra’s algorithm [1] is used for finding shortest paths in a graph G = ⟨V, E⟩. The characteristics of the
Dijkstra’s algorithm variant presented here are as follows:

• Works on a weighted graph.

• Only non-negative weights are allowed.


• Calculates minimum distances from one node v0 to all the others.
• It has the complexity of O(|V |2 ).

Algorithm 1 presents a pseudocode for the Dijkstra’s algorithm.

Algorithm 1: Dijkstra’s algorithm.


Inputs:
G = ⟨V, E⟩ - a weighted graph
v0 - the initial node to determine distances from
Outputs:
∀v ∈ V : d(v) - a set of distances from v0 calculated for all nodes v ∈ V
∀v ∈ V : p(v) - a set of predecessors on the shortest path from v0
Notation:
L(⟨u, v⟩) - the length (weight) of the edge ⟨u, v⟩ ∈ E
N (u) - the set of neighbours of the node u:
N (u) = {v ∈ V : ⟨u, v⟩ ∈ E}
d(v) - current estimate of the minimum distance from v0 to v
p(v) - the set predecessor of v on the shortest path from v0

Q := ∅
for v ∈ V do
d(v) := ∞
p(v) := NULL
Q := Q ∪ v

d(v0 ) := 0

while Q ̸= ∅ do
u := the node in Q with minimal d(u)
Q := Q \ u
for v ∈ N (u) ∩ Q do
x := d(u) + L(⟨u, v⟩)
if x < d(v) then
d(v) := x
p(v) := u

References
[1] https://en.wikipedia.org/wiki/Dijkstra%27s_algorithm

You might also like