Comparison of Single Source Shortest Path Algorithms using C#

Similar documents
2. True or false: even though BFS and DFS have the same space complexity, they do not always have the same worst case asymptotic time complexity.

4/8/11. Single-Source Shortest Path. Shortest Paths. Shortest Paths. Chapter 24

TIE Graph algorithms

Shortest path problems

CS350: Data Structures Dijkstra s Shortest Path Alg.

Single Source Shortest Path

22 Elementary Graph Algorithms. There are two standard ways to represent a

Graph Representation DFS BFS Dijkstra A* Search Bellman-Ford Floyd-Warshall Iterative? Non-iterative? MST Flow Edmond-Karp

Dijkstra s Algorithm. Dijkstra s algorithm is a natural, greedy approach towards

Graphs. Part II: SP and MST. Laura Toma Algorithms (csci2200), Bowdoin College

Weighted Graph Algorithms Presented by Jason Yuan

Dijkstra s Algorithm

(Refer Slide Time: 00:18)

Minimum Spanning Tree

CSE 100 Minimum Spanning Trees Prim s and Kruskal

Graphs. The ultimate data structure. graphs 1

Tutorial. Question There are no forward edges. 4. For each back edge u, v, we have 0 d[v] d[u].

Introduction Single-source shortest paths All-pairs shortest paths. Shortest paths in graphs

Topological Sort. Here a topological sort would label A with 1, B and C with 2 and 3, and D with 4.

Routing Protocols and the IP Layer

Computer Science & Engineering 423/823 Design and Analysis of Algorithms

More Graph Algorithms: Topological Sort and Shortest Distance

Lecture 11: Analysis of Algorithms (CS ) 1

Single Source Shortest Path: The Bellman-Ford Algorithm. Slides based on Kevin Wayne / Pearson-Addison Wesley

Graphs. The ultimate data structure. graphs 1

The Shortest Path Problem

Introduction. I Given a weighted, directed graph G =(V, E) with weight function

CHAPTER 13 GRAPH ALGORITHMS

Minimum Spanning Trees

Single Source Shortest Path (SSSP) Problem

Single Source Shortest Paths

Agenda. Graph Representation DFS BFS Dijkstra A* Search Bellman-Ford Floyd-Warshall Iterative? Non-iterative? MST Flow Edmond-Karp

22 Elementary Graph Algorithms. There are two standard ways to represent a

Part VI Graph algorithms. Chapter 22 Elementary Graph Algorithms Chapter 23 Minimum Spanning Trees Chapter 24 Single-source Shortest Paths

Graphs & Digraphs Tuesday, November 06, 2007

from notes written mostly by Dr. Carla Savage: All Rights Reserved

Single-Source Shortest Paths. CSE 2320 Algorithms and Data Structures Vassilis Athitsos University of Texas at Arlington

Shortest Path Problem

