Question: You are given a directed graph G = ( V , E ) with positive edge lengths. Please develop an efficient algorithm by using Dikstra

You are given a directed graph G =(V, E) with positive edge lengths. Please
develop an efficient algorithm by using Dikstras algorithm to return the length of the shortest cycle in the
graph (if the graph is acyclic, it should say so) and implement it. Your algorithm implementation should
take time at most O(|V |3).
Your input will be a graph described in a file, e.g.,testcase-1.txt. The format will be as follows.
source vertex : list of destination vertices
v1 : dest1 wt11 dest2 wt12...
v2 : dest3 wt23 dest7 w27...
...
vN : destN-1 wtNN-1 destN-2 wtNN-2...
Your program should be able to accept any input file using a command-line argument as follows.
your program.py input input graph f ile
Your program should output, The length of the shortest cycle is: $val, where val is the length. It
will be 0 when there are no cycles.
For example, if my input file is as follows.
0: 1124
1: 32
2: 31
3: 03
The output is,The length of the shortest cycle is: 6, corresponding to the cycle 01
->12
->33
->0.
For example, if my input file is as follows.
0: 11
1: 22
2: 33
3: 1405
The output is,The length of the shortest cycle is: 9, corresponding to the cycle 12
->23
->34
->1.
For example, if my input file is as follows.
0: 11
1: 22
2: 33
The output is,The length of the shortest cycle is: 0, since the graph is acyclic.
You must submit the following to receive full credit.
(1) Python or Java script or C++ file with comments and structure.
(2) Testcase(s) on which you validated your program. Each testcase must be a testcase-i.txt file where
i =1,2,..., n are indices to your testcase files. You MUST include at least one testcase file.
(3) Please make sure you handle corner cases, and gracefully error out when you are provided with in-
correct inputs, etc. Program crashes or errors or no outputs will be penalized.
Give the correct answer according to the above requirements and also verify whether it is satisfying all the requirements and testcases

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!