Add the topological sort sample and the solution

This commit is contained in:
2026-08-20 21:40:07 -04:00
parent 8a2ee0a557
commit 4e7375c732
2 changed files with 68 additions and 0 deletions

View File

@@ -0,0 +1,21 @@
from collections import deque
# double-ended queue, this may be helpful
# see the docs: https://docs.python.org/3/library/collections.html#collections.deque
classes = {
'CPSC 230': {'CPSC 231'},
'CPSC 231': {'CPSC 350', 'CPSC 330'},
'CPSC 350': {'CPSC 380', 'CPSC 408', 'CPSC 406'},
'CPSC 330': {'CPSC 351'},
'CPSC 351': set(),
'ENGR 101': set(),
'CPSC 380': set(),
'CPSC 406': set(),
'CPSC 408': set()
}
def topological_sort(adjacency_list: dict[str, set[str]]):
# return the sorted ordering
return []
print(topological_sort(classes))