Skip to content
Now Accepting Applications for 2027-2028Apply
ITMagicITMagicAcademy
AP resources
APComputer ScienceCSP

Algorithms & Pseudocode

AP Computer Science Principles — algorithms and the three building blocks (sequencing, selection, iteration) using College Board exam-reference pseudocode. Worked example and exam tip.

An algorithm is a finite set of instructions that accomplishes a task. Every algorithm — no matter how complex — is built from just three control structures. AP CSP uses College Board exam-reference pseudocode, so learn its notation.

The three building blocks

  1. Sequencing — steps run in order, top to bottom.
  2. Selection — a decision with IF / ELSE.
  3. Iteration — repetition with REPEAT n TIMES or REPEAT UNTIL (condition).

Exam-reference pseudocode

  • Assignment uses a left arrow: a ← 5
  • Output: DISPLAY(expression) Input: INPUT()
  • MOD gives the remainder: 7 MOD 3 is 1

```

total ← 0

REPEAT 5 TIMES

{

total ← total + 2

}

DISPLAY(total)

```

This displays 10.

Selection example

```

IF (score ≥ 60)

{ DISPLAY("Pass") }

ELSE

{ DISPLAY("Fail") }

```

Worked example

What does n MOD 2 = 0 test? It is true when n is even (remainder 0 when divided by 2) — a very common CSP pattern.

Exam tip

You must be able to trace pseudocode by hand and predict the output, and recognise when two algorithms are equivalent. Watch loop counts carefully (REPEAT 5 TIMES runs exactly 5 times). Also know linear vs binary search and that some problems are "undecidable" or only solvable in reasonable (polynomial) vs unreasonable (exponential) time.

Short Lesson Video

The lesson video for this topic will be added soon.

Mock Exam

The mock exam for this topic will be added soon.

Practice Quiz

Test yourself: instant results and explanations.

  1. 1. Starting with total ← 0, what does REPEAT 5 TIMES { total ← total + 2 } display?

  2. 2. The condition n MOD 2 = 0 is true when n is:

  3. 3. The three building blocks of every algorithm are:

Need support with this topic?

In a free 30-minute intro call we assess your level and build a study plan tailored to you.

Free intro call