AP Computer Science Principles — Cheatsheet
Formulas, exam-day tips, and key terms on one page.
Formulas & relationships
The input–process–output model
INPUT → PROCESSING → OUTPUT
Every program can be described this way. Identifying the inputs a program accepts and the outputs it produces is the fastest way to describe its function.
Range of n bits
patterns = 2ⁿ · largest unsigned value = 2ⁿ − 1
n bits produce 2ⁿ distinct patterns, representing the integers 0 through 2ⁿ − 1. Each added bit doubles the number of representable values.
Compression ratio
compression ratio = original size / compressed size
A ratio of 4:1 means the compressed data is one-quarter the original size. Equivalently, space saved = (original − compressed) / original.
The MOD operator
a MOD b = the remainder when a is divided by b
Example: 23 MOD 10 = 3. A number n is even exactly when n MOD 2 = 0, and n MOD b = 0 means b divides n evenly.
Defining and calling a procedure
PROCEDURE square(n) { RETURN(n * n) } → result ← square(6) // result = 36
The parameter n receives the argument 6; RETURN sends back 36, which the call stores in result.
AP pseudocode list operations
APPEND(L, v) · INSERT(L, i, v) · REMOVE(L, i) · LENGTH(L) · L[i] (1-indexed)
INSERT and REMOVE shift the positions of later elements. LENGTH gives the current element count. The first element is always L[1].
RANDOM in AP pseudocode
RANDOM(a, b) → a random integer from a to b, inclusive
Every integer in the range is equally likely. RANDOM(1, 6) yields 1, 2, 3, 4, 5, or 6, each with probability 1/6.
Path of a web request
name (example.com) → DNS lookup → IP address → packets routed hop-by-hop → reassembled at destination
DNS turns a name into an IP address; the message is split into packets that are routed independently and reassembled at the other end.
Fault tolerance through redundancy
more redundant paths/copies → fewer single points of failure → higher fault tolerance
Redundancy means having backups (extra connections, extra copies) so that when one part fails, the system continues using another.
Speedup
speedup = sequential time / parallel time
A speedup of 4 means the parallel solution runs in one-quarter the time. Total parallel time = time of the sequential-only portion + (parallel portion ÷ number of processors), roughly.
Protocol layers, at a glance
IP = addressing/routing · TCP = reliable ordered delivery · HTTP = web requests
Lower layers handle getting bits to the right place; higher layers build services (like the Web) on top of that foundation.
Scales of impact
computing effect → individual impact and/or societal impact
The same innovation can help some people while harming others, and effects can be personal (one user) or broad (a whole community or nation).
How bias enters a system
biased or unrepresentative data + designer assumptions → biased algorithm → unfair outcomes at scale
The appearance of objectivity can hide the bias, which is why systems must be explicitly audited for unequal outcomes.
Multifactor authentication
MFA = two or more of: something you know + something you have + something you are
Combining independent factors means a stolen password alone is not enough to break in.
Legal vs. ethical
legal = what the law allows · ethical = what is right
An action can be legal but still unethical. Sound computing decisions consider both, especially where laws lag behind technology.
On the exam
- On the exam, tie collaboration to **quality**: diverse teams catch more problems and better serve varied users. Beware answer choices that overclaim — collaboration does not *guarantee* correctness or eliminate the need for testing.
- The exam loves the distinction: **syntax** = won’t run, **runtime** = crashes mid-execution, **logic** = runs but wrong. If a program produces an incorrect result without crashing, it is always a logic error.
- For the Create Performance Task you must write comments identifying key components of your program. Comments and meaningful names are graded parts of the artifact — treat documentation as part of the program, not an afterthought.
- Watch for **overflow**: with a fixed number of bits, the representable range is 0 to 2ⁿ − 1. A value past the top cannot be stored, so the exam expects you to say it overflows — not that it rounds or is stored fine.
- Remember the trade-off in one line: **lossless = exact but larger; lossy = smaller but permanent loss.** For a compression ratio, divide original by compressed — a bigger ratio means a smaller file.
- A correlation in data never by itself proves causation. On the exam, the safe reading of "X and Y rise together" is that they are *associated* — a possible hidden variable or reversed direction must be ruled out before claiming cause.
- When a scenario describes collecting data, scan for two things: is the **sample representative**, and was there **consent/privacy** protection? Those are the two questions the exam repeatedly rewards you for asking.
- `MOD` returns the *remainder*, not the quotient. Keep the classic uses ready: `n MOD 2 = 0` tests even, and `n MOD b = 0` tests whether b divides n evenly.
- The exam frames procedures around **abstraction** and **reuse** (managing complexity), not speed. Know the vocabulary precisely: a *parameter* is in the definition, an *argument* is the value you pass in the call.
- On list-tracing questions, redraw the list after **every** INSERT or REMOVE, because those operations shift the positions of all later elements. Track indices carefully — the exam builds traps out of these shifts.
- `RANDOM(a, b)` is **inclusive** of both endpoints. To model n equally likely outcomes numbered 1 to n, use `RANDOM(1, n)`. Off-by-one endpoints are a favorite exam distractor.
- Keep the roles distinct: **IP addresses** identify devices, **DNS** turns names into IP addresses, and **routing** picks each packet’s path. The exam mixes these up in answer choices on purpose.
- Link the concepts in a chain: **redundancy → multiple paths → no single point of failure → fault tolerance**. If an exam scenario has only one path or one copy, its weakness is the single point of failure.
- The exam’s key insight about parallelism: only the **parallelizable portion** speeds up, so the sequential part limits the total speedup. More processors give diminishing returns — never assume time falls in direct proportion to processor count.
- Connect **open standards** to **scalability** and **interoperability**: because the rules are public and shared, the Internet can keep growing and any device can interconnect. This cause-and-effect is a recurring exam theme.
- When a scenario assumes "everyone has access," look for a **digital divide** harm. Effective answers name a cause (cost, rural infrastructure) and a societal impact (widened opportunity gap), often with a mitigation.
- Two exam essentials on bias: (1) bias often comes from the **data** a system was trained on, and (2) it must be **tested and audited** for — it does not disappear because a computer made the decision.
- Match each defense to its job: **encryption** protects data confidentiality in transit and storage; **authentication/MFA** verifies identity. Phishing and malware are threats; strong unique passwords and MFA are the everyday defenses.
- Beware of **data aggregation**: combining separate, innocuous pieces of personal data can reveal private facts and re-identify people. And remember that "legal" never automatically means "ethical" — the exam rewards recognizing both dimensions.
How to get a 5
- For the Create Task, your function MUST include a parameter, a loop, an if-statement, and mathematical/logical operations to earn full points for algorithm complexity.
- Understand the difference between the Internet (the hardware network) and the Web (the software/information layer on top of it).
- On multiple-choice questions regarding algorithms, always check if a problem can be solved in 'reasonable' time. If an algorithm runs in 2^n time, it is an unreasonable (intractable) algorithm.
- Remember that 'redundancy' in networks is a good thing! It allows for fault tolerance and reliability when components fail.
- Know the exam shape: 70 multiple-choice questions in 120 minutes — about 100 seconds each — counting for the large majority of your score, with the Create performance task supplying the rest. Some questions near the end refer to the program you submitted, so reread your own code and written responses before exam day.
- Trace pseudocode with a variable table, one row per pass through the loop, and lean on the reference sheet you are given rather than translating everything into a language you know. Write down the loop condition and check it before and after each pass — the two errors the exam plants most often are a loop variable that is never updated and a comparison that should be ≥ instead of >. Skim the sheet beforehand so MOD, the ← assignment arrow, RANDOM, LENGTH, and the list operations are familiar, and note that a few multiple-choice items ask for two answers, where both must be correct for credit.
- Remember that AP pseudocode lists start at index 1 and that INSERT and REMOVE shift every later element. Rewrite the whole list after each operation instead of trying to keep the shifts in your head.
- For binary questions, memorize the place values 1, 2, 4, 8, 16, 32, 64, 128 and work from the largest that fits. Also keep straight that n bits give 2ⁿ values but a maximum of 2ⁿ − 1, since that single distinction decides several questions per exam.
- On written responses, always name the specific list, variable, or procedure from the program, answer each part in a separately labeled paragraph, and match the prompt’s verb. A generic sentence such as "the list makes the code simpler" scores nothing; "studyLog holds one entry per subject, so one loop handles any number of entries" earns the point. "Identify" needs one clear sentence, while "explain" or "describe" needs the mechanism — the how or the why — and that missing mechanism is the most common lost point.
- When asked about a harmful effect or about bias, identify who is harmed and trace the cause to a specific design or data choice. Bias on this exam is systematic and inherited from data or assumptions — never describe it as a random mistake or as deliberate malice.
Key terms
Binary to Decimal — Base 2 system. Place values are powers of 2 (128, 64, 32, 16, 8, 4, 2, 1). Example: 1011 = 8 + 0 + 2 + 1 = 11.
Lossy vs. Lossless Compression — Lossy: Reduces file size by permanently discarding some data (e.g., JPEG, MP3). Lossless: Reduces size without losing data; can be perfectly reconstructed (e.g., ZIP).
Algorithmic Efficiency — Measured by how execution time or memory usage grows as input size grows. Polynomial time (e.g., n, n^2) is "reasonable." Exponential time (e.g., 2^n, n!) is "unreasonable."
Heuristic — An approach to a problem that produces a solution that is "good enough" when an exact solution would take an unreasonable amount of time (e.g., Traveling Salesperson).
The Internet vs. WWW — The Internet is the physical network of connected computers and cables. The World Wide Web is a system of linked pages/files accessed *via* the Internet using HTTP.
Fault Tolerance / Redundancy — The Internet is designed with redundant paths. If a router fails, packets can be dynamically rerouted along a different path.
Digital divide — Unequal access to computing between groups, by income, geography, age, education or disability. It concerns access, quality of access, and the skills to use it.
Symmetric vs. Public Key Encryption — Symmetric: Same key used to encrypt and decrypt. Public Key (Asymmetric): Uses a public key to encrypt (anyone can use) and a private key to decrypt (only owner has).
Phishing — A cyber attack where an attacker sends a fraudulent message designed to trick a person into revealing sensitive info or deploying malicious software.
Citizen Science — Scientific research conducted, in whole or in part, by distributed individuals (the public), often using the internet to crowdsource data collection.
Creative Commons — A set of licenses letting creators grant specific reuse rights while keeping copyright. It replaces "all rights reserved" with terms chosen by the creator.
Data abstraction — Using a name to represent a collection of data — a list rather than many separate variables. It lets a program work with any number of items using the same code.
How do you convert a binary number to decimal? — Add the place values of every 1 bit, where places double from right to left (1, 2, 4, 8, 16, 32, …). For example 100101 is 32 + 4 + 1 = 37.
How many values can n bits represent, and what is the largest unsigned value? — 2ⁿ different values, ranging from 0 to 2ⁿ − 1. Each additional bit doubles the number of values, so growth is exponential, not linear.
What is overflow, and what is round-off error? — Overflow occurs when a value is too large for the number of bits allocated to it. Round-off error occurs when a value such as 0.1 cannot be represented exactly in a fixed number of bits, so stored decimals are approximations.
What is the difference between lossy and lossless compression? — Lossless removes redundancy only, so the original can be restored exactly (ZIP, PNG, text). Lossy discards detail permanently to get smaller files and cannot be restored (JPEG, MP3). Choose lossless when exactness matters.
How is analog data converted into digital data? — By sampling — measuring the signal at regular intervals and storing each measurement as bits. A higher sampling rate and more bits per sample give a closer approximation and a larger file, but the result is always an approximation.
What is metadata? Give an example. — Data about data. A photo’s file size, timestamp, camera model, and GPS coordinates are metadata. Metadata can be as revealing as the content itself, which is why it matters for privacy.
What is the difference between information and data, and what can data be used for? — Data are raw values; information is the meaning extracted from them by processing, filtering, and visualization. Large data sets are used to identify trends and correlations and to make predictions, though correlation is not causation.
What is personally identifiable information (PII)? — Any information that can identify an individual on its own or combined with other data — name, address, birth date, biometrics, search history, GPS traces. Removing a name does not anonymize data if the remaining fields still single someone out.
What are the three building blocks of every algorithm? — Sequencing (steps in order), selection (a condition chooses which steps run), and iteration (steps repeat). Any algorithm you write for the exam should be describable in these terms.
In AP pseudocode, what does REPEAT UNTIL (condition) do, and what is the most common bug? — It tests the condition before each pass and repeats while the condition is false, stopping once it becomes true. The most common bug is forgetting to update the loop variable inside the body, which produces an infinite loop.
At what index do AP pseudocode lists begin, and what do INSERT and REMOVE do to the other elements? — Index 1. INSERT(list, i, value) places the value at index i and shifts every later element right, increasing length by 1; REMOVE(list, i) deletes the value at index i and shifts later elements left, decreasing length by 1.
What is the difference between a linear search and a binary search? — Linear search checks elements one at a time and works on any list. Binary search requires a sorted list and halves the remaining range each step, examining about log₂(n) elements — roughly 20 checks for a million items.