1. Home
  2. Big-O cheat sheet

Big-O Cheat Sheet

The time and space complexity of 96 data structures and algorithms on one page. Click any name to watch it run as an interactive 3D model.

What Big-O notation means

Big-O describes how the work an algorithm does grows as its input grows. It ignores constant factors and small inputs and keeps only the part that dominates for large n. An O(n log n) sort will always beat an O(n²) sort once the list is long enough, whatever computer runs them.

Big-ONameIn wordsSteps for n = 1,000,000Example
O(1)ConstantSame work no matter how big the input is.1Array access by index, stack push/pop
O(log n)LogarithmicHalves the problem each step.≈ 20Binary search, balanced-tree lookup
O(n)LinearLooks at every item once.1,000,000Linear search, one pass over an array
O(n log n)LinearithmicThe best possible for comparison sorting.≈ 20,000,000Merge sort, heap sort
O(n²)QuadraticCompares every pair of items.10¹²Bubble sort, insertion sort (worst case)
O(2ⁿ)ExponentialDoubles with every extra item.more than atoms in the universeTrying every subset by brute force

Jump to:Data Structures · Design & Analysis of Algorithms · AI & Machine Learning · Operating Systems · Database Management Systems · Computer Networks · Theory of Computation · Computer Organization & Architecture

Data Structures

TopicCase / operationTimeNotes
Arrays & StringsAccess a[i]O(1)Address is calculated directly.
Search (unsorted)O(n)Check elements one by one.
Insert / delete at the endO(1)Nothing has to move.
Insert / delete at index iO(n)Everything after i shifts.
Reverse / palindrome (two pointers)O(n)n/2 steps, no extra array.
Extra spaceO(n)
Stackpush(x)O(1)Only the top position changes.
pop()O(1)Only the top position changes.
peek()O(1)Reads one element.
search(x)O(n)You may have to pop through every element.
Extra spaceO(n)
Queueenqueue(x)O(1)Write at the rear index.
dequeue() — circular arrayO(1)Just move the front index.
dequeue() — shifting arrayO(n)Every remaining element moves one place.
peek()O(1)Read the front element.
Extra spaceO(n)
Linked ListInsert at headO(1)Only two pointers change.
Insert at tail (no tail pointer)O(n)Must walk to the last node.
Insert / delete after a known nodeO(1)Just re-wire pointers.
Search / access by indexO(n)No random access — walk from the head.
ReverseO(n)One pass, flipping each arrow.
Extra spaceO(n)
Binary Search Tree (BST)Search / insert / delete — balanced treeO(log n)Each step goes one level down; a balanced tree has about log₂ n levels.
Search / insert / delete — worst caseO(n)Inserting sorted data makes the tree a straight line.
Traversal (any order)O(n)Every node is visited exactly once.
Extra spaceO(n)
Binary Heap & Priority Queuepeek (get min)O(1)The minimum is always at index 0.
insertO(log n)Bubble up at most one level per swap.
extractMinO(log n)Sift down at most one level per swap.
build heap from n itemsO(n)Bottom-up heapify (a surprising but proven result).
heap sortO(n log n)n extractions of O(log n) each.
Extra spaceO(n)
Hash TableInsert / search / delete — averageO(1)Hash straight to the right bucket.
Insert / search / delete — worst caseO(n)All keys collide into one bucket.
Resize (rehash) when too fullO(n)Rare, so still O(1) amortised.
Extra spaceO(n)
Trie (Prefix Tree)Insert a word of length LO(L)One step per letter — independent of how many words are stored.
Search a word of length LO(L)Same walk as insert.
Prefix search (autocomplete)O(L + k)Walk the prefix, then collect k results.
Extra spaceO(total letters × alphabet)
AVL TreeSearchO(log n)Height is always about 1.44 log₂ n.
Insert (with rebalancing)O(log n)At most one single or double rotation.
Delete (with rebalancing)O(log n)May rotate at several levels.
One rotationO(1)Only three pointers change.
Extra spaceO(n)
Red-Black TreeSearchO(log n)Height is at most 2 · log₂(n + 1).
InsertO(log n)Recolourings go up the tree; at most 2 rotations.
DeleteO(log n)At most 3 rotations.
Extra spaceO(n)
Segment TreeBuildO(n)Each of the ~2n nodes is computed once.
Range queryO(log n)At most ~4 nodes per level are visited.
Point updateO(log n)One node per level, leaf to root.
Naive array (for comparison)O(n) query / O(1) updatePrefix sums are the opposite trade-off.
Extra spaceO(n)
Fenwick Tree (Binary Indexed Tree)Prefix sumO(log n)One step per 1 bit in i.
Point updateO(log n)Climb to every cell whose range contains i.
Range sumO(log n)Two prefix sums.
BuildO(n log n)O(n) with a clever single pass.
Extra spaceO(n)
Disjoint Set (Union–Find)Find / Union (rank + path compression)O(α(n)) ≈ O(1)α is the inverse Ackermann function, ≤ 4 for any practical n.
Find / Union (naive)O(n)Trees can degenerate into chains.
Make setO(1)parent[x] = x
Extra spaceO(n)
Graph RepresentationMemory — matrixO(V²)One cell per pair of vertices.
Memory — listO(V + E)One entry per edge end.
Is there an edge u–v? — matrix / listO(1) / O(deg u)Direct cell lookup vs scanning a list.
All neighbours of u — matrix / listO(V) / O(deg u)Scan a whole row vs walk a short list.
Extra spaceO(V²) or O(V + E)
Monotonic Stack (Next Greater Element)Whole arrayO(n)Each index is pushed once and popped at most once.
Brute force (compare every pair)O(n²)Shown for comparison.
Extra spaceO(n) for the stack
Bloom FilterAdd / checkO(k)k hash computations, independent of how many items are stored.
False positive rate≈ (1 − e^(−kn/m))^kn items, m bits, k hash functions.
Extra spacem bits (about 10 bits per item for a 1% error rate)

