AP CSP
AP Computer Science Principles / All lessons / Big Idea 3: Algorithms and Programming
3Big Idea 3: Algorithms and Programming
AP CSP topic 3.3

Mathematical Expressions

An algorithm is a step-by-step process for completing a task. Every algorithm can be built from three parts: sequencing (steps in order), selection (choosing a path), and iteration (repeating). Expressions combine values and operators to produce a new value. AP pseudocode uses +, -, *, / and MOD, which gives the remainder after division, so 17 MOD 5 is 2. Operators follow the usual order of operations.

Mathematical Expressions vocabulary

  • Algorithm: A finite set of instructions that completes a task.
  • Sequencing: Running steps one after another in a set order.
  • Expression: A combination of values, variables, and operators that produces a single value.
  • MOD: An operator that gives the remainder after division, for example 17 MOD 5 = 2.

AP-style practice questions

Try each one, then open the answer. To save your progress, take this quiz in the interactive course.

Skill: Code Analysis

1. What is the value of 23 MOD 4?

  1. (A) 3
  2. (B) 5
  3. (C) 5.75
  4. (D) 19
Show answer

(A) 3 23 = 4 × 5 + 3, so the remainder is 3.

Skill: Code Analysis
a ← 3
b ← a * 2 + 4
c ← (b - a) / 7

2. What is the value of c?

  1. (A) 1
  2. (B) 2
  3. (C) 7
  4. (D) 10
Show answer

(A) 1 b = 3 × 2 + 4 = 10, then (10 - 3) / 7 = 1.

Skill: Algorithms and Program Development

3. Which of the following expressions evaluates to true exactly when the integer n is even?

  1. (A) n MOD 2 = 0
  2. (B) n MOD 2 = 1
  3. (C) n / 2 = 0
  4. (D) n * 2 = 0
Show answer

(A) n MOD 2 = 0 Even numbers have a remainder of 0 when divided by 2.

Skill: Algorithms and Program Development

4. Every algorithm can be built using which three structures?

  1. (A) Input, output, storage
  2. (B) Sequencing, selection, iteration
  3. (C) Lists, strings, numbers
  4. (D) Variables, comments, procedures
Show answer

(B) Sequencing, selection, iteration Sequencing, selection, and iteration are the building blocks of all algorithms.

Open 3.3 in the interactive course