Outline. (single-source) shortest path. (all-pairs) shortest path. minimum spanning tree. Dijkstra (Section 4.4) Bellman-Ford (Section 4.

Introduction to Algorithms. Lecture 11

CS 561, Lecture 10. Jared Saia University of New Mexico

All Shortest Paths. Questions from exercises and exams

CS200: Graphs. Rosen Ch , 9.6, Walls and Mirrors Ch. 14

Introduction to Algorithms November 17, 2011 Massachusetts Institute of Technology Fall 2011 Professors Erik Demaine and Srini Devadas Quiz 2

CS 561, Lecture 10. Jared Saia University of New Mexico

Parallelization of Shortest Path Finder on GPU: Floyd-Warshall

Introduction. I Given a weighted, directed graph G =(V, E) with weight function

Analysis of Algorithms, I

problem statement Prim s algorithm a multiple key map representation for a tree code for Prim s algorithm

Artificial Intelligence

CS 161 Lecture 11 BFS, Dijkstra s algorithm Jessica Su (some parts copied from CLRS) 1 Review

Dijkstra's algorithm Prim's algorithm

5.4 Shortest Paths. Jacobs University Visualization and Computer Graphics Lab. CH : Algorithms and Data Structures 456

An Investigation of Dijkstra and Floyd Algorithms in National City Traffic Advisory Procedures

Analysis of Algorithms

TIE Graph algorithms

Minimum-Spanning-Tree problem. Minimum Spanning Trees (Forests) Minimum-Spanning-Tree problem

DESIGN AND ANALYSIS OF ALGORITHMS

Parallel Graph Algorithms

An Experiment on the Performance of Shortest Path Algorithm

Graphs II: Trailblazing

Algorithms for Data Science

Mon Tue Wed Thurs Fri

Breadth-First Search, 1. Slides for CIS 675 DPV Chapter 4. Breadth-First Search, 3. Breadth-First Search, 2

1 Shortest Paths. 1.1 Breadth First Search (BFS) CS 124 Section #3 Shortest Paths and MSTs 2/13/2018

The Shortest Path Problem. The Shortest Path Problem. Mathematical Model. Integer Programming Formulation

MST & Shortest Path -Prim s -Djikstra s

Advanced Algorithm Design and Analysis (Lecture 5) SW5 fall 2007 Simonas Šaltenis

Van Phuc Pham Abstract

L22-23: Graph Algorithms

CS 3410 Ch 14 Graphs and Paths


CSE 100: GRAPH ALGORITHMS

1 Shortest Paths. 1.1 Breadth First Search (BFS) CS 124 Section #3 Shortest Paths and MSTs 2/13/2018

Graphs. Bjarki Ágúst Guðmundsson Tómas Ken Magnússon Árangursrík forritun og lausn verkefna. School of Computer Science Reykjavík University

Dijkstra s algorithm for shortest paths when no edges have negative weight.

Chapter 9. Greedy Technique. Copyright 2007 Pearson Addison-Wesley. All rights reserved.

Shortest Paths. Nishant Mehta Lectures 10 and 11

Solving problems on graph algorithms

Shortest Path Algorithms

1 Dijkstra s Algorithm

Shortest Paths. Nishant Mehta Lectures 10 and 11

1 i n (p i + r n i ) (Note that by allowing i to be n, we handle the case where the rod is not cut at all.)

Chapter 24. Shortest path problems. Chapter 24. Shortest path problems. 24. Various shortest path problems. Chapter 24. Shortest path problems

Lecture 28: Graphs: Shortest Paths (Part 1)

Unit-5 Dynamic Programming 2016

SPANNING TREES. Lecture 21 CS2110 Spring 2016

Review of course COMP-251B winter 2010

Parallel Graph Algorithms

Graph definitions. There are two kinds of graphs: directed graphs (sometimes called digraphs) and undirected graphs. An undirected graph

CS490 Quiz 1. This is the written part of Quiz 1. The quiz is closed book; in particular, no notes, calculators and cell phones are allowed.

Sample Solutions to Homework #4

Graphs Data Structures

Lecture 26: Graphs: Traversal (Part 1)

Quiz 2. Problem Parts Points Grade Grader. Total 120. Name: Recitation: Jayant 12 PM. Christina 10 AM. Jayant 1 PM. Jason 2 PM.

R13. II B. Tech I Semester Supplementary Examinations, May/June DATA STRUCTURES (Com. to ECE, CSE, EIE, IT, ECC)

Graphs. Tessema M. Mengistu Department of Computer Science Southern Illinois University Carbondale Room - Faner 3131

Algorithm Design, Anal. & Imp., Homework 4 Solution

Routing Algorithms. CS158a Chris Pollett Apr 4, 2007.

Shortest Paths. CSE 373 Data Structures Lecture 21

Transcription:

[214] Comparison of Single Source Shortest Path s using C# Swati Vishnoi 1, Hina Hashmi 2 1,2 CCSIT, TMU, Moradabad 1 swativishnoi1@gmail.com 2 hinahashmi17@gmail.com Abstract Many applications like transportation and communication network use shortest path algorithm to find out the shortest path between two nodes. In the Single source shortest path algorithm, a shortest path is calculating from one node to another node. In this paper, I have compared the results of the shortest path algorithms (Dijkstra, ) on the basis of running time. I am using C# programming language to compare the algorithms. I have also compared the algorithms on the basis of complexity and space. I also tried to give some advantages and disadvantages of both the algorithms. Keywords Shortest Path, Dijkstra, Bellman Ford, Run-time Analysis I. ITRODUCTIO Shortest Path Problem is the problem to find out the shortest path between two nodes. There are so many shortest path algorithms depending on the source and destination. a) Single source Shortest Path b) Single destination Shortest Path c) All pair Shortest path In Single source shortest path algorithm, we have to find out the shortest path from a source vertex to another vertex. In single destination shortest path algorithm, we have to find out the shortest path from all vertices to a single destination vertex. In All pair shortest path algorithm, we have to find out the shortest path from all vertices to another vertex. Due to the nature of routing applications, we need flexible and efficient shortest path procedures, both from a processing time point of view and also in terms of the memory requirements. [1] In this paper, I am comparing single source shortest path algorithms ( and ). II. LITERATURE REVIEW As mentioned earlier, a graph can be used to represent a map where the cities are represented by vertices and the routes or roads are represented by edges within the graph. [2] In this section, a graph representation of a map is explained further, and brief descriptions and implementations of the shortest path algorithms being studied are presented. III. WORKIG OF DIJKSTA S AD BELLMA FORD ALGORITHM The working of djkstra s algorithm and bellman ford algorithm is as follows: A. -: The algorithm stores all nodes in a priority queue ordered by distance of the node from the root in the first iteration of the algorithm, only root has distance set to, distance of all other nodes is equal to infinity. Than in each step algorithm picks from the queue a node with the highest priority (least distance from the root) a processes it and reevaluates distances of all unprocessed descendants of the node. This means that the algorithm checks for all descendants that the following condition holds: [3] distance +edgeweight <distance 183

[214] B. -: The Bellman-Ford algorithm is based on the relaxation operation. The relaxation procedure takes two nodes as arguments and an edge connecting these nodes. If the distance from the source to the first node plus the edge length is less than distance to the second node, than the first node is denoted as the predecessor of the second node and the distance to the second node is recalculated (distance(a)+ edge.length). Otherwise no changes are applied. [4] IV. COMPARISO O THE BASIS OF COMPLEXITY AD SPACE We consider a graph[g] with the vertices or nodes [V] and the edges[e].ow If we find the complexity of Dijkstra with the Bellman Ford i.e. Time Complexity Space Complexity O(E+V(log V)) O(V) O(EV) O(V) A. Advantages and Disadvantages : a) - The advantages and disadvantages are as follows: 1. It is a Greedy. 2. It doesn t work on negative weight. 3. It can work for directed and undirected graph. 4. It requires global information. b) - The advantages and disadvantages are as follows: 1. It is a dynamic. 2. It can work on negative weight. 3. It can only work for directed graph. 4. It only requires local information. V. COMPARISO USIG C# CODE ow, I will determine the efficiency of shortest path algorithm. I have created a window based application to find out the running time of both the algorithms. I have created a WindowFormsApplication1, in which I have created a Form and add a list box to display the running time of and bellman ford algorithm. I have implemented algorithm and algorithm using C# code. I have created two functions for and Bellman Ford algorithms. From the Form_Load () method, both functions are called and display the shortest path for every node from a single source. And I have used stopwatch to calculate the running time of algorithm and algorithm in microseconds. I used Random numbers to generate a graph. A. To strore a Graph : public struct Edge public int u, v, w; ; int ODES ; /* the number of nodes */ int EDGES; /* the number of edges */ int[]d=new int [1]; /* d[i] is the minimum distance from source node s to node i */ double[,] G = new double[1, 1]; /* graph to store the graph adjacency matrix */ B. To store the adjacency matrix of graph using Random numbers: Random rn1 = new Random(); for (m = ; m length; m++) for (n = ; n < length; n++) 184