Design & Analysis of Algorithms

TopicCase / operationTimeNotes
Binary SearchBest caseO(1)The target is exactly in the middle.
Average / worst caseO(log n)The range halves every step.
Linear search (for comparison)O(n)Checks elements one by one.
Extra spaceO(1)
Bubble SortBest case (already sorted)O(n)One pass with no swaps, then stop early.
Average caseO(n²)About n²/4 swaps.
Worst case (reversed)O(n²)n(n−1)/2 comparisons and swaps.
Extra spaceO(1)
Selection SortBest case (already sorted)O(n²)It still scans the whole unsorted part every pass.
Average caseO(n²)Exactly n(n−1)/2 comparisons.
Worst caseO(n²)Same comparisons as the best case.
SwapsO(n)At most one per pass, n − 1 in total.
Extra spaceO(1)
Insertion SortBest case (already sorted)O(n)One comparison per element, no shifts.
Average caseO(n²)About n²/4 shifts.
Worst case (reversed)O(n²)Every key shifts past all sorted elements.
Extra spaceO(1)
Merge SortBest caseO(n log n)It always splits and merges fully.
Average caseO(n log n)log₂ n levels × n work per level.
Worst caseO(n log n)Guaranteed — no bad inputs.
Extra spaceO(n)
Quick SortBest caseO(n log n)The pivot splits the array into two equal halves.
Average caseO(n log n)Random data gives reasonably balanced splits.
Worst caseO(n²)The pivot is always the smallest or largest (e.g. sorted input with a last-element pivot).
Extra spaceO(log n)
Heap SortBest caseO(n log n)Every extraction still sifts down.
Average caseO(n log n)
Worst caseO(n log n)Guaranteed — unlike quick sort.
Build heapO(n)Bottom-up heapify.
Extra spaceO(1)
Counting Sort & Radix SortCounting sort (values 0 … k)O(n + k)One pass over the input, one over the counts.
Radix sort (d digits, base b)O(d · (n + b))d stable counting sorts, one per digit.
Any comparison sortΩ(n log n)The limit these algorithms avoid.
Extra spaceO(n + k)
Graph Traversal — BFS & DFSBFS / DFS with an adjacency listO(V + E)Every vertex is visited once and every edge checked at most twice.
BFS / DFS with an adjacency matrixO(V²)Finding neighbours means scanning a whole row.
Extra spaceO(V)
Topological SortKahn's algorithmO(V + E)Every node enters the queue once; every edge is removed once.
DFS methodO(V + E)Every node is visited once; every edge is followed once.
Detecting a cycleO(V + E)Comes for free with either method.
Extra spaceO(V)
Dijkstra's Shortest PathSimple array versionO(V²)Scan all vertices to find the minimum each round.
Binary heap (priority queue)O((V + E) log V)The usual choice for sparse graphs.
Fibonacci heapO(E + V log V)Best in theory, rarely used in practice.
Extra spaceO(V)
Bellman–Ford AlgorithmUp to V − 1 passes over all edgesO(V × E)Each pass relaxes every edge once.
Negative-cycle checkO(E)One extra pass.
Best case (early stop)O(E)When a pass changes nothing, every distance is final.
Dijkstra, for comparisonO((V + E) log V)Faster, but needs non-negative weights.
Extra spaceO(V)
Minimum Spanning Tree — Prim & KruskalKruskal (sort + union-find)O(E log E)Sorting the edges dominates.
Prim (binary heap)O(E log V)
Prim (adjacency matrix, no heap)O(V²)Good for dense graphs.
Extra spaceO(V + E)
Floyd–Warshall (All-Pairs Shortest Paths)TimeO(V³)Three nested loops over the vertices.
Dijkstra from every vertex (for comparison)O(V · E log V)Faster on sparse graphs, but no negative edges.
Extra spaceO(V²)
0/1 Knapsack (Dynamic Programming)Fill the tableO(n × W)One constant-time decision per cell.
Trace back the itemsO(n)
Brute force (try every subset)O(2ⁿ)Hopeless beyond ~30 items.
Extra spaceO(n × W)
Longest Common Subsequence (LCS)Fill the tableO(m × n)One cell per pair of prefixes.
Trace backO(m + n)
Brute force (all subsequences)O(2ᵐ × n)
Extra spaceO(m × n)
Matrix Chain MultiplicationFilling the tableO(n³)O(n²) cells, each trying up to n splits.
Reading the bracketsO(n)Follow s[i][j] recursively.
Trying every bracketingexponential (Catalan numbers)Why brute force is hopeless.
Extra spaceO(n²)
Huffman CodingBuild the tree (k distinct characters)O(k log k)k − 1 merges, each with heap operations.
Count frequencies (text of length n)O(n)
Encode / decodeO(n · code length)
Extra spaceO(k)
KMP String MatchingBuilding the LPS tableO(m)m = length of the pattern.
Searching the textO(n)At most 2n comparisons; i never moves back.
Naive search, worst caseO(n · m)Re-reads text after every mismatch.
Extra spaceO(m) for the LPS table
N-Queens (Backtracking)Backtracking (first solution)O(N!) worst casePruning makes it far faster in practice.
Brute force (any N squares)O(C(N², N))For N = 8 that's over 4 billion placements.
safe() check with setsO(1)Track used columns and diagonals.
Extra spaceO(N)
Edit Distance (Levenshtein)Fill the tableO(m × n)Each of the (m+1)(n+1) cells looks at three neighbours.
MemoryO(m × n)Can be reduced to O(min(m, n)) if only the distance is needed.
Extra spaceO(m × n) table
Activity Selection (Greedy)Sorting by finish timeO(n log n)Skipped if the input is already sorted.
Greedy scanO(n)One pass, comparing start time with the last finish.
Extra spaceO(1) extra (plus the output)

