By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,212 Members | 1,110 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,212 IT Pros & Developers. It's quick & easy.

Use Dijktra's Algorithm & design C++ program

P: 2
Given a topology and a certain node X, find the shortest path tree
with X as the root.

* Input: a topology file similar to the following (which is a three-node

Nodes: (3) // there are three nodes (node 0, 1 and 2)

Edges: (3)
ID node node cost
0 0 1 100 // there is an bidirectional edge between
node 0 & 1, the edge ID is 0, and the cost is 100
1 1 2 50
2 2 0 100

* Output: Description of the tree as following, the order should be
based on breadth-first search
0(0) 1(0) 2(0)

where A(B) means the parent of node A is node B

* Requirements:
- Use standard C++
- Use of Dijkstra's algorithm is required when finding shortest paths
- No GUI
- Platform independent (can be compile under both Windows and Linux)
- The code must be compilable
- Use of STL is recommended (but not required)
- Use of class is required
Jan 24 '09 #1
Share this Question
Share on Google+
2 Replies

Expert 100+
P: 2,402
What is Dijkstra's Algorithm?
Jan 24 '09 #2

P: 2
Dijkstra's algorithm, conceived by Dutch computer scientist Edsger Dijkstra in 1959, [1] is a graph search algorithm that solves the single-source shortest path problem for a graph with non negative edge path costs, outputting a shortest path tree. This algorithm is often used in routing.
For a given source vertex (node) in the graph, the algorithm finds the path with lowest cost (i.e. the shortest path) between that vertex and every other vertex. It can also be used for finding costs of shortest paths from a single vertex to a single destination vertex by stopping the algorithm once the shortest path to the destination vertex has been determined. For example, if the vertices of the graph represent cities and edge path costs represent driving distances between pairs of cities connected by a direct road, Dijkstra's algorithm can be used to find the shortest route between one city and all other cities. As a result, the shortest path first is widely used in network routing protocols, most notably IS-IS and OSPF (Open Shortest Path First
Jan 24 '09 #3

This discussion thread is closed

Replies have been disabled for this discussion.