The Stacks
BIG IDEA 3: ALGORITHMS AND PROGRAMMING · CHEAT SHEET

Algorithms and Programming — the one-page version

Every key term and every exam tip from the 18 topics in this big idea. Print it, fold it, read it on the bus.

3.1Variables and Assignments

Variable
a named storage location that holds one value at a time
Assignment
storing the result of an expression in a variable, written with ← in AP pseudocode
Data type
the kind of value a variable holds: number, Boolean, string, or list
Tip: On any tracing question, draw a two-column table: variable name, current value. Update one row per line of code. Nearly every wrong answer on these questions comes from doing the update in your head and slipping.

3.2Data Abstraction

Data abstraction
using a structure like a list so a collection of values can be treated as one unit
List
an ordered sequence of elements, each accessed by index
Element
a single value in a list
Index
the position of an element in a list; starts at 1 in AP pseudocode
Tip: Index questions are a constant source of lost points. AP pseudocode is 1-indexed. list[0] is an error. If a question shows real-language code (Python-style), it will say so — otherwise assume 1-based.

3.3Mathematical Expressions

MOD
the remainder after integer division; a MOD b
Expression
a combination of values, variables, and operators that evaluates to a single value
Sequencing
executing statements in order, one after another
Tip: Whenever you see MOD, ask "what's the remainder?" and do the long division. For expressions mixing MOD with other operators, put parentheses around the MOD part mentally — MOD has the same precedence as multiplication, so a + b MOD c computes the MOD first.

3.4Strings

String
an ordered sequence of characters
Concatenation
joining two strings end to end
Substring
a contiguous sequence of characters within a string
Tip: When the exam shows string operations, it defines them in the question (e.g., "the procedure SUBSTRING(str, start, end) returns…"). Read that definition carefully — in particular, whether the end index is included — and apply it literally rather than assuming a language you know.

3.5Boolean Expressions

Boolean
a value that is either true or false
Relational operator
an operator that compares two values, such as = or <
Logical operator
NOT, AND, or OR — combines or negates Boolean values
Equivalent expressions
expressions that evaluate to the same value for every possible input
Tip: For "which expression is equivalent" questions, don't reason abstractly — plug in all four combinations of true/false (or a few boundary numbers) and compare outputs. It takes 30 seconds and is essentially error-proof.

3.6Conditionals

Selection
choosing which code to execute based on a Boolean condition
Conditional statement
an IF or IF/ELSE statement
Tip: Count the IFs. Independent IFs can each fire; an IF/ELSE chain fires exactly one branch. When a question asks "how many lines are displayed," this distinction is usually the whole question.

3.7Nested Conditionals

Nested conditional
a conditional statement placed inside the block of another conditional
Tip: Trace nested conditionals from the outside in. Decide the outer condition, cross out the branch that doesn't run, and only then look at what's inside the surviving branch. Never evaluate an inner condition before you've confirmed its outer branch runs.

3.8Iteration

Iteration
repeating a block of code
Loop body
the statements inside a loop that are repeated
REPEAT UNTIL
a loop that runs while its condition is false and stops once it becomes true
Infinite loop
a loop whose exit condition is never met
Tip: REPEAT UNTIL runs while the condition is false. Students constantly flip this. Read it as "keep going until this becomes true." And always check the initial condition — a loop that's already satisfied runs zero times.

3.9Developing Algorithms

Algorithm
a finite set of precise instructions that accomplishes a task
Sequencing
statements executed in order
Selection
choosing a path with a conditional
Iteration
repeating with a loop
Accumulator
a variable that builds up a result, such as a running total, across iterations
Tip: When asked "what does this algorithm do," don't trace with random values — trace with a tiny list of 3 items and watch what the tracked variable equals at the end. The initialization line usually tells you the pattern before you've read anything else.

3.10Lists

