Case study: CS 499 Enhancement Two, algorithms and data structures
ABCU course planner
My CS 300 project looked courses up in a tree. I rebuilt it to understand the catalog as a graph: it refuses catalogs no student could finish, lists every prerequisite, and builds term-by-term plans that say when they are the shortest possible.
- Random catalogs tested: never more than one term over the best plan
- 216,000
- Random catalogs tested: never more than one term over the best plan
- To find a prerequisite loop, even across 100,000 courses
- O(V + E)
- To find a prerequisite loop, even across 100,000 courses
- Test cases, with AddressSanitizer and UBSan in CI
- 83
- Test cases, with AddressSanitizer and UBSan in CI
- My role
- Solo: design, code, tests, benchmarks and CI
- When
- Built for CS 300 in June 2026, rebuilt in November
- Stack
- C++17, CMake, doctest, GitHub Actions on MSVC and GCC
01
Where it started
In CS 300 I wrote a menu-driven program for ABCU's academic advisors. It loaded the course catalog into an AVL tree and could print a course and its direct prerequisites. That was the assignment, and it did it.
For my capstone I reviewed it the way a teammate would and found twelve problems, A1 to A12. The worst were quiet ones: a catalog no student could ever finish loaded as if it were fine, and a bad reload wiped out the good data. Here is what changed for the ones an advisor would feel most.
| Finding | In CS 300 | Now |
|---|---|---|
| A1 | Only a course’s direct prerequisites were shown | Every prerequisite, in an order a student can follow, plus the longest chain |
| A2 | An alphabetical list was labeled a sample schedule | A real term-by-term plan with a proof of how good it is |
| A6 | A catalog with a prerequisite loop loaded as valid | Refused, with the loop spelled out course by course |
| A7 | A repeated course number was dropped without a word | The file is refused, naming both lines |
| A8 | A failed reload erased the good catalog | The new file is checked on its own and swapped in only if it passes |
| A9 | Splitting on every comma broke quoted titles | A strict RFC 4180 CSV parser |
| A12 | One file, no build script, no tests | CMake, 83 test cases and CI on two compilers |
02
Try it
This is the real ABCU catalog, planned in your browser with the same rules as the C++ program. Mark a course finished, squeeze the per-term limit down to one, or add the bad catalog line and watch the planner refuse it.
Plan a student's path through the ABCU catalog
Tap courses the student has finished. Point at a course to see its longest chain.
Most courses per term
Semester plan
The real catalog SNHU supplied for CS 300, planned in your browser with the same rules as the C++ program.
03
Decisions that mattered
Each one came with a cost. Here is what I chose, and what I gave up for it.
Refuse an impossible catalog, and say exactly why
Prerequisites form a directed graph. A three-color depth-first search finds any loop in O(V + E) and reports it the way an advisor would say it:
CSCI200 requires CSCI300, which requires CSCI200. The original loaded that same file and reported success.Admit what cannot be solved fast, then prove how close I get
Finding the fewest terms under a per-term limit is NP-complete in general (Ullman, 1975). So the planner uses Kahn's topological sort with a priority queue, taking the course with the longest chain still waiting on it first, in O(V log V + E).
Then it prints a lower bound beside every plan: the remaining courses divided by the limit, or the longest remaining chain, whichever is larger. When the plan meets that bound, it is the shortest possible, and the advisor is told so. When it does not, they are told how many terms it could be off by.
How I chose the tie-break: I tested two rules against an exact search on 216,000 small random catalogs. Most unlocks first matched the true best plan on 215,952 of them and never lost more than one term. Lowest course number first lost a term 165 times, so it lost the job.
Keep the AVL tree, but only after measuring it
In CS 300 I picked the AVL tree from Big-O analysis alone. This time I benchmarked it against
std::map,std::unordered_mapand a sorted vector on catalogs up to 100,000 courses.Big-O predicted the shape, but not the constants. The sorted vector beat both trees at loading, lookup and listing because its data sits together in memory. But adding one course to it meant shifting every later course: 311 times slower than my tree. The hash table looked courses up fastest, then had to sort itself to list them.
The trade-off: my tree is never the fastest. It stays within 13 times of the best on every operation, while each alternative has one operation where it falls apart.
No recursion in the graph code
A textbook recursive search uses one stack frame per course in the chain. I measured where that breaks: a stack overflow at 15,000 courses in a Debug build and 25,000 in Release. Every search in the planner keeps its own stack instead, and a test runs it on a 100,000-course chain.
Treat the catalog file as hostile
The catalog and everything typed at the menu are untrusted input. The parser follows RFC 4180 strictly, and the loader caps file size, line length, course count and prerequisites per course. Titles with control characters are refused, so a file cannot rewrite the advisor's terminal with escape codes (CWE-150).
A bad file is refused as a whole, with every problem listed by line number so it can be fixed in one pass. Memory is owned by smart pointers, and CI builds with AddressSanitizer and UBSan on every push.
04
What it measured
Measured on one laptop with the Release build: the median of seven timed runs after a warm-up. The scripts that produce every number, and the raw results, are in the repository.
Four ways to store the catalog, measured at 100,000 courses
Nanoseconds, shorter is faster. Bars use a logarithmic scale so the biggest gaps still fit. The fastest in each group is outlined.
Load per course
- AVL tree (mine)
- 453.7
- std::map
- 353.4
- unordered_map
- 167.7
- sorted vector
- 332.2
Look up per course
- AVL tree (mine)
- 274.1
- std::map
- 394.5
- unordered_map
- 73.0
- sorted vector
- 198.9
List in order per course
- AVL tree (mine)
- 10.1
- std::map
- 67.1
- unordered_map
- 378.3
- sorted vector
- 0.8
Add one course per insertion
- AVL tree (mine)
- 712.5
- std::map
- 609.5
- unordered_map
- 218.5
- sorted vector
- 221,902
Median of 7 runs, Release build, one laptop. My tree is never the fastest, and it is never the one that falls apart.
- Find a loop
- 1.0 ms
- Every chain length
- 1.0 ms
- Build a plan, 5 per term
- 30.8 ms
- Build the graph
- 63.9 ms
With 148,378 prerequisite links. Time per unit of work stays flat as catalogs grow 100 times, as O(V + E) says it should.
- Matched the best plan
- 215,952
- One term over
- 48
- More than one over
- 0
Out of 216,000 random catalogs of 4 to 12 courses, each checked against an exact search.
05
Check my work
Every change reached the main branch through a pull request that states the problem, the decision and its alternatives, the Big-O cost, the tests and the security effect. GitHub Actions builds each push on Windows with MSVC and on Ubuntu with GCC and both sanitizers, with warnings treated as errors.
# build and run the 83 test cases (Developer PowerShell) cmake --preset msvc-debug cmake --build --preset msvc-debug ctest --preset msvc-debug # on Linux, with AddressSanitizer and UBSan cmake --preset gcc-sanitize