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.
1. What is the value of 23 MOD 4?
- (A) 3
- (B) 5
- (C) 5.75
- (D) 19
Show answer
(A) 3 23 = 4 × 5 + 3, so the remainder is 3.
a ← 3 b ← a * 2 + 4 c ← (b - a) / 7
2. What is the value of c?
- (A) 1
- (B) 2
- (C) 7
- (D) 10
Show answer
(A) 1 b = 3 × 2 + 4 = 10, then (10 - 3) / 7 = 1.
3. Which of the following expressions evaluates to true exactly when the integer n is even?
- (A) n MOD 2 = 0
- (B) n MOD 2 = 1
- (C) n / 2 = 0
- (D) n * 2 = 0
Show answer
(A) n MOD 2 = 0 Even numbers have a remainder of 0 when divided by 2.
4. Every algorithm can be built using which three structures?
- (A) Input, output, storage
- (B) Sequencing, selection, iteration
- (C) Lists, strings, numbers
- (D) Variables, comments, procedures
Show answer
(B) Sequencing, selection, iteration Sequencing, selection, and iteration are the building blocks of all algorithms.