Algorithm Expression (College Board AP® Computer Science Principles): Study Guide

Robert Hampton

Written by: Robert Hampton

Reviewed by: James Woodhouse

Updated on

Algorithm fundamentals

What is an algorithm?

  • An algorithm is a set of finite instructions that, when followed in order, accomplish a specific task

  • Finite means the algorithm must eventually reach an end; it cannot run forever

  • Every algorithm is constructed from three fundamental building blocks:

    • Sequencing: executing steps one after another in a specific order

    • Selection: making a decision based on a condition (e.g. IF a score is above 50, display "Pass")

    • Iteration: repeating a set of steps until a condition is met (e.g. REPEAT UNTIL all items have been checked)

  • These three components can be combined to structure any algorithm, regardless of complexity

  • Algorithm implementation is the process of translating an algorithm into working code in a programming language

  • Algorithms can be expressed in several ways before being turned into code:

Representation

Description

Best used for

Natural language

Steps written in everyday words

Explaining an algorithm to a non-technical audience

Flowchart diagram

Visual chart using shapes and arrows to show the flow of steps

Showing decision points and branching logic clearly

Pseudocode

Structured text that resembles code but is language-independent

Planning the logic before writing actual code

Natural language example

1. Ask the user to enter a number
2. Divide the number by 2 and check the remainder
3. If the remainder is 0, display "Even"
4. Otherwise, display "Odd"
 

Flowchart diagram example

Flowchart for checking if a number is even or odd. Input number, check if number mod 2 equals 0, display "Even" if yes, "Odd" if no, then stop.

Pseudocode example

number ← INPUT()
IF (number MOD 2 = 0)
{
   DISPLAY("Even")
}
ELSE
{
   DISPLAY("Odd")
}
 
  • All three representations describe the same algorithm; only the format changes

  • Natural language is the easiest to understand but the least precise

  • Pseudocode is the closest to actual code and the most useful for algorithm implementation

Examiner Tips and Tricks

  • When the AP exam describes a process and asks you to identify the algorithm or its components, look for the three building blocks: sequencing (steps in order), selection (a decision or condition), and iteration (repetition). Most exam questions about algorithms test whether you can recognize which building block is being used in a given scenario.

  • For the AP Create Performance Task, you must include sequencing, selection, and iteration in your program — being able to identify these in your own code is essential for the written responses.

Worked Example

A teacher describes the following process: "Look at each student's test score. If the score is 90 or above, add the student's name to the honor roll list. Repeat this for every student in the class."

Which algorithm building blocks are used in this process?

(A) Sequencing only

(B) Selection and iteration only

(C) Sequencing, selection, and iteration

(D) Iteration only

[1]

Answer:

(C) Sequencing, selection, and iteration [1 mark]

  • The process sequences steps in order, uses selection to check each score against the 90 threshold, and uses iteration to repeat for every student; all three building blocks are present

Unlock more, it's free!

Join the 100,000+ Students that ❤️ Save My Exams

the (exam) results speak for themselves:

Robert Hampton

Author: Robert Hampton

Expertise: Computer Science Content Creator

Rob has over 16 years' experience teaching Computer Science and ICT at KS3 & GCSE levels. Rob has demonstrated strong leadership as Head of Department since 2012 and previously supported teacher development as a Specialist Leader of Education, empowering departments to excel in Computer Science. Beyond his tech expertise, Robert embraces the virtual world as an avid gamer, conquering digital battlefields when he's not coding.

James Woodhouse

Reviewer: James Woodhouse

Expertise: Computer Science & English Subject Lead

James graduated from the University of Sunderland with a degree in ICT and Computing education. He has over 14 years of experience both teaching and leading in Computer Science, specialising in teaching GCSE and A-level. James has held various leadership roles, including Head of Computer Science and coordinator positions for Key Stage 3 and Key Stage 4. James has a keen interest in networking security and technologies aimed at preventing security breaches.