Ministry of Higher Education

Jazan University, Jazan | |

A DIJKSTRA SHORTEST PATH ALGORITHM

Faculty of Computer Science & Information system

ABSTRACT

Dijkstra Algorithm is utilized to compute shortest path in a network. It is essential to explain the different types of connected, directed and weighted graphs. Tree is also discussed with the help of graph. Dijkstra shortest path is shown and described with the example. Pseudo code and algorithm are also included along with their efficiency and applications. The different aspects of related algorithms were discussed, such as A* algorithm, Bellman–Ford algorithm and Prim’s algorithm

Keywords – Algorithm, Network, Tree, Pseudo code

INTRODUCTION

Graphs

➢ G (V, E) where:

- V is vertex set

- E is edge set: every e in E connects two vertices -If (i, j) connected they are said adjacent

-Edge e = (i, j) is said incident to i and j

-|V| = cardinality of the vertex set

➢ A graph G(V, E) can be represented by |V| x |V| adjacency matrix ➢ A path between vertices i and j is a sequence of vertices and edges starting with vertex i and ending in j, such that every edge is incident to the preceding and following vertices.

➢ A path is simple if every node/edge appears only once. ➢ Distance between vertices i and j: minimum number of edges along a path from i to j ➢ Cycle: simple path where starting vertex coincides with ending vertex ➢ A graph is connected if there exists a path between any possible vertex pair i and j

➢ A graph is directed if edges have a direction. In this case, (i, j) belonging to E does not imply that (j, i) belongs to E. Edges are called arcs in this case ➢ A graph is weighted if every edge (or arc) comes with a number .

Tree

Graph T is a tree if:

➢ One and only one simple path between every vertex pair (i, j) ➢ If N = |V|:

Exactly N1

edges (arcs)

Connected, no cycles

➢ Every vertex of a tree can be assumed to be the

➢ root of the tree

➢ A tree can be represented by arranging vertices in sequential layers of increasing distance from root

➢ In a layered representation of a tree

- Every vertex (except for the root), has only one parent vertex - Every vertex has 0 or more children

- A node with 0 children is a leaf

Dijkstra's Algorithm: Dijkstra's algorithm is called the single-source shortest path. It is also known as the single source shortest path problem. It computes length of the shortest path from the source to each of the remaining vertices in the graph. The single source shortest path problem can be described as follows: Let G= {V, E} be a directed weighted graph with V having the set of vertices. The special vertex s in V, where s is the source and let for any edge e in E, EdgeCost(e) be the length of edge e. All the weights in the graph should be non-negative. Before going in depth about Dijkstra’s algorithm let’s talk in detail about directed-weighted graph. Directed graph can be defined as an ordered pair G: = (V,E) with V is a set, whose elements are called vertices or nodes and E is a set of ordered pairs of vertices, called directed edges, arcs, or arrows. Directed graphs are also known as digraph.

[pic]

Figure of Directed graph

DESCRIPTION OF THE ALGORITHM

Before going into details of the pseudo-code of the algorithm it is important to know how the algorithm works. Dijkstra’s algorithm works by solving the sub problem k, which computes the shortest path from the source to vertices among the k closest vertices to the source. For the dijkstra’s algorithm to work it should be directed- weighted graph and the edges should be non-negative. If he edges are negative then the actual shortest path cannot be obtained.

At the...