AP Computer Science Principles · Study guide

Big Idea 3: Variables, Operators, Strings & Lists

Big Idea 3 · Algorithms & Programming · Part 1 of 4

Variables, Operators,
Strings & Lists

The building blocks of every program: how data is stored, how expressions are evaluated, and how lists organize collections of values.

§1 What Big Idea 3 Covers

Big Idea 3 (AAP) is the programming and algorithms half of the course — the largest Big Idea at 30–35% of the exam. Most questions fall into one of these categories:

  • Tracing code — given a code segment, figure out what it outputs or returns.
  • Fixing bugs — given code that almost works, identify the change that fixes it.
  • Choosing the right construct — which loop, condition, or list operation.
  • Algorithms — linear vs. binary search, efficiency, heuristics.
  • Robot navigation — moving a robot through a grid.

Part 1 covers variables, operators, strings, and lists. Parts 2–4 cover selection, iteration, procedures, the robot, and algorithms.

Most important skill

The single most valuable skill for BI3 is hand-tracing code. Many questions are just "run this code in your head and tell me what happens." Being systematic — writing variable values in a table — beats trying to trace mentally.

§2 Variables and Data Types

A variable is a named storage location that holds a value. The assignment operator (←) puts a value into a variable:

a ← 5
b ← a + 3

After these lines: a = 5 and b = 8.

TypeWhat it storesExamples
NumberIntegers or decimals5, 3.4, -7
Booleantrue or falsetrue, false
StringSequence of characters"hello", "AP CSP"
ListOrdered collection of values[3, 7, 11, 2]
Common pitfall

Do not confuse the assignment arrow ← ("store this value") with the equality operator = ("does this equal that?"). a ← 5 stores 5 in a. a = 5 asks "is a equal to 5?" and returns true or false.

§3 Arithmetic & MOD

OperatorNameExampleResult
+Addition7 + 310
-Subtraction7 - 34
*Multiplication7 * 321
/Division17 / 53.4 (always decimal)
MODRemainder17 MOD 52
Definition · AP CSP division

Unlike Java, AP CSP pseudocode division always produces a decimal: 17 / 5 = 3.4, not 3. There is no "integer division" on the AP CSP exam. MOD gives you the remainder.

3.1 Common Uses of MOD

  • Even / odd: n MOD 2 = 0 means n is even.
  • Last digit: n MOD 10 gives the ones digit.
  • Cycle: i MOD 3 cycles through 0, 1, 2, 0, 1, 2, …
  • Divisibility: n MOD 5 = 0 means n is divisible by 5.

§4 Boolean Operators

Relational operators (=, ≠, <, >, ≤, ≥) compare two values and return true or false. Boolean operators (AND, OR, NOT) combine Boolean values:

ABA AND BA OR BNOT A
truetruetruetruefalse
truefalsefalsetruefalse
falsetruefalsetruetrue
falsefalsefalsefalsetrue
Key idea

AND is true only when both parts are true. OR is true when at least one part is true (inclusive — both true also counts). Don't let everyday English mislead you.

4.1 De Morgan's Laws

Two patterns appear on the exam often:

  • NOT (A AND B) = (NOT A) OR (NOT B)
  • NOT (A OR B) = (NOT A) AND (NOT B)

When you push NOT inside parentheses, AND flips to OR and vice versa.

§5 Strings

A string is a sequence of characters in double quotes. The exam uses strings mostly for concatenation, length, and comparison.

Exam tip · Concatenation names vary

The exam does not have one standard name for concatenation. You may see it as concat(a, b), combine(a, b), or described in plain English ("returns a followed by b"). Read the problem's own description — don't assume a name from a previous question.

§6 Lists

A list is an ordered collection of values. The exam uses 1-based indexing: the first element is at index 1, not 0.

letters[1] is "A"; letters[5] is "E". Accessing letters[0] or letters[6] causes an error.

6.1 List Operations

OperationWhat it does
LENGTH(list)Returns the number of elements.
APPEND(list, value)Adds value to the end. Length increases by 1.
INSERT(list, i, value)Inserts value at index i. Elements at or after i shift right.
REMOVE(list, i)Removes element at index i. Elements after i shift left. Length decreases by 1.
list[i] ← valueReplaces element at index i. Length unchanged.
FOR EACH x IN listIterates x through every element in order.
Common pitfall

INSERT and REMOVE shift other elements. After REMOVE(list, 2) on [A, B, C, D], the list becomes [A, C, D] — what was at index 3 is now at index 2. Watch out for this in loops that track indexes manually.

6.2 FOR EACH vs. Indexed Iteration

FOR EACH is simpler when you just need each element's value. Use an indexed loop when you need the position or need to compare adjacent elements.

§7 Key Terms

TermDefinition
AssignmentStoring a value in a variable (a ← value)
BooleanA value that is either true or false
ExpressionA combination of values, variables, and operators that evaluates to a result
IndexThe position of an element in a list (starting at 1 on the exam)
ListOrdered collection of values, indexed starting at 1
MODOperator giving the remainder of division
StringA sequence of characters in quotes
VariableA named storage location for a value

§8 Self-Check

  1. What is the difference between ← and = in AP CSP pseudocode?
  2. Evaluate: 17 MOD 4, 20 MOD 5, 3 MOD 7.
  3. Given letters = ["P", "Q", "R", "S", "T"], what is letters[3]? What does LENGTH(letters) return? What does the list look like after REMOVE(letters, 2)?
  4. Which is equivalent to NOT (a > 5 AND b < 10)? (a) a < 5 AND b > 10, (b) a ≤ 5 OR b ≥ 10, (c) a ≤ 5 AND b ≥ 10, (d) a > 5 OR b < 10
Show Answers
  1. ← is assignment (stores a value). = is comparison (returns true or false).
  2. 17 MOD 4 = 1. 20 MOD 5 = 0. 3 MOD 7 = 3 (dividend smaller than divisor → remainder is the dividend).
  3. letters[3] = "R". LENGTH = 5. After REMOVE(letters, 2): ["P", "R", "S", "T"] (length 4).
  4. (b). By De Morgan's: NOT(a > 5) OR NOT(b < 10) = a ≤ 5 OR b ≥ 10.