CPSC 203, 2025 W1
November 20, 2025
The data we use for computation is separate from the visualization.
Initialize structure:
v,
d[v] = INF,p[v] = nullInitialize source: d[s] = 0
Repeat these steps n times:
d[] unlabelled vertex: vvw of v,
d[w])
d[w] = ______________p[w] = v____________________________________ ____________________________________ ____________________________________
____________________________________ ____________________________________ ____________________________________
What We’ll See in the Demos
Convert map data to graph
Identify amenities (Starbucks)
Compute shortest route between two landmarks
Visualize everything interactively
| Algorithm | Data Structure | Costs? | Shortest? | Frontier |
|---|---|---|---|---|
| DFS | Stack | ignored | no | dive deep |
| BFS | Queue | all equal | yes | explore in layers |
| Dijkstra | Priority Queue | any non-neg | yes | explore by shortest known distance |
REALLY great example: https://www.youtube.com/watch?v=wsSEKm-rU6U
OSMNX reference: https://github.com/gboeing/osmnx-examples
Tutorial: https://gist.github.com/psychemedia/b49c49da365666ba9199d2e27d002d07
Determine the least cost route through a set of given locations, returning to the start.


“Given a list of cities, and the distances between each pair of cities, what is the shortest possible route that visits each city exactly once and returns to the origin city?”
Classic problem on graphs
First known mention was in 1930
________________________________________
Suppose you have 6 locations. How many different candidate solutions are there? Generalize to k locations?

________________________
________________________
________________________
________________________
________________________
https://medium.com/data-science/around-the-world-in-90-414-kilometers-ce84c03b8552
Steps to assemble our solution:
________________________________________
________________________________________
________________________________________
________________________________________
________________________________________
lambda Do?Goal: Create a new column (latlong) and fill it with coordinates for each errand in the dataframe.
How it works:
df.apply(..., axis=1): Run a function once for each row.
lambda row: ox.geocode(row['errand']): A tiny inline function. Read it as: “Given a row, look up the place name in row['errand'],geocode it, and return the (lat, lon).”
The returned value becomes the entry in the new latlong column.
Why lambda? We only need this function once, so we write it right where it’s used.
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?
There are lots of applications: