Skip to main content
Back to module
Teaching Computer Science · CS Pedagogy

Parsons problems and worked examples

Reading34mLesson 3 of 3 in this module

Use worked examples, subgoal labels and Parsons problems to reduce cognitive load for novice programmers.

Why it matters

Writing a program from scratch asks a novice to do many things at once: recall syntax, choose a plan, remember variable names, and track what the code does. Cognitive load theory explains why that overloads beginners: working memory can hold only a few new items at a time. Two techniques with strong research support reduce that load while keeping students thinking: worked examples and Parsons problems.

Worked examples

A worked example is a complete, step-by-step solution that students study before solving similar problems themselves. Research across maths and programming (often called the worked-example effect) shows that beginners learn more from studying good examples than from solving the same number of problems unaided.

Make worked examples more effective by:

  • Pairing each example with a practice problem that has the same structure but a different context.
  • Subgoal labels: short headings that name the purpose of each chunk of code. Lauren Margulieux and colleagues found that labelled examples improve transfer to new problems.
  • Fading: first a full example, then one with a step missing, then two, until students write the whole thing.
  • Self-explanation prompts: "Why does this line come before the loop?"
# Subgoal: set up a counter
count = 0
# Subgoal: look at each item
for score in scores:
    # Subgoal: test the condition
    if score >= 50:
        # Subgoal: update the counter
        count = count + 1
# Subgoal: report the result
print(count)

The subgoals ("set up a counter, look at each item, test, update, report") are a reusable plan students can apply to "count the words longer than five letters" next.

Parsons problems

A Parsons problem (introduced by Dale Parsons and Patricia Haden in 2006) gives students the correct lines of a program in scrambled order. Students drag them into the right order and, in some versions, the right indentation.

Why they work:

  • Students focus on logic and order, not syntax recall or typing.
  • Every attempt uses correct syntax, so they see good code.
  • They are quick to solve and quick to check automatically.
  • Barbara Ericson's research found Parsons problems can produce similar learning to writing the same code, in less time.

Variations:

  • Distractors: extra lines that are plausible but wrong (an off-by-one range, = instead of ==). Choose distractors that match common misconceptions, so a wrong choice is diagnostic.
  • Indentation required: students must also indent correctly, which tests understanding of blocks.
  • Faded Parsons: some lines have blanks to fill in, as a bridge to writing code.
  • Adaptive Parsons: the tool combines blocks or removes distractors after repeated failures (Runestone Academy supports this).

Worked example: designing a Parsons problem

Goal: practise the accumulator pattern.

  1. Write a correct solution of 5-8 lines (longer ones get frustrating).
  2. Split it into blocks, one line each (or two lines that always go together).
  3. Add one or two distractors based on misconceptions you have seen: for example count = 0 inside the loop.
  4. Decide whether indentation is part of the puzzle.
  5. Write the checking rule: exact order, or any order that produces correct output (some lines can be swapped legally).
  6. Test it on a colleague and time it: 2-5 minutes is a good target.

Free tools include Runestone Academy and js-parsons; you can also do them on paper strips.

Common mistakes

  • Examples without practice. Studying examples helps only when followed by similar problems.
  • Too many distractors. One or two is enough; more turns the puzzle into guesswork.
  • Only one correct order when others work. If two lines can be swapped, accept both or redesign.
  • Using Parsons forever. They are a bridge. Fade toward writing code independently.

Quick recap

  • Beginners have limited working memory; worked examples and Parsons problems reduce load.
  • Use subgoal labels, fading and self-explanation with worked examples.
  • Parsons problems scramble correct code; distractors should match real misconceptions.
  • Keep puzzles short, check alternate valid orders, and fade toward independent writing.

Try it

Open the Do tab: solve a Parsons problem, add a distractor and write the shuffle and grading functions.

Also in this lesson: