CS Principles
💡

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

How to get a 5

Key terms

Binary to DecimalBase 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 CompressionLossy: 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 EfficiencyMeasured 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."
HeuristicAn 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. WWWThe 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 / RedundancyThe Internet is designed with redundant paths. If a router fails, packets can be dynamically rerouted along a different path.
Digital divideUnequal 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 EncryptionSymmetric: 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).
PhishingA cyber attack where an attacker sends a fraudulent message designed to trick a person into revealing sensitive info or deploying malicious software.
Citizen ScienceScientific research conducted, in whole or in part, by distributed individuals (the public), often using the internet to crowdsource data collection.
Creative CommonsA set of licenses letting creators grant specific reuse rights while keeping copyright. It replaces "all rights reserved" with terms chosen by the creator.
Data abstractionUsing 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.