Homework 09: Dijkstra Shortest Path Solution

$30.00

Category:

Description

Instruction

 

Submit your answer to this question via PC^2 under your account by the posted due time. No late submissions will be accepted. Note that homework is opened-book, but no outside assistance is permitted.

 

Problem

 

Dijkstra’s algorithm is an algorithm for finding the shortest paths between nodes in a graph, which may represent, for example, road networks. It was conceived by computer scientist Edsger W. Dijkstra in 1956 and published three years later.

 

Write a program that returns the shortest distance from node X to node Y on a given directed acyclic graph (DAG), e.g.,

 

 

 

 

Note that the last two bits of input represent the starter node X and destination node Y. Also, the size of the given DAG could be varying in this problem.

 

Sample input

 

A,B,10,A,C,3,B,C,1,B,D,2,C,B,4,C,D,8,C,E,2,D,E,7,E,D,9,A,E

 

A,B,10,A,C,3,B,C,1,B,D,2,C,B,4,C,D,8,C,E,2,D,E,7,E,D,9,A,C

 

 

Sample output

 

 

The shortest distance from A to E is 5

 

The shortest distance from A to C is 3

 


error: Content is protected !!