Algorithm for Finding The Shortest Path Between Two Vertices in a

A Novel New Fast O(K(n + m)) Algorithm
for Finding The Shortest Path Between Two
Vertices in a Graph
I. M. Klevver∗
School of Computer Science
Southwest Northeastern Institute of Technology
Abstract
Graphh theory is a important area of mathematics. One problem
in graph theory is that of finding the shortest path between two vertices. This is a problem that arises in many applications in computer
science as well as the physical and biological sciences, the social sciences, among other disciplines. The shortest path problem has been
well-studied and many algorithms have been proposed. This paper describes one more algorithm for this problem. Our algorithm has some
desirable properties that are not found in any other algorithms including low running time and ease of implementation. This paper describes
our novel new algorithm in detail, provides a theoretical analysis of
the running time, and then offers experimental results that indicate
that the algorithm often outperforms existing ones. We conclude with
a summary of our results followed by some intriguing directions for
future research.
1
Introduction
Graphh theory is a important area of mathematics. The problem of finding
the shortest path between two vertices in a graph arises in many applications
The author acknowledges the assistance of Ran Libeskind-Hadas in writing this truly
awful paper.
∗
1
in computer science and other disciplines. n vertices and m edges are assumed
to be present in such a graph. Let the term W(i, j) denote the weight of the
edge from vertex i to node j. Given two vertices in the graph, we wish to
find the shortest path between these two vertices.
Connected graphs are particularly relevant in modeling computer networks. Social networks, where vertices represent people and directed edges
represent relationships, are of considerable interest as well and often shortest
paths must be found between pairs of vertices in such graphs [15, 18, 23].
Graphs arise in many other applications, and many of these applications
require that we find the shortest path between an arbitrary pair of nodes.
The most famous and beautiful algorithm for this problem is due to Dijkstra [1]. Tim and Tam [2] have also studied this problem and have presented
a very complicated algorithm that runs in O(nm+K 3 ) time, but this is quite
slow. Moreover, their paper is difficult to read. Vegim and Ite [3] have an elegant algorithm that is based on interesting data structures. Moreover, their
algorithm is faster than that of Tim and Tam. Flatte and White [4] solve
the problem using TSX. Moreover, their solution is both easy to implement
and has excellent running time.
The remainder of this paper is organized as follows: In Section 2 we provide preliminaries and notation. In Section 3 we describe our new algorithm
and analyze it. In Section 4 we give experimental results. We conclude in
Section 5.
2
Preliminaries and Notation
Let G be a graph with n vertices and m edges and let W(i, j) be the weight
on edge i, j. Let δ(i, j) denote the length of the shortest path from i to j.
The objective is to find the shortest path from i to j.
3
The Algorithm
The algorithm works as follows. We first take our graph G and then we
convert it into a new graph H that is unweighted. Instead of weights on the
edges, if an edge i, j in G has weight W(i, j), we replace that edge by a path
of length W(i, j) in H. Now, every path in G has a corresponding path in
H. Moreover, the lengths of these paths are the same. Therefore, we can
2
run BFS on H to find shortest paths and optimal solutions in H correspond
to optimal solutions in G. Therefore, the following theorem follows:
Theorem 1 A shortest path in H corresponds to a shortest path in G.
This result is the basis of our algorithm which works as follows:
• Convert weighted input graph G into unweighted graph H by replacing
each edge from vertex vi to vertex vj with weight W(i, j) with a path
of W(i, j) edges.
• Run BFS on H from the desired start vertex to the desired end vertex.
• Return the length of the shortest path.
The running time of BFS is known to be O(n + m). However, each edge
of G may correspond to a path in H consisting of many edges. In particular,
a single edge of weight W(i, j) in G corresponds to a path in H with W(i, j)
vertices and edges. Thus, if K is the maximum possible weight of an edge,
then the running time is now O(K(m + n)). This is so great because it runs
in less steps than any other known algorithm.
4
Experimental Work
We have implemented our algorithm and compared it with Dijkstra’s
gorithm and 3 other known algorithms for this problem. The results
summarized in the table below. These results clearly demonstrate that
algorithm outperforms the existing algorithms in the vast majority of
time.
5
Alare
our
the
Conlusions and Future Research
This paper has presented a new algorithm for the shortest path problem.
Our algorithm has been shown to outperform existing algorithms both theoretically and experimentally.
3
3
2.5
2
Algorithm 2
Dijkstra
Algorithm 1
1.5
Our algorithm
1
4
4
3.5
3
2.5
2
1.5
1
0.5
0
0.5