[214] 1); w[m, n] = rn1.ext(, G[m, n] = w[m, n]; C. To Store the Edges with their weight: k = ; for (i = ; i < ODES; ++i) for (j = ; j < ODES; ++j) if (w[i, j]!= ) edges[k].u = i; edges[k].v = j; edges[k].w = w[i, j]; k++; l++; EDGES = k; D. To Find out the running time using stopwatch: Stopwatch s = new Stopwatch(); s.start(); BellmanFord(source_vertex); /* Call for */ s.stop(); long time = s.elapsedticks / Stopwatch.Frequency / (1L * 1L)); listbox1.items.add("time taken by Bellman ford is"+ time+" microseconds"); s.start(); Dijkstra(source_vertex); /* Call for */ s.stop(); long time = s.elapsedticks / Stopwatch.Frequency / (1L * 1L)); listbox1.items.add("time taken by algorithm is"+ time+" microseconds"); TABLE I First Run 5 1577 741 1 1617 764 5 1853 4655 1 2777 3226 5 23923 4251 1 9255 3341616 Second Run 5 1459 657 1 357 687 5 1918 9631 1 2921 32822 5 23794 4224362 1 96836 3363691 Third Run 5 1567 667 1 1455 697 5 1758 4557 1 2644 37941 5 2587 4158252 1 92149 3359217 Fourth Run 5 146 688 1 1411 678 5 1748 4476 1 2466 3294 5 24285 4196981 185