AI & Machine Learning

TopicCase / operationTimeNotes
Gradient DescentOne step (n parameters)O(n)Compute the gradient and update every parameter.
One step on a dataset of m examples (batch)O(m · n)The gradient sums over every training example.
Stochastic / mini-batch stepO(b · n)Uses only b examples per step — much cheaper.
Extra spaceO(n)
Linear RegressionPrediction for one inputO(d)d = number of features.
One gradient descent stepO(n · d)Uses every training example.
Normal equation (exact)O(n · d² + d³)Matrix inversion — slow for many features.
Extra spaceO(d)
Logistic RegressionPredictionO(d)One weighted sum and a sigmoid.
One training stepO(n · d)
Extra spaceO(d)
Support Vector Machine (SVM)Training (kernel SVM, n points)O(n²) to O(n³)Solving a quadratic optimisation problem.
Training (linear SVM, modern solvers)≈ O(n · d)Coordinate descent and similar methods.
PredictionO(s · d)s support vectors, d features (O(d) for a linear SVM).
Extra spaceO(s · d) for the model
Neural Network (Forward Pass)Forward pass (one input)O(total weights)Every weight is used once — one multiply and one add.
Dense layer with n inputs and m neuronsO(n · m)This is a matrix–vector multiplication.
Extra spaceO(total weights)
Convolutional Neural Network (CNN)One convolution (H×W image, k×k kernel)O(H · W · k²)
Parameters of a conv layerk × k × channels_in × channels_outTiny compared with a fully connected layer.
Max-pooling 2×2O(H · W)
Extra spaceO(H · W) per feature map
Transformers & Self-AttentionAttention over n tokens (d dimensions)O(n² · d)Every token is compared with every other token.
Memory for the attention tableO(n²)Why very long contexts are expensive.
Sequential steps per layerO(1)All tokens are processed at once (an RNN needs n steps).
Extra spaceO(n² + n · d)
K-Nearest Neighbours (KNN)TrainingO(1)Just store the data ("lazy learning").
Prediction (brute force)O(n · d)Distance to every training point.
Prediction with a k-d tree (low d)about O(log n)
Extra spaceO(n · d)
Naive Bayes ClassifierTraining (n messages, total length L)O(L)Just count words, one pass.
Classifying a message of m wordsO(m · k)k classes, one lookup per word and class.
Model sizeO(V · k)One probability per word per class.
Extra spaceO(V · k)
Decision TreePredictionO(depth)Answer one question per level.
Training (n points, d features)O(d · n log n · depth)Sort values to try every threshold.
Extra spaceO(number of nodes)
K-Means ClusteringOne iterationO(n · k · d)n points × k centroids × d features distances.
Whole algorithmO(i · n · k · d)i iterations — usually small (tens).
Extra spaceO(n · d + k · d)
Principal Component Analysis (PCA)Covariance matrix (n points, d features)O(n · d²)
Eigen-decompositionO(d³)
Projecting the dataO(n · d · k)
Extra spaceO(d²)
A* SearchWorst case (grid with V cells)O(V log V)With a priority queue for the open set.
With a perfect heuristicO(path length)It walks straight to the goal.
Extra spaceO(V)
Minimax & Alpha–Beta PruningMinimax (branching b, depth d)O(bᵈ)Visits every leaf.
Alpha-beta, best move orderingO(b^(d/2))Can search twice as deep in the same time.
Alpha-beta, worst orderingO(bᵈ)
Extra spaceO(b · d)
Q-Learning (Reinforcement Learning)One Q-learning updateO(|A|)Look up max over the actions of the next state.
Q-table sizeO(|S| · |A|)One value per state–action pair (here 25 × 4).
Episodes to convergegrows with the state spaceEvery pair must be tried many times.
Extra spaceO(|S| · |A|)
PerceptronOne predictionO(d)A dot product over d features.
One epochO(n · d)n points, d features each.
Mistakes before convergence≤ (R/γ)²Novikoff's bound for separable data with margin γ and radius R.
Extra spaceO(d) weights
Genetic AlgorithmOne generationO(P · L)P individuals of length L: evaluate, select, cross over, mutate.
Generations neededproblem dependentNo guarantee of finding the optimum, but usually far fewer evaluations than brute force.
Extra spaceO(P · L)

Operating Systems

TopicCase / operationTimeNotes
CPU Scheduling (FCFS, SJF, SRTF, Round Robin, Priority)FCFS selectionO(1)Take the front of a queue.
SJF / SRTF / Priority selectionO(log n)Using a min-heap of ready processes.
Round Robin selectionO(1)Circular queue.
Extra spaceO(n)
Process Synchronization (Semaphores & Mutex)wait() / signal() on a semaphoreO(1)Plus the cost of sleeping/waking a process.
Busy-waiting spinlockWastes CPU while waitingOK only for very short critical sections.
Extra spaceO(1) per semaphore
Deadlock & Banker's AlgorithmSafety algorithm (n processes, m resource types)O(m · n²)Up to n passes over n processes.
Resource request checkO(m · n²)Runs the safety algorithm.
Extra spaceO(m · n)
Memory Allocation (First, Next, Best & Worst Fit)First fitO(h)Stops at the first hole that fits (h = number of holes).
Next fitO(h)Like first fit, but starts where the last search ended.
Best fit / Worst fitO(h)Must look at every hole (O(log h) with a sorted tree of holes).
Extra spaceO(h) to keep the list of holes
Paging & Address Translation (TLB)TLB hitt + mTLB lookup, then the actual memory access.
TLB miss (page table in memory)t + 2mExtra memory access to read the page table.
Effective access timeh(t + m) + (1 − h)(t + 2m)h = TLB hit ratio.
Page faultmillisecondsThe page must come from disk — about 100,000× slower.
Paging & Page Replacement (FIFO, LRU, Optimal)FIFO per referenceO(1)A queue of loaded pages.
LRU per referenceO(1)Hash map + doubly linked list.
Optimal per referenceO(n)Must look into the future — not implementable in practice.
Extra spaceO(frames)
Disk Scheduling (FCFS, SSTF, SCAN, C-SCAN, LOOK, C-LOOK)FCFSO(n)Serve the requests in arrival order.
SSTFO(n²)n times, search the pending requests for the nearest one.
SCAN, C-SCAN, LOOK, C-LOOKO(n log n)Sort the requests once, then sweep across them.
Head movement of one SCAN sweep≤ 2 × disk sizeOut to one edge and back across the disk.
Extra spaceO(n)
Dining Philosophers ProblemNaive solutioncan deadlockCircular wait is possible when everyone holds one fork.
Resource orderingdeadlock-freeBreaks circular wait; starvation is still possible with an unfair scheduler.
Waiter (n − 1 seats)deadlock-freeAt least one philosopher can always get both forks.
Extra spaceOne lock or semaphore per fork
File Allocation MethodsRead block k (contiguous)O(1)address = start + k
Read block k (linked)O(k)Follow k pointers, one disk read each.
Read block k (indexed)O(1)Index block first, then the data block (2 reads).
Extra spacePointers or an index per file

Database Management Systems

TopicCase / operationTimeNotes
SQL Joins (INNER, LEFT, RIGHT, FULL)Nested loop joinO(n × m)Compare every pair of rows.
Hash joinO(n + m)Build a hash table on one table.
Sort-merge joinO(n log n + m log m)
Extra spaceO(n + m) for hash join
Functional Dependencies, Closure & Candidate KeysClosure X⁺ (n attributes, f dependencies)O(n · f)Each pass adds at least one attribute, at most n passes.
Finding all candidate keysO(2ⁿ · n · f)Worst case tries every subset; the core and superset pruning help a lot.
Checking if X is a superkeyO(n · f)Just compare X⁺ with all attributes.
Normalization (1NF, 2NF, 3NF)Effect on readsMore joinsData is split across tables.
Effect on writesFewer updatesEach fact is stored once.
Transactions & ACIDWrite-ahead logging per updateO(1)Append a log record before changing data.
Recovery after a crashO(log size)Scan the log to redo / undo.
Conflict SerializabilityFinding all conflicting pairs (n operations)O(n²)Compare every pair once.
Cycle check / serial order (t transactions)O(t + e)DFS or a topological sort of the graph.
Testing view serializabilityNP-completeWhy databases use the conflict test instead.
B+ Tree IndexingSearchO(log n)One node (disk block) per level.
Insert / deleteO(log n)Splits only travel up one path.
Range query returning k keysO(log n + k)Walk the leaf chain.
Extra spaceO(n)
Relational Algebra (Select and Project)Selection σO(n)One test per row, or O(log n) with an index.
Projection πO(n)Plus duplicate removal, which needs hashing or sorting.
Duplicate eliminationO(n) hashing, O(n log n) sorting
Extra spaceO(n) for the result
Deadlock Detection (Wait-For Graph)Cycle detection (DFS)O(V + E)V transactions and E waits-for edges.
Deadlock prevention (wait-die)O(1) per lock requestCompare transaction timestamps; no graph needed.
Extra spaceO(V + E) for the graph

