0% found this document useful (0 votes)
26 views12 pages

Dijkstra's Algorithm

The Dijkstra algorithm, also known as the shortest path algorithm, is an algorithm for determining the shortest path from a source vertex to all other vertices in a graph with weights on each edge. Its name refers to Edsger Dijkstra, who first described it in 1959. The algorithm works iteratively to find the shortest path from a source vertex to all other vertices in the graph.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views12 pages

Dijkstra's Algorithm

The Dijkstra algorithm, also known as the shortest path algorithm, is an algorithm for determining the shortest path from a source vertex to all other vertices in a graph with weights on each edge. Its name refers to Edsger Dijkstra, who first described it in 1959. The algorithm works iteratively to find the shortest path from a source vertex to all other vertices in the graph.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

Dijkstra's algorithm

Algorithm of
Dijkstra. Also called Dijkstra's Algorithm
shortest path algorithm
it is an algorithm for the
determination of the best path
short given a vertex origin to the
remaining vertices in
agraphwith weights in each
arista. Its name refers to
aEdsger Dijkstrawho lo
described for the first time
in1959.

Content
[hide]

1 Applications
2 Characteristics of Concept: The Dijkstra algorithm, also called
algorithm shortest path algorithm, it is a
3 Steps of the algorithm
algorithm for path determination
4 Algorithm execution
shortest path from a source vertex to the rest of
5 Final of the Process of
Execution vertices in a graph with weights on each
6 Pseudocode arista. Its name refers to Edsger
or6.1 Priority Queue Dijkstra, who described it for the first time
o6.2 Without a tail in 1959.
priority
7 External links

Applications
In multiple applications where graphs are applied, it is necessary to know the path of
minimum cost between two given vertices:

Distribution of products to a network of commercial establishments.


Mail distribution.
Let G = (V, A) be a weighted directed graph.

The shortest path problem from one vertex to another consists of determining the path from
lower cost, from a vertex u to another vertex v. The cost of a path is the sum of the
costs (pesos) of the arcs that compose it.
Characteristics of the algorithm
It is a greedy algorithm.
Work in stages, and take the best solution at each stage without considering
future consequences.
The optimum found in one stage can be modified later if a
better solution.

Steps of the algorithm


Algorithm 24.1: Dijkstra's Algorithm. Initialization.

Let V be a set of vertices of a graph.


Let C be a matrix of costs of the edges of the graph, where C[u,v] stores the
cost of the edge between u and v.
S is a set that will contain the vertices for which it has already been determined the
minimum path.
Let D be a one-dimensional array such that D[v] is the cost of the minimum path from the vertex
origin to vertex v.
Let P be a one-dimensional array such that P[v] is the predecessor vertex of v in the path.
minimum that is built.
The origin vertex is the beginning. Remember that Dijkstra's Algorithm determines the
minimum paths that exist starting from a source vertex to the rest of the vertices.

Step 1. S ← {vinitial} // Initially S will contain the vertex // origin


