Algorithm Homework Help
Algorithm Homework Help
Graph Problems
• Graph reachability by BFS or DFS in O(|E|) time
• Graph exploration/connected components via Full-BFS or Full-DFS
• Topological sort / Cycle detection via DFS
• Negative-weight cycle detection via Bellman-Ford
• Single Source Shortest Paths (SSSP)
Restrictions SSSP
Graph Algorithm
Weights Name Running Time
O(·)
DAG Any DAG |V | + |E|
Relaxation
General Unweighted BFS |V | + |E|
General Non- Dijkstra |V | log |V | + |
negative Bellman-Ford E|
General Any |V | · |E|
• All Pairs Shortest Paths (APSP)
– Run a SSSP algorithm |V | times
– Johnson’s solves APSP with negative weights in O(|V |2 log |V | + |V ||
E|)
Problem 2. Unicycles
Problem 3. Doh!-nut
Momer has just finished work at the FingSprield power plant at
location p, and needs to drive to his home at location h. But along the
way, if his driving route ever comes within driving distance k of a
doughnut shop, he will stop and eat doughnuts, and his wife, Harge,
will be angry. Momer knows the layout of Fing Sprield, which can be
modeled as a set of n locations, with two-way roads of known driving
distance connecting some pairs of locations (you may assume that no
location is incident to more than five roads), as well as the locations
of the d doughnut shops in the city. Describe an O(n log n)-time
algorithm to find the shortest driving route from the power plant back
home that avoids driving within driving distance k of a doughnut shop
(or determine no such route exists).