now that when we have a graph with negative edge costs, Dijkstra’s algorithm 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 +1. (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.”

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

We know that when we have a graph with negative edge costs, Dijkstra’s algorithm 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 +1. (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?

Expert Solution
steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY