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