Research of Shortest Path Algorithm Based on the Data Structure (1)
Research of Shortest Path Algorithm Based on the Data Structure (1)
Data Structure
other disciplines [ 1]. It is not only the key problem in network o i=j
analysis but also the key issue in graph theory, and therefore it Where,wijis the weight value of the edge between Vi and Vi'
has been widely used in electronic navigation, network
optimization, logistics, transportation and other areas in From above formula, we can know that the main idea of
people's daily life. The shortest path is also the one between Dijksra algorithm is to iterate the path,and get the shortest path
the nodes in weighted graph of a data structure. Dijkstra according to the increase order of the path length, as is shown
algorithms used for calculating the shortest path, which was in (2).
introduced by the famous Dutch computer scientist
Eiziga Dijkstra,was recognized as the best algorithm that can
•
(2)
be applied to get the shortest path from a node to any other B. weighted graph storage
nodes [2]. Identify a shortest distance from the source point to
Graph storage problem in the computer is the primary
the other target nodes, and then use the path length to find the
consideration before programming. In this paper, weighted
shortest path iteratively, that is, the basic idea of Dijkstra
graph is denoted by the adjacency matrix cost [max][AX].
algorithm. However, with the development of the computer,
When there is an edge or arch between nodes Vi and Vi, cost[iJ[jJ
the scale of the problems is increasing continuously, and
is the weight value on the edge(Vi,vJ, and it will be presented
meanwhile the use of traditional Dijkstra has increased the
by OCJ when there is no edge. Combining with adjacency matrix
space and time complexity. Therefore, this paper has proposed
cost,the node order and the shortest path length between Vi and
the optimization of algorithm based on the data structure,
which has very important significance for improving the Vi can be obtained. Weighted graph is shown in Fig. 1, and its
efficiency of solving the shortest path algorithm. cost matrix is shown in Fig. 2.
108
Authorized licensed use limited to: Indraprastha Institute of Information Technology. Downloaded on February 06,2025 at 08:59:42 UTC from IEEE Xplore. Restrictions apply.
A. Analysis ofoptimization ideas
1) The selection of the shortest path nodes and nodes
ranking.
In Dijkstra algorithm, each node in the network diagram
will be changed from unmarked node to the shortest path node.
This change requires scanning a large number of stored
disorder unmarked nodes one by one, so that the shortest path
Figure 1. A directed weighted graph
of the intermediate node can be achieved. If calculating on the
basis of this large amount of data,the calculation speed will be
certainly affected. Now we can rank the nodes to be scanned
0 00 4 30 00 00
according to the label value, and it needs only one iteration to
0 00 00 8 00 obtain the eligible nodes, which increases the computational
00 15 0 00 00 5
efficiency significantly. Here the heap sort method given by
cost = Willioms is used to select the shortest path node.
00 00 00 0 00 00
complexity. If directly applied to calculating the best path of heap sort to adjust the array T [} into a small heap, take the
the urban road network, this algorithm will need a great heap top node which is also the first element of the array as the
amount of computation, and cannot meet the dynamic needs intermediate nodes, and then add it into the labeled nodes
either [5]. In addition, the adjacency matrix and incidence collection S; Then compare the difference sets indicated
matrix used in the traditional algorithm to store network data collection (ad) [current} -S) with the current shortest path of
will open up a huge storage space to store a large number of any node Vi in the changed current collection of adjacent nodes;
invalid OCJ elements and 0 elements, which is bound to cause Then find the difference set between the unit set of adjacent
huge waste of run time and can also reduce the computational nodes of all nodes in the S collection and S (denoted as U ad)
efficiency in Matrix algorithm. [S} S), put these nodes into the array T in order, cover the
-
109
Authorized licensed use limited to: Indraprastha Institute of Information Technology. Downloaded on February 06,2025 at 08:59:42 UTC from IEEE Xplore. Restrictions apply.
which the storage structure selected in the graph G IS the From the table we can see that in the process of searching
adjacent list. The optimized algorithm is as follows: for the shortest path, the path number of traditional Dijkstra
algorithm shows an increasing tendency, while the improved
#define n 1000
algorithm is not the case. In the early stage of the running, the
Void Dijkstra (Mgraph G,int YO,int T[ ] ,int D[ ] ,) search path of improved Dijkstra algorithm shows an
{ increasing tendency, but at the latter stage of reaching the end
int i =O,j,F[n] ,T[n] ,p,k; path,it greatly reduced the number of stored paths, while at the
for ( i =0;i < GVexnum;i + + ) end of the algorithm, the path stored in the memory is only 1
{F[i] =O;D [i] =NFNITE;T[V] =0; } that is the shortest path. Therefore, the improved algorithm
for (p =Gvextices[O]. firstarc;p;p =p - > nextarc) releases the storage space, reduces data redundancy, and
{K =p-> adjvex;D [k] =p-> info;T[i] =D [k] ,i + + ; } improves the running time and efficiency.
F[O] = l;D [0] = 0;
for ( j = l;j < GVexnum;j + +) V. SUMMARY
{HeapAdjust (T[n] ,i) ;
This paper mainly studied the application of the shortest
HeapMin (T,current,distance,path);
path algorithm based on the data structure, and proposed the
F[current] = 1; }
improved Dijkstra algorithm, which optimized selection of the
for (p =Gvextices[ current ]. firstarc;p;p =p-> nextarc)
shortest path node and data storage structure and organization.
{ K =p-> adjvex; Studies showed that, compared with the traditional Dijkstra
If( ! F[k]&& D[current] +(p-> info) <D [k] ) algorithm, the optimized Dijkstra algorithm which has
D [k] =D [current] +(p-> info) ; optimized the space complexity, time complexity and storage
SearchAdj (S,T[n] ,i) ; combination reduced the storage space, reduced data
} } redundancy and greatly improved the running rate. It was
clearly showed that the optimized algorithm is more applicable
C. Comparative Analysis
to calculate the shortest path.
Compare the formation of the maximum path number in the
implementation process and its operating efficiency of the
REFERENCES
improved Dijkstra algorithm with that in the traditional
algorithm, and the results are shown in Table l. As shown in [I] Y. Cao, The Shortest path algorithm in data structures, [1]. Yibin
University, vol. 6, 2007,pp.82 -84.
the table, the improved Dijkstra algorithm not only effectively
improves the calculations and running efficiency, but also [2] Q. Sun, J. H. Shen, J. Z. Gu, An improved Dijkstra algorithm [J].
Computer Engineering and Applications, vol. 3 ,2002, pp.99-101.
greatly reduces the number of path in analyzing the shortest
[3] F. S. XU. Shortest path calculation algorithm[1]. Computer Applications,
path.
yoI.5,2004, pp.88 - 89.
[4] L. B. Chen, R. T. Liu, A Dijkstra's shortest path algorithm [J]. Harbin
TABLE I. ALGORITHM OPERATING EFFICIENCY COMPARISON University of Technology, vo1.3,2008,pp. 35 - 37.
[5] F. S. XU, C. Tian, All the Shortest Path Algorithm [J]. Computer
Engineering and Science,YoI.12, 2006,pp. 83-84.
Original data Traditional Dijkstra Improved Dijkstra
algorithm algorithm
Arc Nodes Total Computing Total Computing
number timers) number timers)
ofpaths ofpaths
420 132 387 0.048 87 0.031
110
Authorized licensed use limited to: Indraprastha Institute of Information Technology. Downloaded on February 06,2025 at 08:59:42 UTC from IEEE Xplore. Restrictions apply.