Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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 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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started