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 OV
Your input will be a graph described in a file, egtestcasetxt The format will be as follows.
source vertex : list of destination vertices
v : dest wt dest wt
v : dest wt dest w
vN : destN wtNN destN wtNN
Your program should be able to accept any input file using a commandline 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 when there are no cycles.
For example, if my input file is as follows.
:
:
:
:
The output isThe length of the shortest cycle is: corresponding to the cycle
For example, if my input file is as follows.
:
:
:
:
The output isThe length of the shortest cycle is: corresponding to the cycle
For example, if my input file is as follows.
:
:
:
The output isThe length of the shortest cycle is: since the graph is acyclic.
You must submit the following to receive full credit.
Python or Java script or C file with comments and structure.
Testcases on which you validated your program. Each testcase must be a testcaseitxt file where
i n are indices to your testcase files. You MUST include at least one testcase file.
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 me the code in java 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
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
