Skip to main content
AP CSP course

C22 · Topic 3.3 · 40 minutes · AAP-2.A, AAP-2.B, AAP-2.C

Sequencing an algorithm

By the end you can:

  • Express an algorithm in precise steps.
  • Trace interactions between expressions and assignments.
  • Explain when reordering changes behaviour.

Before this lesson: topics 3.1.

Expression
A combination of values and operators evaluated to produce a value.
MOD
The remainder operation; for positive integers a and b,a MOD b is the remainder on division byb.

Understand

An algorithm is a finite, precise sequence of steps for a task. It can be expressed in natural language, diagrams or pseudocode; a programming language is one representation, not its definition. State what inputs are allowed and what result should be produced before comparing implementations.

Sequencing affects values when a later statement reads something changed earlier. Two independent assignments might be reorderable, but a calculation that depends on an updated variable is not generally interchangeable with its predecessor. Use a trace or a counterexample to justify a claim about reordering.

Worked example

x←4;y←9;x←x+y;y←x MOD 5.

  1. After initialization,x 4 andy 9.
  2. Updating x produces 13.
  3. Then y receives 13 MOD 5=3; swapping the last two instructions would use the earlier x value and change the result.

Explore each concept

Choose a concept, change its inputs and follow the explanation. Each example models the stated rule or scenario; completing it is practice rather than evidence of mastery.

  • Arithmetic precedence
  • Parentheses and reordering
  • Numeric addition versus concatenation
Open this example on its own

Change it · step through · explain

Change an input, predict what will happen, then advance one step. Read why the state changes, reset and experiment. This fixed teaching model does not save progress or award XP.

Ready · Make a prediction

Ready to explore: Precedence, division, MOD and sequencing
  1. a (0–100)4Waiting
  2. b (1–100)5Waiting
  3. Expressiona+2*bWaiting

Ready to explore: Precedence, division, MOD and sequencing

Why: Change an input, predict the first effect, then advance one step.

Try this: Change one input or choose another listed case. Predict the effect, reset and compare the states and governing rule.

Step through and experiment

Change it · step through · explain

Change an input, predict what will happen, then advance one step. Read why the state changes, reset and experiment. This fixed teaching model does not save progress or award XP.

Ready · Make a prediction

Ready to experiment
  1. Input 14Waiting
  2. Input 29Waiting
  3. Input 35Waiting

Ready to experiment

Why: Predict the first change, then advance one step.

Try this: Change one input, predict the difference, then reset and compare.

Check a misconception

Claim: Any rearrangement of the same statements gives the same result.

Data dependencies can make order essential.

Guided practice

Trace the version with the last two instructions swapped.

Work with a partner. Make a prediction, compare your reasoning, then identify the rule that supports your answer.

Independent transfer

Describe in plain language an algorithm to find the total capacity of a finite club list.

Exit check

What makes a natural-language algorithm precise enough to test?

Write your reasoning before comparing with a classmate. If your teacher assigned this task, submit it through My classes to save your work and receive feedback.

Check yourself

  1. Question 1 of 2A later calculation uses an updated variable. What should be checked before reordering?

    Select one answer.

  2. Question 2 of 2Which TWO are valid ways to represent an algorithm?

    Select exactly two answers (0 of 2 selected).

Your practice so far

Check an answer to see its rationale.

Teacher guidance and scoring