Traversal
visiting each element of a list, usually with FOR EACH
APPEND
adds a value to the end of a list
INSERT
places a value at a given index, shifting later elements right
REMOVE
deletes the element at a given index, shifting later elements left
Linear search
checking elements one by one until the target is found or the list ends
Tip: Rewrite the list after every INSERT/REMOVE/APPEND — literally write it out with brackets. Tracking index shifts in your head is where these go wrong. And in a FOR EACH loop, changing the loop variable does not change the list.

3.11Binary Search

Binary search
a search on a sorted list that repeatedly halves the range being examined
Sorted list
elements arranged in order, required for binary search
Tip: If a question about binary search doesn't say the list is sorted, that's the answer: binary search can't be used. If it asks for the maximum number of checks, find the smallest power of 2 that is greater than the list size and use that exponent: 8 items → 4, 15 → 4, 16 → 5, 64 → 7, 100 → 7, 1000 → 10.

3.12Calling Procedures

Procedure
a named block of code that can be called; also called a function or method
Parameter
a variable in a procedure's definition that receives a value when called
Argument
the actual value passed to a procedure when it is called
Return value
the value a procedure sends back to the code that called it
Modularity
dividing a program into separate procedures that each handle one task
Tip: Track "where am I" during a trace. When you hit a procedure call, write down the line you'll return to, go execute the procedure with the arguments substituted for the parameters, and come back. RETURN means you stop reading the procedure instantly — even if there are lines below it.

3.13Developing Procedures

Procedural abstraction
using a procedure without needing to know how its internal code works
Generalization
using parameters so a procedure works for many inputs, not one fixed case
Tip: When a question asks why a programmer should turn repeated code into a procedure, the right answer is about reducing duplication and making changes easier. Answers about making the program run faster or use less memory are distractors — procedures don't do that.

3.14Libraries

Software library
a collection of pre-written procedures that other programs can use
API
the specification of how to use a library: its procedures, parameters, and return values
Documentation
written explanation of how a library's procedures behave
Tip: Questions here are usually scenario-based: a developer wants to add a map to an app. The correct reasoning is "use a library to avoid rewriting tested code," and the correct next step is "read its documentation/API." Any option suggesting you must understand the library's internal implementation is wrong.

3.15Random Values

RANDOM(a, b)
returns a random integer from a to b, inclusive, each equally likely
Tip: Count outcomes as b − a + 1, then count how many satisfy the condition. Students forget that both endpoints are included and get 1/9 instead of 1/10. If a question describes wanting a value "from 1 to 100," the call is RANDOM(1, 100), not RANDOM(0, 100).

3.16Simulations

Simulation
a program that models a real-world or hypothetical process as an abstraction
Simplifying assumption
a detail intentionally left out or held constant to make a model tractable
Tip: Two answer patterns dominate. "Why use a simulation?" → safety, cost, time, or impossibility of the real thing. "What's a limitation?" → simplifying assumptions mean results may not reflect reality. If an option says a simulation gives "exact" or "guaranteed" real-world results, it's wrong.

3.17Algorithmic Efficiency

Efficiency
how an algorithm's required steps or memory grow with input size
Reasonable time
polynomial growth in steps (n, n², n³ …) as input grows
Unreasonable time
exponential or factorial growth in steps as input grows
Heuristic
a technique that finds a good-enough solution quickly when an optimal one is impractical
Tip: If a question gives a table of input size vs. steps, check the growth: steps doubling when n increases by 1 = exponential = unreasonable. Steps multiplying by 4 when n doubles = n² = reasonable. When the stem says "no efficient algorithm exists" or "the solution doesn't have to be perfect," the answer involves a heuristic.

3.18Undecidable Problems

Decidable problem
a problem for which an algorithm exists that correctly answers every input
Undecidable problem
a problem for which no algorithm can correctly answer every input
Halting problem
the undecidable problem of determining whether an arbitrary program will stop or run forever
Tip: Three categories, don't mix them: (1) reasonable time — has a fast algorithm; (2) unreasonable time — has an algorithm, but too slow, so use a heuristic; (3) undecidable — no algorithm can exist for all cases. If the stem says "no algorithm can ever" or mentions determining whether an arbitrary program halts, it's undecidable.