D 40 Ea 13 Assignment 2

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

Assignment 2

(CLO-3)
Handling Negative Cycles in the Bellman-Ford Algorithm (Complex Computing Problem)
Objective:
The goal of this assignment is to challenge students to creatively think about how to handle
negative weight cycles in graphs when using the Bellman-Ford algorithm to find the shortest
path. Students are expected to identify negative cycles and propose a solution to handle them,
ensuring that the algorithm can still find meaningful shortest paths where possible.
Problem Statement:
You are required to enhance the Bellman-Ford algorithm to detect and handle negative weight
cycles. A negative weight cycle makes the shortest path problem undefined, as the path cost can
be reduced indefinitely by traversing the cycle. In this assignment, you need to propose an
algorithmic solution that addresses the presence of negative weight cycles and attempts to find
valid shortest paths for the vertices.
Requirements:
1. Detect Negative Weight Cycles:
 Implement the Bellman-Ford algorithm to detect the presence of negative weight cycles
in the graph.
 If a negative weight cycle is detected, report the cycle.
2. Handle Negative Weight Cycles:
 Propose and implement an algorithmic strategy to handle negative weight cycles. This
could include, but is not limited to:
 Removing the cycle from the graph and finding the shortest paths in the modified graph.
 Implementing a threshold on the path length to avoid indefinite reduction due to the
cycle.
 Any other innovative approach that you believe addresses the problem effectively.
Detailed Instructions:
1. Input:
 The graph is given as a set of edges, where each edge is defined by three integers: (u, v,
w) representing an edge from vertex u to vertex v with weight w.
 The number of vertices (V) and edges (E) will be provided.
 The source vertex (S) from which to calculate the shortest paths will also be provided.
2. Output:
 For each vertex, output the shortest distance from the source vertex.
 If a negative weight cycle is detected, output the vertices forming the cycle.
 If applicable, output the shortest path distances for unaffected vertices.
3. Algorithm Implementation:
 Implement the Bellman-Ford algorithm and extend it to detect negative weight cycles.
 Devise a method to handle negative weight cycles and ensure the algorithm can provide
meaningful shortest paths where possible.
Submission:
 Submit your solution as a single PDF file on or before Sunday (09 June, 2024, 11:59
pm).
 Provide a brief report (1-2 pages) explaining your chosen strategy for handling negative
cycles and an analysis of its efficiency and potential limitations with an example.
Evaluation Criteria:
 Correctness: The algorithm correctly detects negative weight cycles and computes
shortest path distances accurately.
 Innovation: The proposed method for handling negative weight cycles is creative and
addresses the problem effectively.
 Clarity: The code is well-documented, and the approach is clearly explained in the
accompanying report.
 Efficiency: The solution is reasonably efficient, balancing complexity and performance.

You might also like