n
Step 2. For each v∈V, v ≠ initial, to do
2.1. D[v] ← C[vinitial, v] // Initially the cost of the // path m
the minimum from initial to v is the content in //the cost matrix
2.2. P[v] ← vinitial // Initially, the // predecessor of v in the c
minimum amino built //so far is initial
Step 3. While (V– S ≠∅do //As long as there are vertices for
for which the minimum path has not been determined
3.1. Choose a vertex w∈(V-S) such that D[w] is the minimum.
3.2. S ← S∪ w is added to the set S, since it is already there.
the minimum path to w
3.3. For each v∈(V-S) to do
3.3.1. D[v] ← min(D[v], D[w] + C[w,v]) // Choose, among // the path
the minimum towards v that we have so far, and the way to v
passing through w via its minimum path, the one with the lowest cost.
3.3.2. If min(D[v],D[w]+C[w,v]) = D[w]+C[w,v] then P[v] ← w
If you choose to go by w then //the predecessor of v for the moment e
sw
Step 4. End

Execution of Algorithm
Step 1: Initialization

Step 2: Choose a vertex w∈ V - {A} such that D[w] is minimized, and add w to
solution set S
Step 3: each v∈ make D[v] ← min(D[v], D[w] + C[w, v])
Step 4: Choose a vertex w∈ V - {A, B} such that D[w] is minimal, and add w to
set solution S.

Step 5: For each v∈ {C, E} make D[v] ← min( D[v], D[w]+C[w, v]

File:Algo09.JPG

Step 6: Choose a vertex w∈ V - {A, B, D} such that D[w] is minimum, and add w to it
solution set S.
Step 7: For each v∈ make D[v] ← min(D[v], D[w] + C[w, v])
Step 8: Choose a vertex w∈ V - {A, B, D, C} such that D[w] is minimal, and add
to the solution set S.
Final of the Execution Process
After step 8, we have the following situation:

The set of vertices V = {A, B, C, D, E}


The set of vertices for which the minimum path has already been determined S = {A, B, D,
C, E}

So, since V-S=Ø, the algorithm ends, as for each node of the graph has...
determined what its minimum path is. As a result of the algorithm execution.
we have:

D[B] P[B]
10 50 30 60 A D A C

At the end of the execution of Dijkstra's algorithm, the array D stores the
costs of the minimum paths starting from the source vertex to the rest of the vertices. By
so, in our example, the minimum path from A to B has a cost of 10, the path
the minimum cost from A to C is 50, the minimum cost from A to D is 30 and the
the minimum path from A to E has a cost of 60.
Let's see how to obtain the shortest paths from the predecessor array.
The paths are reconstructed starting from the destination vertex until reaching the origin vertex.
MinimumPath (A, B) = AB since P[B]=A
MinimumPath (A, C) = ADC since P[C]=D and P[D]=A
MinimumPath (A, D) = AD since P[D]=A
MinimumPath (A, E) = ADCE since P[E]=C, P[C]=D and P[D]=A

Finally, the minimum path that includes all the vertices of the graph is ADCE.

Pseudocode
Priority queue
DIJKSTRA (Graph G, source_node s)
for you∈ V[G] to do
INFINITY
father[u] = NULL
distancia[s] = 0
add (glue, (s,distance[s]))
while queue is not empty do
u = extract_min(Queue)
for everyone v∈ adjacency to do
if distance[v] > distance[u] + weight(u, v) then
distance[v] = distance[u] + weight(u, v)
father[v] = u
add(glue,(v,distance[v]))

Without priority queue


Dijkstra function (Graph G, starting_node s)
We will use a vector to store the distances from the output node to
whole restaurant distance[n]
We initialize the vector with initial distances boolean seen[

//boolean vector to control the vertices that have already been have
the minimum distance
for each w∈ Do V[G]
If (there is no edge between s and w) then
Infinity //you can mark the box with a -1 for
example
Serial Number
weight(s, w)
finally yes

end for
distancia[s] = 0
certain
n is the number of vertices that the Graph has
while (not_seen_all) do
vertex = take_the_minimum_of_the_distance_vector that has not been seen;
view[vertex] = true;
for each w∈ successors (G, vertex) do
if distance[w] > distance[vertex] + weight(vertex, w) then
distance[w] = distance[vertex] + weight(vertex, w)
end if
end for
end while
end function

External links
Template:Commons

Presentation of Dijkstra's Algorithm


Java applets to test Dijkstra's algorithm (English)
GraphmodulePerlinCPAN
Bio::Coordinate::GraphPerl module in CPAN that implements Dijkstra's algorithm
VideoTutorial inVideoPractico.comthe Dijkstra
Dijkstra's algorithm in languages like PHP, Actionscript and others

Categories:
Pages with broken links to files
Informatics
Programming
Algorithms
Unable to access the content of the provided link.

You might also like