Skip to main content
CMU
Computer Science
12 credits

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. 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. 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. 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. 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. 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

Preview
65 min

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.

0 / 4 done~65m remaining
Keep this plan free

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