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.
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 — The gap between demographic groups or regions that have access to modern information/communications technology and those that don't.
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 public copyright license that enables the free distribution of an otherwise copyrighted work, allowing creators to specify how others can use their work.
Data Abstraction — Hiding the complex details of how data is stored. Using a list/array is a form of data abstraction.