CMU 15-122: Principles of Imperative Computation
15-122 teaches imperative programming with correctness front and center: contracts, loop invariants, and reasoning about code in the C0 teaching language before transitioning to real C. It covers data structures from stacks and queues through hash tables, trees, and graphs, and it's the second course of the CMU CS core.
Fennie is independent and not affiliated with Carnegie Mellon University. This is an unofficial study guide.
What makes it hard
The course demands two fluencies at once: writing working code and proving it correct with preconditions, postconditions, and invariants. Students who can hack out working solutions but can't articulate why they work lose exactly the points 122 is designed to award. The late-semester transition to real C (pointers, memory, undefined behavior) compounds onto the reasoning workload.
What you'll cover
- • Contracts: pre/postconditions and assertions
- • Loop invariants and correctness reasoning
- • Arrays and searching/sorting
- • Stacks, queues, and linked structures
- • Hash tables and trees
- • C and memory management
The 15-122 study guide
How to study for CMU 15-122, step by step.
- 1
Learn to love the contracts early
Invariant-writing feels like bureaucracy until it starts catching your bugs, usually around week four. Practice writing pre/postconditions for small functions from day one; the skill is most of the course's grade surface.
- 2
Articulate why before running
For every loop you write, state the invariant and convince yourself it holds before testing. 122's exams ask for the reasoning explicitly, and it can't be reverse-engineered from working code under exam time.
- 3
Drill the data-structure operations on paper
Hash table inserts, tree rotations, heap operations: exams test them by hand with the reasoning attached. Draw the before-and-after for every operation type until it's mechanical.
- 4
Respect the C transition
When the course moves from C0 to real C, the safety rails vanish: pointers, casts, and undefined behavior arrive together. Re-do early exercises in C and learn what valgrind output means before the assignments require it.
- 5
Start assignments early because correctness takes passes
A 122 assignment isn't done when it runs; it's done when the contracts are right and the edge cases hold. That second phase takes real time, and it's where the points are.
Today
Today's 15-122 plan
What a Fennie Daily Plan looks like for 15-122. Yours is built from your own syllabus and adapts every day to your deadlines and progress.
First plan free, no card required. Fennie is independent and unaffiliated with your school.
FAQ
Is 15-122 hard?
It's a serious step up from 112: you're graded on proving code correct, not just making it work, and the late transition to real C adds memory management on top. Students who practice writing invariants from week one, rather than treating them as paperwork, handle it well.
What language does 15-122 use?
C0, a safe teaching subset of C designed at CMU with built-in contract support, transitioning to real C in the final stretch. The progression is deliberate: learn correctness reasoning with rails on, then apply it where the rails come off.
How do I prepare for 15-122?
Arrive with 112-level programming genuinely fluent. The course spends its difficulty budget on reasoning, not syntax. Early on, over-invest in writing contracts and invariants for simple code; it feels slow and it's the entire game by midterm season.
More CMU courses
15-112: Fundamentals of Programming and Computer Science
15-112 is CMU's famous accelerated introduction to programming in Python: control flow, functions, data structures, recursion, OOP, and efficiency, ending in an open-ended term project. Its public course website and the related CMU CS Academy platform give it a search footprint far beyond Pittsburgh.
15-110: Principles of Computing
15-110 is CMU's gentler introduction to computing, covering Python programming plus computing concepts like data representation, algorithms, and the limits of computation. It's designed for students who aren't CS majors or who want a runway before 15-112, and it's one of the largest courses on campus.
15-150: Principles of Functional Programming
15-150 teaches functional programming in Standard ML: types, recursion and induction, higher-order functions, and reasoning about programs as mathematical objects. It runs alongside 15-122 in the CMU CS core, and for most students it's the first time programming and proof become the same activity.
15-213: Introduction to Computer Systems
15-213 is the famous CS:APP course: data representation, x86-64 assembly, caches, memory, linking, exceptions, virtual memory, and concurrency, taught through the legendary lab sequence (bomb lab, attack lab, cache lab, malloc lab, shell lab, proxy lab). Its textbook and materials are used worldwide, making it one of the most-searched CS courses on the internet.