Add notes on the topic
This commit is contained in:
BIN
notes-and-examples/2026.08.27/classes.png
Normal file
BIN
notes-and-examples/2026.08.27/classes.png
Normal file
Binary file not shown.
5
notes-and-examples/2026.08.27/overview.md
Normal file
5
notes-and-examples/2026.08.27/overview.md
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
## Overview
|
||||||
|
|
||||||
|
We'll go over exercise 2 from [last week](../2026.08.20/overview.md), as well as
|
||||||
|
a new topic: [topological sort](./topological_sort.md). Try to complete the
|
||||||
|
exercise from the document.
|
||||||
27
notes-and-examples/2026.08.27/topological_sort.md
Normal file
27
notes-and-examples/2026.08.27/topological_sort.md
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
## Class ordering
|
||||||
|
|
||||||
|
These are some classes for Chapman University, for
|
||||||
|
the [computer science program](https://catalog.chapman.edu/preview_program.php?catoid=33&poid=6408&print).
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
> [!QUESTION] What type of graph is this?
|
||||||
|
|
||||||
|
We say that a class is a *prerequisite* or a *dependency* of another class
|
||||||
|
if we need to take it before that other class. So, we need to take CPSC 230
|
||||||
|
before CPSC 231, for example.
|
||||||
|
|
||||||
|
Could you come up with something like this for your school?
|
||||||
|
|
||||||
|
## The algorithm
|
||||||
|
|
||||||
|
If you were to come up with a list of classes, such that the list of classes
|
||||||
|
is in the order which you need to take them, what would that look like?
|
||||||
|
|
||||||
|
This order is what we're trying to achieve with the topological sort
|
||||||
|
algorithm. Note that there can be multiple correct solutions.
|
||||||
|
|
||||||
|
## The exercise
|
||||||
|
|
||||||
|
Let's write the algorithm. First, test it against the Chapman classes, then
|
||||||
|
put in your classes and see how it fares against that.
|
||||||
@@ -15,7 +15,7 @@ classes = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
def topological_sort(adjacency_list: dict[str, set[str]]):
|
def topological_sort(adjacency_list: dict[str, set[str]]):
|
||||||
# return the sorted ordering
|
# return the sorted ordering ['CPSC 230', 'ENGR 101', 'CPSC 231', ...]
|
||||||
return []
|
return []
|
||||||
|
|
||||||
print(topological_sort(classes))
|
print(topological_sort(classes))
|
||||||
|
|||||||
Reference in New Issue
Block a user