CPSC 203, 2025 W2
March 26, 2026
SSSP: “many one-way routes from home (tree)” vs TSP: “one big round trip through everyone (loop)”
| Aspect | SSSP (Single-Source Shortest Paths) | TSP (Travelling Salesperson) |
|---|---|---|
| Goal | Shortest route from one start to each vertex | One cheapest tour visiting all vertices and returning |
| Shape | Tree of paths from the source | Cycle through all vertices |
| Must visit all? | No – each path can skip most vertices | Yes – must visit every vertex exactly once |
| Overlap | Paths often share edges | Tour is one sequence; no repeated visits |
| Difficulty | Fast algorithms (e.g., Dijkstra) | NP-hard; exact solution is hard for large graphs |
Steps to assemble our solution:
________________________________________
________________________________________
________________________________________
________________________________________
________________________________________
Verify references here:
What structure should we use?
dist['Vancouver']['Bellingham'] -> int
path['Vancouver']['Bellingham'] -> list
example: dist['Van']['Bel'] = nx.shortest_path_length(G, 'Van', 'Bel', weight='length')
tours = list(itertools.permutations(list(dferrands['node'])))
We assemble each candidate solution as an arrangement of all of the errands:
Ex: A D B E F C
How do we find the total distance if we do the errands in the suggested order?
dfdist[A][D] + dfdist[D][B] + ... + dfdist[C][A]
There are lots of applications: