Computer Algorithms (506994-002). Work with your neighbor (pair work). Write your names here:
Name 1: _______________________ Name 2: _______________________
CampusNav's six-location graph, source = Gate (G):
Gate(G) --3-- Library(L) --2-- CS-Building(C)
| | |
4 5 2
| | |
Dorm(D) --6-- Gym(Y) ----3---- Cafeteria(F)
Edges (undirected, walking minutes): G-L 3, G-D 4, L-C 2, L-Y 5, D-Y 6, Y-F 3, C-F 2.
Worksheet Part A (~15 minutes) - Dijkstra by Hand
Hand-simulate Dijkstra's algorithm from Gate. At each round, write down which vertex you settle and update the distance table.
A1. Fill in the distance table, one round at a time. Start with Gate = 0 and everything else = ∞. After each round, write the updated distances (leave a cell unchanged if nothing improved it).
| Vertex | Round 0 (init) | Round 1 | Round 2 | Round 3 | Round 4 | Round 5 | Round 6 |
|---|---|---|---|---|---|---|---|
| Gate | 0 | ||||||
| Library | ∞ | ||||||
| Dorm | ∞ | ||||||
| CS-Building | ∞ | ||||||
| Gym | ∞ | ||||||
| Cafeteria | ∞ |
A2. Settlement order. Write, in order, which vertex got settled in each round:
Round 1: _______ Round 2: _______ Round 3: _______ Round 4: _______ Round 5: _______ Round 6: _______
A3. Explain one "no update" round. Find at least one round in your trace where relaxing an edge did not improve a distance. Which edge was it, and what was the candidate distance that got rejected?
A4. Final answer. What is the shortest distance from Gate to the Cafeteria, and what is the actual route (list the vertices in order)?
Distance: _______ Route: _____________________________________
Worksheet Part B (~15 minutes) - When Dijkstra Breaks
CampusNav's design team adds a one-way "covered walkway" shortcut credit: Cafeteria → Library costs −4 minutes (directed - it only applies in that direction).
B1. Re-run Dijkstra with the new edge. Using your Part A trace as a starting point, mark clearly: in which round does Dijkstra settle Library? In which round does Dijkstra first discover the new Cafeteria → Library edge (i.e. which round settles Cafeteria)?
Library settled in round: _______ Cafeteria settled in round: _______
B2. Does Dijkstra ever use the new edge? Standard Dijkstra only relaxes edges going into vertices that are still unsettled. Given your answer to B1, does Dijkstra ever actually check the Cafeteria → Library edge as a way to improve Library's distance? Why or why not?
B3. Compute the "what if" by hand. What distance to Library would the Cafeteria → Library edge offer, if Dijkstra did check it? (Use Cafeteria's final distance from Part A.) Is this offer better than, worse than, or equal to Library's actual settled distance?
Offer: _______ Compared to settled distance: (circle one) better / worse / equal
B4. The danger, in your own words. Even though the numbers in B3 came out the way they did, explain in 2-3 sentences why relying on Dijkstra with a negative edge present is still risky in general. (Hint: what would happen to the loop Library → CS-Building → Cafeteria → Library if the shortcut credit were −5 instead of −4?)
B5. Run Bellman-Ford instead. Relax every edge (both directions of each walkway, plus the one-way −4 edge) once, then check: did anything change compared to your Part A table? How many total rounds would you need to run to be guaranteed correct, regardless of edge order, for a 6-vertex graph?
Anything changed after round 1? _______ Guaranteed-correct rounds needed: _______
Worksheet Part C (~10 minutes) - P vs. NP Practice
C1. Is "find the shortest path between two given buildings on CampusNav's campus graph" in P, in NP, or both? Justify in one sentence.
C2. True or False, with a one-sentence justification: "NP stands for 'not polynomial,' meaning these problems can never be solved quickly."
C3. CampusNav's scavenger hunt (visit all 8 buildings exactly once, minimize total distance) gets a specific proposed 8-building route from a student.
(a) How would you check, in polynomial time, whether that specific route is valid and compute its total distance?
(b) Why doesn't being able to check that one route quickly mean CampusNav can find the best route quickly?