[214] 1 92377 Fifth Run 5 156 1 1495 5 1659 1 3479 5 24323 1 126932 Average 5 1513.8 1 199.6 5 1787.2 1 2857.4 5 24282.4 1 1168.8 3434142 67 728 4486 3195 4147961 33643137 684.6 71.8 5561 33528.6 4186513.2 3371918.6 Average Running Time for =5,1 2 199.6 15 1513.8 1 =5 684.671.8 =1 5 Figure 1 For =5, algorithm is the efficient algorithm. Average Running Time for =5 We can observe from this table that for the small number of vertices (=5, 1) is taking less time in comparison with algorithm. And for the large number of vertices (=5, 1, 5, 1) s is taking less time in comparison with. VI. COCLUSIO In this study we have studied about two single source shortest path algorithms and their comparison. There is advantage and disadvantage in algorithms. To find the running time of each algorithm I used one Program for comparing the running time (in Microseconds). After running the same program on five different runs (for each different value of =5, 1, 5, 1, 5, 1), I calculated the average running time for each algorithm and then showed the result with the help of a chart. From the chart I can conclude that for a small number of nodes (=5, 1) is the most efficient algorithm to find out the shortest path. 6 5561 5 4 3 =5 1787.2 2 1 Figure 2 For =1,again algorithm is efficient algorithm, there is a very big difference in running time of running time and algorithm. 186

[214] 35 3 25 2 15 1 5 Average Running Time for = =1 33528.6 2857.4 =1 better than algorithm. algorithm takes twice the running time of Bellman Ford algorithm. But a large number of nodes (>5) algorithm becomes more efficient. For =5, algorithm is three times to running time. For =1, is 11 times to algorithm. Average Running Time for =1 3371918.6 35 3 25 Figure 3 2 15 =1 1 For =5, 1, algorithm is the efficient algorithm in comparison to. Average Running Time for =5 5 1168.8 45 4186513.2 4 35 3 25 =5 2 15 1 5 24282.4 Figure 4 By these all charts, we can conclude that for small number of nodes ( < 5) Bellman Ford perform Figure 5 For =5, 1, algorithm outperforms in comparison to algorithm. REFERECES [1] Faramroze Engineer, Fast Shortest Path s for Large Road etworks [2] Kairanbay Magzhan, Hajar Mat Jani, A Review And Evaluations Of Shortest Path s [3] http://en.algoritmy.net/article/455 514/Dijkstras-algorithm [4] http://en.algoritmy.net/article/473 389/Bellman-Ford-algorithm 187