Computer Networks

TopicCase / operationTimeNotes
OSI & TCP/IP LayersOSI layers7Reference model for teaching and troubleshooting.
TCP/IP layers4The model the internet actually uses.
CRC (Cyclic Redundancy Check)Computing the CRC bit by bitO(n · r)n data bits, an r-bit remainder.
Table-driven CRC (one byte at a time)O(n / 8) lookupsHow network cards and libraries really do it.
Extra bits sentrThe degree of the generator.
Bursts of errors always caughtlength ≤ rLonger bursts slip through with probability about 2^−r.
Hamming CodeParity bits for m data bitsr with 2^r ≥ m + r + 1About log₂ m extra bits.
Encoding / checkingO(n log n)r groups, each up to n bits (O(n) with XOR tricks).
Errors corrected1 bitAdd one overall parity bit (SECDED) to also detect 2-bit errors.
Sliding Window ProtocolMax frames in flightN (window size)
Retransmissions after one loss — Go-Back-Nup to NThe lost frame and everything after it.
Retransmissions after one loss — Selective Repeat1Only the lost frame.
Extra spaceReceiver buffer of N frames (Selective Repeat)
Subnetting & CIDR (IPv4)Addresses in a /n network2^(32 − n)Every extra host bit doubles the size.
Usable hosts in a /n network2^(32 − n) − 2The network and broadcast addresses are reserved.
Find network or broadcast addressO(1)One bitwise AND (or OR) on 32 bits.
Subnets after borrowing b bits2^bEach one has 2^(32 − n − b) addresses.
Routing Algorithms (Distance Vector)One round (V routers, E links)O(V · E)Every router combines its neighbours' vectors.
Rounds to converge≤ V − 1The longest shortest path in hops.
Extra spaceO(V) per router
TCP 3-Way HandshakeMessages to open a connection3SYN, SYN-ACK, ACK.
Messages to close4FIN, ACK, FIN, ACK.
Delay before data can flow1 round-trip time
TCP Congestion ControlSlow startdoubles per RTTExponential growth until cwnd reaches ssthresh.
Congestion avoidance+1 MSS per RTTAdditive increase.
After a losscwnd / 2Multiplicative decrease (to 1 after a timeout).
Rounds to reach a window of W from 1about log₂ WThanks to slow start.
Token Bucket (Traffic Shaping)Per packetO(1)Check and decrement a counter.
Maximum burstbucket sizeA full bucket lets that many packets go at once.
Long-run average ratetoken rateNever more than the tokens added per tick.
Extra spaceO(1) — one counter and a timestamp
DNS ResolutionCold lookup8 messagesBrowser → resolver, then 3 query/reply pairs to root, TLD and authoritative servers, then the reply.
Cached lookup2 messagesThe resolver answers from its cache until the TTL expires.
Extra spaceOne cache entry per name and record type

Theory of Computation

