Add new overview + exercise files + update last week's examples

This commit is contained in:
2026-08-03 15:40:07 -07:00
parent fafa36aad3
commit da7acf5f78
4 changed files with 75 additions and 6 deletions

View File

@@ -32,7 +32,7 @@ with 2nd-degree connections in the second inner list, and so forth.
Your algorithm should take a starting person and a *maximum N*, such that your
algorithm does not return connections past the maximum Nth connection.
Example: `nthDegreeConnections(Mallory, 2)` would return the following lists
Example: `nth_degree_connections(Mallory, 2)` would return the following lists
in a list:
- `[Carol, Grace]`: 1st-degree connections
@@ -55,15 +55,27 @@ Your algorithm should take the starting and ending points, and return a list
of tuples. Each tuple should contain the traversal from point A to point B,
followed by the total weight.
In this fictitious graph, calling `possiblePaths("Santa Ana", "San Francisco")`
In this fictitious graph, calling `possible_paths("Santa Ana", "San Francisco")`
should yield the return below. Which path is better?
```python
graph = {
"Santa Ana": [("Los Angeles", 5), ("Palm Springs", 50)],
"Los Angeles": [("San Francisco", 25), ("Santa Ana", 5)],
"Palm Springs": [("San Francisco", 30), ("Santa Ana", 50)],
"San Francisco": [("Los Angeles", 25), ("Palm Springs", 30)]
'Santa Ana': {
'Los Angeles': 5,
'Palm Springs': 50
},
'Los Angeles': {
'San Francisco': 25,
'Santa Ana': 5
},
'Palm Springs': {
'San Francisco': 30,
'Santa Ana': 50
},
'San Francisco': {
'Los Angeles': 25,
'Palm Springs': 30
}
}
```

View File

@@ -0,0 +1,28 @@
# see the overview from 2026.07.31
sample_graph = {
'Alice': set(['Bob', 'Carol']),
'Bob': set(['Alice', 'Dave']),
'Carol': set(['Alice', 'Eve', 'Mallory']),
'Dave': set(['Frank', 'Eve', 'Bob']),
'Eve': set(['Carol', 'Grace', 'Dave']),
'Frank': set(['Dave', 'Heidi']),
'Grace': set(['Eve', 'Ivan', 'Mallory']),
'Heidi': set(['Frank', 'Ivan']),
'Ivan': set(['Heidi', 'Grace']),
'Mallory': set(['Carol', 'Grace'])
}
def nth_degree_connections(
graph: dict[str, set[str]],
starting_vertex: str,
max_n: int
):
# TODO
pass
print(nth_degree_connections(sample_graph, 'Mallory', 2))
print(nth_degree_connections(sample_graph, 'Alice', 4))
print(nth_degree_connections(sample_graph, 'Ivan', 1))
print(nth_degree_connections(sample_graph, 'Grace', 0))
print(nth_degree_connections(sample_graph, 'Carol', 100))

View File

@@ -0,0 +1,26 @@
# see the overview from 2026.07.31
sample_graph = {
'Santa Ana': {
'Los Angeles': 5,
'Palm Springs': 50
},
'Los Angeles': {
'San Francisco': 25,
'Santa Ana': 5
},
'Palm Springs': {
'San Francisco': 30,
'Santa Ana': 50
},
'San Francisco': {
'Los Angeles': 25,
'Palm Springs': 30
}
}
def possible_paths(start: str, end: str):
# TODO
pass
print(possible_paths('Santa Ana', 'San Francisco'))

View File

@@ -0,0 +1,3 @@
## Outline
Let's work on the exercises from [last week](../2026.07.31/overview.md).