File Structure Lab4

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

Alexandria University

Computer and Systems Engineering


Department

Faculty of Engineering
Data Structures 2
Due: Monday, 18 May, 2015

Lab 4

Shortest Paths Algorithms

Overview

In this assignment, youre required to implement two shortest paths algorithms which are
Bellman-Ford and Dijkstra algorithms. You will apply your implementation on an input graph
and compare the results and the perfromance of the two algorithms.

Bellman-Ford Algorithm

The Bellman-Ford algorithm is an algorithm that computes shortest paths from a single source
vertex to all of the other vertices in a weighted digraph. It is capable of handling graphs in
which some of the edge weights are negative numbers. It works in O(|V ||E|) time and O(|V |)
space complexities where |V | is the number of vertices and |E| is the number of edges in the
graph. Time complexity can be also enhanced using several methods like in [4].

Dijkstra Algorithm

This algorithm finds shortest paths from the source to all other nodes in the graph, producing a shortest path tree. Its time complexity is O(|V |2 ) but can reach less than that when
using priority queue. Dijkstra algorithm cant handle negative weights. But, it is asymptotically the fastest known single-source shortest-path algorithm for arbitrary directed graphs with
unbounded non-negative weights.

Input Graph Structure

Input file will contain several lines that describe the graph structure as follows. First line
contains two integers V and E which determine number of vertices and edges respectively.
This line is followed by E lines describing the edges in the graph. Each of the E lines contain 3
numbers: i, j, w separated by a single space. i,j represnts the nodes that are connected through
this edge (i, j are less than V) where w determines the weight on this edge. Weights may be
negative or positive.

Requirements

Youre required to:


1. Implement Bellman-Ford and Dijkstra Algorithms.
1

Alexandria University
Computer and Systems Engineering
Department

Faculty of Engineering
Data Structures 2
Due: Monday, 18 May, 2015

2. Report the running time for both algorithms and compare between them. To formalize
this point, draw a graph between both number of vertices and number of edges versus
the running time for both algorithms.
3. A report that describes your implementation and comparisons between the two algorithms.

Bonus
1. You are encouraged to apply some heuristics and techniques to enhance the running time
for both algorithms.
2. A competition will be held between delivered implementations. Your algorithm will be
tested on large input graphs and best performance algorithms will be given extra bonus
marks.

References
1. Cormen, T. H., Leiserson, C. E., Rivest, R. L., & Stein, C. (2009). Introduction to
algorithms. MIT press.
2. Wikipedia contributors. BellmanFord algorithm. Wikipedia, The Free Encyclopedia.
Wikipedia, The Free Encyclopedia, 24 Apr. 2015. Web. 30 Apr. 2015.
3. Wikipedia contributors. Dijkstras algorithm. Wikipedia, The Free Encyclopedia. Wikipedia,
The Free Encyclopedia, 17 Apr. 2015. Web. 30 Apr. 2015.
4. Pape, U. Implementation and efficiency of Moore-algorithms for the shortest route problem. Mathematical Programming 7.1 (1974): 212-222.

You might also like