TopicCase / operationTimeNotes
DFA & NFA (Finite Automata)Run a DFA on a string of length nO(n)One transition per symbol.
Simulate an NFA with k statesO(n · k²)Track the set of possible states.
Convert NFA → DFA (subset construction)up to O(2ᵏ) states
Extra spaceO(1) for a DFA, O(k) for an NFA
DFA MinimizationRemoving unreachable statesO(n · |Σ|)One BFS from the start state.
Partition refinement (Moore)O(n² · |Σ|)At most n rounds, each looks at every transition.
Hopcroft's algorithmO(n · |Σ| · log n)The fastest known method.
Extra spaceO(n)
Regular ExpressionsThompson NFA size (regex length m)O(m) states
Matching a text of length nO(n · m)Set-of-states simulation — no exponential blow-up.
Backtracking engines (worst case)exponentialCatastrophic backtracking on patterns like (a+)+b.
Extra spaceO(m)
Pushdown Automata (PDA)Deterministic PDA run (input length n)O(n)
General CFG parsing (CYK)O(n³)
Extra spaceO(n) stack
Turing MachineBinary increment (n bits)O(n)
Palindrome check (n symbols)O(n²)The head runs back and forth n/2 times.
Extra spaceThe tape (unbounded)
CYK Algorithm (Parsing Context-Free Grammars)CYK parsingO(n³ · |G|)n² cells, up to n splits each, and |G| rules checked per split.
Table sizeO(n²)One set of variables per substring.
Extra spaceO(n²) table cells
NFA to DFA Conversion (Subset Construction)DFA states producedup to 2ⁿEvery subset of the n NFA states could be reachable.
Work per DFA stateO(n · |Σ|)Union the moves of each member for every symbol.
Extra spaceUp to 2ⁿ table rows

Computer Organization & Architecture

TopicCase / operationTimeNotes
Instruction PipeliningNon-pipelined (n instructions, k stages)n · k cycles
Ideal pipelinek + (n − 1) cyclesAfter the pipeline fills, one instruction finishes every cycle.
Ideal speed-up≈ k (as n grows)
Cache Memory MappingDirect mapped lookup1 tag comparison
k-way set associative lookupk comparisons (in parallel)
Fully associative lookupone comparison per line (in parallel)Fast but expensive hardware — used only for small caches like TLBs.
IEEE 754 Floating PointSingle precision (float)1 + 8 + 23 = 32 bitsAbout 7 significant decimal digits.
Double precision (double)1 + 11 + 52 = 64 bitsAbout 15–16 significant decimal digits.
Booth's Multiplication Algorithmn-bit multiplicationn roundsEach round is at most one add/subtract plus one shift.
Long runs of 1s in Qonly 2 add/subtract operations per run
Extra spaceA, Q and Q₋₁ registers (2n + 1 bits)
Restoring & Non-Restoring DivisionRounds (n-bit dividend)nOne quotient bit per round.
Restoring — add/subtract operationsup to 2nA subtract every round, plus an add when restoring.
Non-restoring — add/subtract operationsn (+ 1)One per round, plus at most one final correction.
Extra spaceRegisters A (n + 1 bits), Q (n bits), M (n bits)
Two's ComplementNegate a numberO(n)Invert n bits and add 1, which may ripple a carry through all n bits.
Add or subtractO(n)The same adder works for signed and unsigned numbers.
Extra spacen bits per number
Ripple-Carry AdderAdd two n-bit numbersO(n)Each carry waits for the previous adder, so the delay is n full-adder delays.
Carry-lookahead adderO(log n)Computes all carries in parallel using generate and propagate signals.
Extra spacen full adders (about 5 gates each)

How to use this cheat sheet

  • Best, average and worst case can differ. Quick sort is O(n log n) on average but O(n²) in the worst case.
  • Amortised costs (like a dynamic array that sometimes doubles its size) are averaged over many operations, so a rare slow step doesn't change the overall bound.
  • Space matters too. Merge sort needs O(n) extra memory; heap sort sorts in place with O(1).
  • Not sure why a bound holds? Open the lesson and step through the 3D model — counting the steps yourself is the best proof.