Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

(20 points) We know that when we have a graph with negative edge costs, Dijkstra's algo rithm is not guaranteed to work. (a) Does



(20 points) We know that when we have a graph with negative edge costs, Dijkstra's algo rithm is not guaranteed to work. (a) Does Dijkstra's algorithm ever work when some of the edge costs are negative? Explain why or why not. (b) Find an algorithm that will always find a shortest path between two nodes, under the assumption that at most one edge in the input has a negative weight. Your algorithm should run in time O(m log n), where m is the number of edges and n is the number of nodes. That is, the runnning time should be at most a constant factor slower than Dijkstra's algorithm. To be clear, your algorithm takes as input (i) a directed graph, G, given in adjacency list form. (ii) a weight function f, which, given two adjacent nodes, v, w, returns the weight of the edge between them. For non-adjacent nodes v, w, you may assume f(v, w) returns |o. (iii) a pair of nodes, s, t. If the input contains a negative cycle, you should find one and output it. Otherwise, if the graph contains at least one directed path from s to t, you should output a shortest path. Otherwise, output "No path." (c) Can you generalize your idea to graphs with two negative edges? Three? What happens to the running time as the number of edges increases?

Step by Step Solution

There are 3 Steps involved in it

Step: 1

a Dijkstras algorithm does not work correctly with negative edge ... 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

Step: 3

blur-text-image

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

Global Strategy

Authors: Mike W. Peng

5th Edition

0357512367, 978-0357512364

More Books

Students also viewed these Programming questions