Dijkstra's algorithm problems [00NS]
- October 3, 2026
[D1] Dijkstra with negative weight (1pt) [00NT]
- October 3, 2026
Why doesn't Dijkstra's algorithm work if edges in the graph can have negative weights (even if there are no directed cycles)? Give an example of a directed graph with no directed cycles where Dijkstra's algorithm fails to find the minimum-weight path between a pair of vertices. Be sure to demonstrate that you understand why your graph is a counterexample; that is, show what Dijkstra's algorithm does on your example graph, and explain why the path it finds is not the minimum-weight path.
[D2] Dijkstra for longest paths (1pt) [00NU]
- October 3, 2026
What happens if we replace the word “smallest” in Dijkstra’s algorithm with the word “biggest”—that is, we use a max priority queue so we pull out the vertex u with the maximum distance on each iteration, and for each edge (u,v) we update d[v] to be the maximum of d[v] and the sum d[u] + w_{uv}. Can we use this modified Dijkstra’s algorithm to find longest paths bewteen nodes in any graph without directed cycles? Prove that this works, or give a counterexample (with explanation) where it doesn’t.
[K9] Kattis: Dijkstra problem (3 pts) [00OS]
- October 9, 2026
Solve one of the following Kattis problems requiring Dijkstra's Algorithm:
[D3] The Roving Photographer (2 pts) [00OT]
- October 9, 2026
Phoebe the Photographer is just leaving for work at the small-town newspaper where she works as a staff photographer, when she suddenly remembers that she was supposed to take a photograph to decorate page C17. She will just have to take a photograph on the way, but she is worried about getting to work late!
Phoebe's town can be represented by a directed, weighted graph with V vertices and E edges, where the weight on each edge represents the time needed to travel along that street in the given direction. (As usual, two-way streets are represented by one edge in each direction, possibly with different weights.) One particular vertex represents Pheobe's house, and another vertex represents her work. There are various locations (i.e. vertices) at which Pheobe could take a photograph; each such vertex has a number representing the amount of time Pheobe would need to spend taking a photograph there (some photographs can be taken quickly, while others need a while to set up).
Pheobe needs to travel to some location where she can take a photograph, pause long enough to take the photo, and then travel to her workplace. Explain how Pheobe could compute such a path which is as short as possible, and analyze the running time of your algorithm.
Hint.
- October 9, 2026
You may come up with a \Theta (VE\lg V) algorithm, but it is possible to do better: it can be done in \Theta (E \lg V) time.
Hint.
- October 9, 2026
How can you transform the graph so that the problem is solved by a single call to Dijkstra's Algorithm?
Hint.
- October 9, 2026
Consider duplicating each vertex, one to represent visiting that location with no photograph taken, and another to represent visiting that location with a photograph already taken.