Answered step by step
Verified Expert Solution
Link Copied!

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 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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Visual C# And Databases

Authors: Philip Conrod, Lou Tylee

16th Edition

1951077083, 978-1951077082

More Books

Students also viewed these Databases questions

Question

What does Processing of an OLAP Cube accomplish?

Answered: 1 week ago