Homework 5. Due: Monday, March, 7 2022 Before 8am EDT. Practice Problems (Don't Turn In) : Dijkstra's Algorithm
Homework 5. Due: Monday, March, 7 2022 Before 8am EDT. Practice Problems (Don't Turn In) : Dijkstra's Algorithm
Homework 5.
Due: Monday, March, 7 2022 before 8am EDT.
1. Dijkstra’s algorithm: This is not covered in the lectures because it’s the sort of thing many
of you have seen before, possibly multiple times. If you haven’t seen it, or need a refresher,
look at Chapter 4.4 of [DPV]. We will assume you know the answer to the following questions:
(a) What is the input and output for Dijkstra’s algorithm?
(b) What is the running time of Dijkstra’s algorithm using min-heap (aka priority queue)
data structure? (Don’t worry about the Fibonacci heap implementation or running time
using it.)
(c) What is the main idea for Dijkstra’s algorithm?
2. [DPV] Problem 3.3 (Topological ordering example)
1
Name: 2
Instructions.
For the graded problems, you are allowed to use the algorithms from class as black-boxes
without further explanation. These include
• DFS (outputs connected components, a path between two vertices, topological sort
on a DAG. You also have access to the pre and post arrays!), BFS and the Explore
subroutine.
• Dijkstra’s algorithm to find the shortest distance from a source vertex to all
other vertices and a path can be recovered backtracking over the pre labels.
• Bellman-Ford and Floyd-Warshall to compute the shortest path when weights are allowed
to be negative.
• SCCs which outputs the strongly connected components, and the metagraph of connected
components.
• Kruskal’s and Prim’s algorithms to find MST.
• Ford-Fulkerson and Edmonds-Karp to find max flow on networks.
When using a black-box, make sure you clearly describe which input you are passing
to it and how you use the output from or take advantage of the data structures created
by the algorithm. To receive full credit, your solution must:
• Include the description of your algorithm in words (no pseudocode!).
Unless otherwise indicated, black-box graph algorithms should be used without modification.
Example: I take the input graph G, I first find the vertex with largest degree, call it v ∗ . I take the
complement of the graph G, call it G. Run Dijkstra’s algorithm on G with s = v ∗ and then I get
the array dist[v] of the shortest path lengths from s to every other vertex in the graph G. I square
each of these distances and return this new array.
We don’t want you to go into the details of these algorithms and tinker with it, just use it as a
black-box as showed with Dijkstra’s algorithm above. Make sure to explain your algorithm in words,
no pseudocode.
2
Name: 3
(a) Given the limitation on your car’s fuel tank capacity, show how to determine in linear time
whether there is a feasible route from s to t.
(b) You are now planning to buy a new car, and you want to know the minimum fuel tank
capacity that is needed to travel from s to t. Give an O((|V | + |E|)log|V |) algorithm to determine
this. (Note: to solve part (b) you may modify known algorithms – if you do so, be sure to explain
your modifications in detail and how those modifications impact the known run time, if at all.)