Algorithms for Data Science · Quiz 2 · Weeks 1–6
Randomness, at scale
Six weeks, one idea: when the data is too big to touch, throw randomness at it and prove the answer is still nearly right. Every topic below is that same move applied to a different object — a distance, a bucket, a matrix, a graph.
Prof. Rajkumar opens Week 1 by writing one sentence on the board: "Randomization as a tool to deal with Scale." Hold onto it. Each unit follows the identical three-beat structure:
- Exact is too expensive. Exact isometry needs $d$ orthonormal vectors in $\mathbb{R}^k$; exact NN costs $O(nd)$; exact SVD costs $O(mn^2)$; exact mincut is combinatorially hard.
- Randomize. A Gaussian matrix, a random hyperplane offset, a random sketch, a random edge sample.
- Concentrate. Show the random thing is right in expectation, then use a tail bound + union bound to show it is right with high probability.
Beat 3 is why Week 1 spends four lectures on Markov, Chebyshev and Hoeffding before touching a single algorithm. Those inequalities are not a warm-up — they are the engine that every later proof runs on.
What is actually examinable
| Unit | Lectures | You must be able to… |
|---|---|---|
| Concentration inequalities | W1 L1–L5 | State each bound with its exact hypotheses; plug numbers in; know which is tightest and why; apply union & subset bounds |
| Johnson–Lindenstrauss | W1 L6–L9, W2 L1–L3 | State the lemma; know $M=R/\sqrt{k}$; reproduce the unbiasedness argument; know $k \ge \tfrac{8}{\epsilon^2}\log\tfrac{2n^2}{\delta}$ and where every constant comes from |
| ANN & LSH | W3 L1–L8 | Write the $(r,c,p_1,p_2)$ conditions in the right direction; compute TPR/FPR after AND and OR; derive $k$, $\rho$, $L$; do the numeric example |
| SVD & Randomized SVD | W4 L1–L5 | Track every matrix shape; state Eckart–Young; run the 6-step randomized SVD with per-step cost; explain oversampling and power iteration |
| Spectral clustering | W5 L1–L3, W6 L1 | Build $W, D, L$; prove $f^\top L f$ identity; know why $\lambda_1=0$ is useless; run the full algorithm |
| Spectral sparsification | W6 L2–L4 | State the $(1\pm\epsilon)$ quadratic-form condition; explain reweighting $w' = w/p$ and why it is unbiased |
Read a unit, then open its practice questions before looking at the answer — recall beats re-reading. Reveal all in the top bar opens every answer at once if you'd rather skim, and the page prints cleanly with all answers expanded. The formula cheat sheet and traps list are the two things to re-read in the last thirty minutes.
Unit 01 · Week 1, Lectures 1–5
Concentration inequalities
Three bounds that say the same thing with increasing force: a random variable rarely strays far from its mean. They differ only in how much you're allowed to assume, and you pay for stronger assumptions with a tighter bound.
Markov's inequality
If $X$ is a non-negative random variable and $a > 0$:
$$P(X \ge a) \;\le\; \frac{\mathbb{E}[X]}{a}$$Non-negativity is not decoration — it is the whole proof. Drop it and the bound is false. Notice what Markov needs: only the mean. That is its strength (you almost always know the mean) and its weakness (it ignores everything about the shape).
Fair die, $X \in \{1,\dots,6\}$, so $\mathbb{E}[X] = 21/6 = 3.5$.
Truth: $P(X \ge 5) = P(X \in \{5,6\}) = 2/6 = 0.33$.
Markov says: $P(X \ge 5) \le 3.5/5 = 0.7$.
Correct, and useless. $0.7$ vs. a true $0.33$ — Markov is loose. That looseness is exactly the motivation for Chebyshev.
Let $X$ = distance of a data point to its $k$-means cluster centre, with $\mathbb{E}[X] = 5$. "For a randomly picked point, what is the chance its distance to the centre is at least 20?"
$$P(X \ge 20) \;\le\; \frac{5}{20} \;=\; 0.25$$Distances are non-negative, so Markov applies with no further assumptions. This is the pattern: you know an average, you want a tail.
Chebyshev's inequality
Markov cannot tell apart two variables with the same mean but wildly different spread — the professor draws exactly this: one number line with points scattered far, another with points hugging the mean, both with the same red mean marker. To separate them you need the variance.
If $X$ has finite $\mathbb{E}[X]$ and finite variance $\sigma^2$, then for any $k > 0$:
$$P\big(|X - \mathbb{E}[X]| \ge k\sigma\big) \;\le\; \frac{1}{k^2}$$The deviation is measured in units of $\sigma$, not in absolute units. $P(|X-\mu| \ge k\sigma) \le 1/k^2$, so if a question gives you an absolute threshold $t$, you must first set $k = t/\sigma$ and the bound is $\sigma^2/t^2$. Writing $1/t^2$ is the single most common slip here.
Also: this is a two-sided bound (the absolute value). Markov and the Hoeffding form below are one-sided.
Chebyshev decays like $1/k^2$ — polynomial. Better than Markov, still not fast. And it needs only one random variable, no independence.
Hoeffding's inequality
Now assume more: many variables, independent, each bounded. In exchange you get exponential decay.
Let $X_1,\dots,X_n$ be independent with each $X_i \in [a,b]$, and let $\bar X = \frac{1}{n}\sum_{i=1}^n X_i$. Then for $t > 0$:
$$P\big(\bar X - \mathbb{E}[\bar X] \ge t\big) \;\le\; \exp\!\left(-\frac{2nt^2}{(b-a)^2}\right)$$Read the exponent as a checklist of what helps you: $n$ up → bound shrinks (more samples, more concentration); $t$ up → bound shrinks (asking about a bigger deviation); $(b-a)$ up → bound grows (wider range, more room to wander).
Coin with bias $p$. Each $X_i \in [0,1]$ so $b - a = 1$ and $\mathbb{E}[\bar X] = p$:
$$P(\bar X - p \ge t) \;\le\; e^{-2nt^2}$$With $t = 0.15$, the bound reaches $\approx 0.01$ around $n \approx 102$ — a hundred tosses already pin the empirical frequency to within $15\%$ with $99\%$ confidence.
It is a trade of assumptions for decay rate. Nothing more.
| Bound | Needs | Decay | Sided |
|---|---|---|---|
| Markov | $X \ge 0$; mean exists | $1/a$ — harmonic | one |
| Chebyshev | finite mean and variance | $1/k^2$ — polynomial | two |
| Hoeffding | independent, bounded in $[a,b]$ | $e^{-2nt^2/(b-a)^2}$ — exponential | one (as stated) |
Two utility inequalities
Small, and they carry the entire final step of the JL proof.
Since $P(A \cup B) = P(A) + P(B) - P(A\cap B)$ and $P(A \cap B) \ge 0$:
$$P(A_1 \cup \cdots \cup A_n) \;\le\; \sum_{i=1}^{n} P(A_i)$$No independence needed. That is precisely why it is usable — the $\binom{n}{2}$ pairwise-distortion events in JL are anything but independent.
If $A \subseteq B$ (equivalently $A \Rightarrow B$), then $P(A) \le P(B)$.
Used whenever you replace an event by a weaker, easier-to-bound one. In the Chernoff step, "$\|x\|^2 \ge c$" is rewritten as "$e^{\lambda\|x\|^2} \ge e^{\lambda c}$" — same event, monotone map, so equality actually holds; the inequality direction matters when the implication is strict.
Practice — Unit 01
MCQA non-negative random variable $X$ has $\mathbb{E}[X] = 4$. Which is the tightest guaranteed upper bound on $P(X \ge 16)$?
- A$0.0625$
- B$0.25$
- C$0.5$
- DCannot be determined without the variance
Markov: $P(X \ge 16) \le 4/16 = 0.25$. Option A is $(4/16)^2$ — the tempting move of "squaring because Chebyshev has a square", but you have no variance, so Chebyshev is unavailable. D is wrong because Markov needs only non-negativity and the mean, both of which you have.
NAT$X$ has $\mathbb{E}[X] = 50$ and $\sigma = 5$. Using Chebyshev, what is the smallest upper bound you can state for $P(|X - 50| \ge 20)$? (Answer to 2 decimals.)
Convert the absolute threshold into $\sigma$-units first: $k\sigma = 20 \Rightarrow k = 20/5 = 4$. Then $P \le 1/k^2 = 1/16 = 0.0625 \approx \mathbf{0.06}$.
The trap answer is $1/20^2 = 0.0025$, from forgetting to divide by $\sigma$.
MSQWhich statements are true?
- AMarkov's inequality can be applied to a random variable taking values in $[-3, 3]$.
- BHoeffding's bound decreases as the number of samples $n$ increases, all else fixed.
- CChebyshev's inequality requires the $X_i$ to be independent.
- DFor a fixed deviation, Hoeffding's bound is tighter than Chebyshev's for large $n$.
A is false: Markov demands $X \ge 0$. (You could apply it to $X + 3$, but not to $X$.)
C is false: Chebyshev is a statement about a single random variable — no independence anywhere. Independence is Hoeffding's requirement.
D is true: $e^{-2nt^2}$ beats $\sigma^2/(nt^2)$ eventually, and "eventually" arrives fast.
NATYou toss a fair coin $n$ times and want $P(\bar X - 0.5 \ge 0.1) \le 0.05$. Using Hoeffding, what is the smallest integer $n$ that guarantees this?
Here $X_i \in [0,1]$ so $b-a=1$, and $t = 0.1$. Require $e^{-2n(0.01)} \le 0.05$, i.e. $-0.02n \le \ln 0.05 = -2.9957$, giving $n \ge 149.79$. So $n = \mathbf{150}$.
Note this is the one-sided form. If the question had asked for $P(|\bar X - 0.5| \ge 0.1)$, you would first union-bound the two tails to get $2e^{-2nt^2} \le 0.05$, and $n$ would rise to $185$.
MCQEvents $A_1, \dots, A_{100}$ each have probability $0.001$. What can you say about $P(A_1 \cup \cdots \cup A_{100})$?
- AIt equals $0.1$
- BIt is at most $0.1$
- CIt is at least $0.1$
- DIt equals $1 - (0.999)^{100}$
Union bound gives $\le 100 \times 0.001 = 0.1$, and that is all you can say. A and D both assume something extra: D is the answer if the events were independent, which you were never told. This distinction is the entire reason the union bound is the tool of choice in the JL proof — the pairwise events there are dependent, and $1-(1-p)^m$ is not available.
Unit 02 · Week 1 L6–L9, Week 2 L1–L3
The Johnson–Lindenstrauss lemma
You can crush $n$ points from $\mathbb{R}^{10{,}000}$ down to $\mathbb{R}^{2000}$ and every pairwise distance survives to within $\pm 10\%$ — using a matrix you generate without ever looking at the data.
Given $n$ points $D = \{x_1,\dots,x_n\} \subset \mathbb{R}^d$ and $\epsilon \in (0,1)$, there exists a linear map $f : \mathbb{R}^d \to \mathbb{R}^k$ with
$$k \in O\!\left(\frac{\log n}{\epsilon^2}\right)$$such that for every pair $x_i, x_j \in D$:
$$(1-\epsilon)\|x_i - x_j\|^2 \;\le\; \|f(x_i) - f(x_j)\|^2 \;\le\; (1+\epsilon)\|x_i - x_j\|^2$$$k$ depends on $\log n$ and $\epsilon$ — it does not depend on $d$ at all. The professor writes this in capitals on the slide. Any option claiming $k$ grows with $d$ is wrong; any option with $\log d$ is wrong.
$n = 10^6$, $d = 10{,}000$, $\epsilon = 0.1$ so $1/\epsilon^2 = 100$:
$$k = O\!\left(\frac{\log 10^6}{\epsilon^2}\right) = O\big(6\log 10 \times 100\big) \approx 20 \times 100 = 2000$$Guarantee obtained: $0.9\|x-y\|^2 \le \|f(x)-f(y)\|^2 \le 1.1\|x-y\|^2$. A million points, $10{,}000 \to 2000$ dimensions, all $\approx 5\times10^{11}$ pairwise distances preserved to $\pm10\%$.
Read this as an order-of-magnitude illustration, not a plug-in of the proved bound. It uses $\log_2$ and silently drops the constant $8$. Feeding the same numbers into $k \ge \frac{8}{\epsilon^2}\log\frac{2n^2}{\delta}$ gives $k \approx 24{,}500$ — larger than $d$ itself. Both facts are worth carrying: the $O(\cdot)$ statement is what gets examined, and the constants are why JL is often less impressive in practice than on the slide.
Step 1 — Why no exact isometry exists
An isometry is a norm-preserving map: $\|Ru\| = \|u\|$ for all $u$. Expand what that demands of $R \in \mathbb{R}^{k\times d}$:
$$\|Ru\|^2 = (Ru)^\top(Ru) = u^\top (R^\top R) u \;\stackrel{!}{=}\; u^\top u \quad\Longrightarrow\quad R^\top R = I_{d\times d}$$Now read off what $R^\top R = I_d$ means. Writing $R$'s columns as $a_1,\dots,a_d \in \mathbb{R}^k$, the condition says those $d$ vectors are mutually orthonormal — $d$ orthonormal vectors living inside $\mathbb{R}^k$. Impossible when $k < d$: a $k$-dimensional space holds at most $k$ mutually orthogonal directions.
Exact is off the table. Settle for an approximate isometry, and only for the $\binom{n}{2}$ distances we actually care about — not for all of $\mathbb{R}^d$. That restriction is what buys us everything.
Step 2 — The construction
Let $R \in \mathbb{R}^{k\times d}$ have i.i.d. entries $r_{ij} \sim \mathcal{N}(0,1)$, and set
$$M = \frac{R}{\sqrt{k}}$$That is the whole construction. No data is consulted.
Fix any $u \in \mathbb{R}^d$ (later $u$ will be a difference $x_i - x_j$). Look at one coordinate of $Ru$, namely $r_1^\top u = \sum_{i=1}^d r_{1i}u_i$.
The cross terms die because the entries are independent. That is the only place independence is used here.
So every coordinate of $Ru$ is an independent $\mathcal{N}(0, \|u\|^2)$ draw. We have $k$ samples from a zero-mean Gaussian whose variance is exactly the quantity we want. The natural estimator of that variance is the average of squares:
$$\widehat{\|u\|^2} \;=\; \frac{1}{k}\sum_{i=1}^k (r_i^\top u)^2 \;=\; \left\|\frac{R u}{\sqrt k}\right\|^2 = \|Mu\|^2$$It is not a fudge factor. Dividing by $\sqrt{k}$ is precisely what turns "sum of $k$ squares" into "average of $k$ squares", which is the unbiased variance estimator. Hence $\mathbb{E}\big[\|Mu\|^2\big] = \|u\|^2$ — unbiased, exactly, for every $k$.
Step 3 — From unbiased to concentrated
Unbiased is not enough; we need the estimate to be close, not merely right on average. Standardise. Define
$$V = \tfrac{1}{\sqrt k}Ru \in \mathbb{R}^k, \qquad x = \frac{\sqrt{k}\,V}{\|u\|} \in \mathbb{R}^k \quad\Longrightarrow\quad \|x\|^2 = \frac{k\|V\|^2}{\|u\|^2}$$A short computation gives $\mathbb{E}[x] = \vec 0$ and $\operatorname{Cov}(x) = I_{k\times k}$, so
$$x \sim \mathcal{N}(\vec 0, I_{k\times k}), \qquad \mathbb{E}\big[\|x\|^2\big] = \sum_{i=1}^k \mathbb{E}[x_i^2] = k$$Now rewrite the bad event. Dividing by $\|u\|^2$ and multiplying by $k$:
$$P\Big(\|V\|^2 \ge (1+\epsilon)\|u\|^2\Big) \;=\; P\Big(\|x\|^2 \ge (1+\epsilon)k\Big)$$We have reduced everything to one clean question: how far can the squared norm of a standard $k$-dimensional Gaussian stray above its own mean $k$?
Step 4 — The Chernoff-style bound
Markov is too weak applied directly. The trick is to apply Markov to $e^{\lambda\|x\|^2}$, which converts an additive deviation into a multiplicative one.
- Exponentiate (monotone, so the event is unchanged): $P(\|x\|^2 \ge (1+\epsilon)k) = P\big(e^{\lambda\|x\|^2} \ge e^{\lambda(1+\epsilon)k}\big)$ for any $\lambda > 0$.
- Apply Markov: $\displaystyle \le \frac{\mathbb{E}\big[e^{\lambda\|x\|^2}\big]}{e^{\lambda(1+\epsilon)k}}$.
- Split by independence: $\mathbb{E}\big[e^{\lambda\sum_i x_i^2}\big] = \prod_{i=1}^k \mathbb{E}\big[e^{\lambda x_i^2}\big]$.
- Each factor is the MGF of a $\chi^2_1$: $\mathbb{E}\big[e^{\lambda x_i^2}\big] = (1-2\lambda)^{-1/2}$. So the bound is $\dfrac{(1-2\lambda)^{-k/2}}{e^{\lambda(1+\epsilon)k}}$.
- Write as one exponential and Taylor-expand $\log$ for small $\lambda$: $\;\le \exp\!\big(k(2\lambda^2 - \lambda\epsilon)\big)$.
- Minimise $F(\lambda) = 2\lambda^2 - \lambda\epsilon$: $F'(\lambda) = 4\lambda - \epsilon = 0 \Rightarrow \boxed{\lambda = \epsilon/4}$, giving $F(\epsilon/4) = -\epsilon^2/8$.
and symmetrically for the $(1-\epsilon)$ side.
Step 5 — Union bound over all pairs, and out pops $k$
That bound is for one fixed vector. We need it for all $\binom{n}{2}$ difference vectors simultaneously. The events are dependent (they share the same $M$), so the union bound is the only tool available:
$$P(\text{some pair distorted}) \;\le\; \sum_{\binom{n}{2}\text{ pairs}} 2e^{-k\epsilon^2/8} \;\le\; 2n^2 e^{-k\epsilon^2/8}$$The factor $2$ covers both tails; $\binom{n}{2} \le n^2$ is the crude-but-fine bound the professor uses. Demand this be at most a failure probability $\delta$ and solve:
$$2n^2 e^{-k\epsilon^2/8} \le \delta \;\Longrightarrow\; \frac{k\epsilon^2}{8} \ge \log\frac{2n^2}{\delta} \;\Longrightarrow\; \boxed{\;k \;\ge\; \frac{8}{\epsilon^2}\log\frac{2n^2}{\delta}\;}$$Since $\log(2n^2/\delta) = O(\log n)$ for fixed $\delta$, this is $k \in O(\log n/\epsilon^2)$. The lemma is proved.
The course-specific numbers are $\lambda = \epsilon/4$, the exponent $e^{-k\epsilon^2/8}$, and $k \ge \frac{8}{\epsilon^2}\log\frac{2n^2}{\delta}$. A one-sided-only analysis drops the $2$ and gives $k \ge \frac{8}{\epsilon^2}\log\frac{n^2}{\delta}$. Questions do ask you to plug into these.
Highlights the notes call out
- The analysis is probabilistic, but the lemma asserts the existence of a deterministic $f$. Probability is the proof technique, not the conclusion.
- To actually build $f$: keep drawing random $M$ until one works. Each draw succeeds with probability $\ge 1-\delta$, so you rarely need many.
- $M$ is oblivious to the data — you only need $d$, $n$ and $\epsilon$ to generate it, never the points themselves. You can build the map before the dataset arrives.
- Applying the map costs $O(ndk)$ — $n$ points, each a $k\times d$ matrix-vector product.
- The win is real only when $d \gg \log n/\epsilon^2$. For small $d$, $k$ may exceed $d$ and there was nothing to reduce.
The linear-algebra reading
Take the SVD $M = U\Sigma V^\top$ with $M \in \mathbb{R}^{k\times d}$: $U$ is $k\times k$ orthonormal, $\Sigma$ is $k \times d$ "diagonal", $V^\top$ is $d\times d$ orthonormal. So $Mu$ is three moves:
- $V^\top$ — a random rotation in $\mathbb{R}^d$. Length preserved, direction randomised.
- $\Sigma$ — scale and truncate. Keep the first $k$ coordinates, scaled by $\sigma_1,\dots,\sigma_k$; discard the remaining $d-k$. This is the actual dimension reduction.
- $U$ — another rotation, now inside $\mathbb{R}^k$. Length preserved again.
A random rotation spreads a unit vector's mass evenly over all $d$ coordinates, so each entry of $V^\top u$ is $\approx 1/\sqrt d$. Meanwhile the singular values of $\frac{1}{\sqrt k}R$ all concentrate near $\sqrt{d/k}$ (within roughly $\pm 1$). Multiply: each surviving coordinate is $\approx \sqrt{d/k}\cdot 1/\sqrt{d} = 1/\sqrt k$. Summing $k$ of them:
$$\|Mu\|^2 \approx \underbrace{\tfrac1k + \cdots + \tfrac1k}_{k\ \text{terms}} = 1 = \|u\|^2$$Truncating to $k$ coordinates loses almost nothing precisely because the rotation was random — no coordinate carried disproportionate mass. In high dimensions, a random direction is nearly orthogonal to any fixed direction, and mass is democratically distributed. That is the geometric heart of JL.
Geometrically: $M$ maps the unit sphere to an ellipsoid whose axis lengths are the singular values. Because those singular values are all nearly equal, the ellipsoid is nearly a sphere — and a nearly-spherical image is exactly what "approximate isometry" means.
Practice — Unit 02
MCQA dataset has $n = 10^4$ points in $\mathbb{R}^{50{,}000}$. A colleague adds $50{,}000$ more features (so $d$ doubles) but keeps $n$ the same. How does the JL target dimension $k$ change?
- AIt doubles
- BIt grows by $\log 2$
- CIt is unchanged
- DIt halves
$k \in O(\log n/\epsilon^2)$ has no $d$ in it. Doubling $d$ changes nothing about $k$; it only makes the reduction more worthwhile. What does change is the cost of applying the map, $O(ndk)$, which doubles.
NATUsing $k \ge \frac{8}{\epsilon^2}\log\frac{2n^2}{\delta}$ with $n = 1000$, $\epsilon = 0.5$, $\delta = 0.1$ (natural log), what is the smallest valid integer $k$?
$\dfrac{2n^2}{\delta} = \dfrac{2\times10^6}{0.1} = 2\times 10^7$, so $\ln(2\times10^7) = \ln 2 + 7\ln 10 = 0.693 + 16.118 = 16.811$.
And $\dfrac{8}{\epsilon^2} = \dfrac{8}{0.25} = 32$. So $k \ge 32 \times 16.811 = 537.96$, giving $k = \mathbf{538}$.
Two things to watch: the paper may specify $\log_2$ instead of $\ln$ (which would change the number), and the $2$ inside $\log\frac{2n^2}{\delta}$ is the two-sided factor — drop it and you get $536$ instead.
MSQAbout the JL map $M = R/\sqrt{k}$ with $R_{ij} \sim \mathcal{N}(0,1)$, which are true?
- A$\mathbb{E}\big[\|Mu\|^2\big] = \|u\|^2$ for every $u$ and every $k$.
- B$M$ must be recomputed if a new data point is added.
- C$M^\top M = I_d$.
- DThe lemma guarantees a map exists, though the construction is randomized.
B is false: $M$ never depends on the data — only on $d$, $n$, $\epsilon$. (Strictly, $n$ enters through $k$, so adding enough points eventually nudges $k$; but no recomputation is triggered by the point's values, which is what the option claims.)
C is false: that is exactly the exact-isometry condition proved impossible for $k < d$.
A is true — unbiasedness is exact, not asymptotic. D is true — probabilistic method, deterministic conclusion.
MCQIn the JL proof, why is the union bound used instead of $1-(1-p)^m$ for the $\binom{n}{2}$ pairwise events?
- AThe union bound gives a tighter estimate
- BThe pairwise distortion events are not independent
- C$\binom{n}{2}$ is too large for the product formula to converge
- DBecause the events are disjoint
All $\binom{n}{2}$ events are driven by the same random matrix $M$, so they are heavily dependent — the product formula is simply invalid. The union bound is looser (A is backwards) but it needs no independence, which is the entire point. D is wrong too: the events overlap freely.
MCQHalving $\epsilon$ from $0.2$ to $0.1$, with $n$ and $\delta$ fixed, multiplies the required $k$ by roughly:
- A$2$
- B$4$
- C$\sqrt2$
- D$\log 2$
$k \propto 1/\epsilon^2$, so halving $\epsilon$ quadruples $k$. Accuracy is expensive: the $\epsilon^{-2}$ dependence, not the $\log n$, is what usually makes $k$ large in practice.
Unit 03 · Week 3, Lectures 1–8
Approximate nearest neighbours & LSH
JL got the dimension down but the query still touches all $n$ points. To go sub-linear in $n$ you must stop measuring distances altogether — and instead build a hash that makes near points collide on purpose.
Why JL is not the answer here
| Approach | Preprocessing | Per query |
|---|---|---|
| Naive NN in $\mathbb{R}^d$ | — | $O(nd)$ |
| JL, then NN in $\mathbb{R}^k$ | $O(ndk)$ | $O(dk + nk)$ |
| LSH | build $L$ tables | $O(n^\rho)$ with $\rho < 1$ |
The JL query cost is $O(dk)$ to project the query plus $O(nk)$ for $n$ distance computations. The $d$ shrank to $k$, but the $n$ is untouched — that is the term that hurts at a billion points. What survives from JL is only the intuition: close points map to close points. LSH pushes that idea to its extreme — instead of preserving distance, only preserve "same bucket or not".
The definition
A family $\mathcal{H}$ is $(r,c,p_1,p_2)$-sensitive, for $r > 0$, $c > 1$, $0 \le p_2 < p_1 \le 1$, if for any $x,y \in \mathbb{R}^d$ and a randomly chosen $h \in \mathcal{H}$:
$$\|x-y\| \le r \;\;\Longrightarrow\;\; \Pr_{h\sim\mathcal H}\big(h(x)=h(y)\big) \;\ge\; p_1 \qquad \textsf{[TPR]}$$ $$\|x-y\| \ge cr \;\;\Longrightarrow\;\; \Pr_{h\sim\mathcal H}\big(h(x)=h(y)\big) \;\le\; p_2 \qquad \textsf{[FPR]}$$The randomness is over the choice of $h$, not over the data.
Close $\Rightarrow$ collide a lot: $\;\le r$ pairs with $\ge p_1$. Far $\Rightarrow$ collide rarely: $\;\ge cr$ pairs with $\le p_2$. Flipping either inequality is the single most common error on this topic. Sanity check that always works: $p_1$ is the big probability and goes with the small distance.
Also note: nothing at all is asserted about the annulus $r < \|x-y\| < cr$. That grey ring is the price of approximation.
Language the professor uses throughout: points within $r$ are "good points" / neighbours / positives; points beyond $cr$ are "bad points" / strangers / negatives. So $p_1$ literally is the true positive rate and $p_2$ is the false positive rate of a single hash.
The hash family: Datar et al. (2004)
Read it geometrically: $a^\top x$ projects $x$ onto a random direction, $b$ shifts the ruler by a random offset, and $\lfloor\cdot/w\rfloor$ chops the line into intervals of length $w$. Two points collide iff their projections land in the same interval.
- Condition on $a$. Write $\Delta = a^\top(x-y)$, the gap between the two projections on the line.
- Necessary condition. If $|\Delta| \ge w$ the two points can never share an interval of width $w$. So collision requires $|\Delta| < w$.
- Probability over $b$. Given $\Delta$, the random offset $b$ must fall in a sub-interval of length $w - |\Delta|$ out of $w$: $$\Pr_b\big(h(x)=h(y) \mid a\big) = \max\!\left(0,\; 1 - \frac{|\Delta|}{w}\right)$$
- Average over $a$. Since $a \sim \mathcal N(0,I_d)$, the scalar $\Delta = a^\top(x-y) \sim \mathcal{N}\big(0, \|x-y\|^2\big)$. Integrating: $$\Pr\big(h(x)=h(y)\big) = \frac{2}{\sqrt{2\pi}\,\|x-y\|}\int_0^\infty \max\!\left(0, 1-\frac tw\right) e^{-\frac{t^2}{2\|x-y\|^2}}\,dt$$
Not its closed form — the professor never evaluates it. Only that it is a monotonically decreasing function of $\|x-y\|$. Call it $f(\cdot)$. Then $p_1 = f(r)$ and $p_2 = f(cr)$, and since $cr > r$ and $f$ decreases, $p_2 < p_1$ automatically. That is the entire justification that $\mathcal H_w$ is a sensitive family.
Step 4 is also where the Gaussian is doing real work: a Gaussian $a$ makes $a^\top(x-y)$ a one-dimensional Gaussian whose variance is exactly $\|x-y\|^2$. The projection converts a $d$-dimensional distance into a one-dimensional spread — which is why this family is tuned to Euclidean distance specifically.
This is not random-hyperplane / cosine LSH. Do not substitute $1 - \theta/\pi$ into anything here. In the Datar family the hash output is an integer (a bucket index), not a bit, and the buckets are slabs, not wedges.
The 2025 T3 paper asked which picture matches cosine similarity, so know the contrast even though the lectures only derive the Euclidean family:
| Family | Hash | Buckets look like | Collision prob. |
|---|---|---|---|
| Euclidean (Datar) — taught | $\big\lfloor\frac{a^\top x + b}{w}\big\rfloor$ | parallel slabs / stripes of width $w$ | decreasing in $\|x-y\|$ |
| Cosine (SimHash) | $\mathrm{sign}(a^\top x)$ | angular wedges through the origin | $1 - \theta/\pi$ |
The discriminator: cosine similarity is scale-invariant ($x$ and $2x$ have similarity $1$), so its buckets must be cones through the origin. Euclidean distance is not scale-invariant, so its buckets are translation-covariant stripes. Concentric circles or squares are wrong for both — they bucket by norm, so two antipodal points on the same ring always collide despite being maximally far apart.
Why one hash is not enough — the professor's running example
The query has $T = 10$ good points nearby and $B = 8000$ bad points far away.
- Expected good points retrieved: $0.8 \times 10 = \mathbf{8}$ ✓
- Expected bad points retrieved: $0.4 \times 8000 = \mathbf{3200}$ ✗
3208 points retrieved in total — worse than useless. Even though $p_2$ is "small", it is multiplied by a huge $B$. This is the entire motivation for what follows.
Step 1 — AND: crush the FPR
Concatenate $k$ independent hashes into one vector-valued hash:
$$g(x) = \big[h_1(x)\;\; h_2(x)\;\;\cdots\;\;h_k(x)\big], \qquad h_i \sim \mathcal H \text{ independently}$$Two points collide under $g$ only if all $k$ coordinates match. By independence:
$$\mathrm{TPR} = p_1^k, \qquad \mathrm{FPR} = p_2^k$$Expected number of false-positive collisions is $n\,p_2^k$. Set it to $1$ — a constant, independent of $n$:
$$n\,p_2^k = 1 \;\Longrightarrow\; p_2^k = \frac 1n \;\Longrightarrow\; \boxed{\;k = \frac{\log n}{\log(1/p_2)}\;}$$In the example: $k = \log(10{,}000)/\log(1/0.4) \approx 10$.
$\mathrm{FPR} = (0.4)^{10} = 0.000105$ → about $1$ bad point. Excellent.
$\mathrm{TPR} = (0.8)^{10} = 0.107$ → $10 \times 0.107 \approx 1$ good point. Terrible.
We traded "finds the neighbour but retrieves 3208 points" for "retrieves 3 points but almost never finds the neighbour". Neither is acceptable.
Step 2 — OR: rescue the TPR
Build $L$ independent tables, each one an AND of $k$ hashes. Two points collide if at least one table matches. Taking complements and using independence across tables:
$$\Pr(\text{collide}) = 1 - \prod_{i=1}^{L}\Pr\big(g_i(x) \ne g_i(y)\big) = 1 - \big(1 - p^k\big)^L$$The exponent $\rho$ — where sub-linearity comes from
Substitute the chosen $k = \log n/\log(1/p_2)$ into $p_1^k$:
$$p_1^k = \exp\!\left[\log n \cdot \frac{\log p_1}{\log(1/p_2)}\right] = \exp\!\left[\log n \cdot \left(-\frac{\log(1/p_1)}{\log(1/p_2)}\right)\right]$$Since $p_2 < p_1$, we have $\log(1/p_1) < \log(1/p_2)$, so $\rho < 1$ always.
Now choose $L = \theta n^{\rho}$ for a constant $\theta$. Then:
$$\mathrm{TPR} = 1 - \big(1 - n^{-\rho}\big)^{\theta n^{\rho}} = 1 - \Big[\big(1-n^{-\rho}\big)^{n^{\rho}}\Big]^{\theta} \;\xrightarrow[\;n\to\infty\;]{}\; \boxed{\;1 - e^{-\theta}\;}$$using $(1 - 1/x)^x \to 1/e$. And for the FPR, since $p_2^k = 1/n$ by construction:
$$\mathrm{FPR} = 1 - \left(1 - \tfrac1n\right)^{L} \approx 1 - e^{-L/n} = 1 - e^{-\theta n^{\rho-1}} \approx \boxed{\;\theta\, n^{\rho-1}\;}$$(the last step uses $1 - e^{-z}\approx z$ for small $z$, valid because $\rho < 1 \Rightarrow n^{\rho-1}\to 0$). Multiply the FPR by $n$ points to get the expected number of bad points retrieved:
$$\#\text{false positives} \approx n \cdot \theta n^{\rho-1} = \theta\, n^{\rho} \quad \text{— sub-linear, because } \rho < 1.$$$\rho = \dfrac{\log(1/0.8)}{\log(1/0.4)} = 0.2435$, so $L = 2 \times (10{,}000)^{0.2435} \approx 2\times 10 = 20$ tables.
$\mathrm{TPR} = 1 - e^{-2} = 0.86$ → $10 \times 0.86 \approx \mathbf{9}$ of the $10$ good points.
Bad points $\approx \theta n^{\rho} = \mathbf{20}$ of the $8000$.
| Construction | TPR | FPR | Points retrieved |
|---|---|---|---|
| Single hash, $k=1, L=1$ | 0.8 | 0.4 | 3208 |
| Pure AND, $k=10, L=1$ | 0.107 | 0.0001 | 3 |
| AND-then-OR, $k=10, L=20$ | 0.86 | 0.002 | 29 |
$\theta=1 \Rightarrow$ TPR $=0.63$; $\theta=2 \Rightarrow 0.86$; $\theta=3 \Rightarrow 0.96$. Higher $\theta$ means more tables, more memory, more query work — and a better chance of finding the neighbour. That is the whole tuning story.
What $\rho$ controls, and how to make it small
- Number of tables: $L = \theta n^\rho$. Larger $\rho$ → more tables → more query time and more storage.
- FPR: $\theta n^{\rho-1}$. Larger $\rho$ → more junk retrieved.
- Sub-linearity: $n^\rho \ll n$ precisely because $\rho < 1$. Everything hinges on this.
So you want $\rho$ small, which means you want the gap between $p_1$ and $p_2$ to be large. The performance of the whole algorithm is decided by the quality of the hash family — the professor's closing design principle for the week.
For the Datar family, $w$ controls bucket granularity: small $w$ → fine buckets, both probabilities drop; large $w$ → coarse buckets, both rise toward 1. Neither extreme separates. The recipe: sample a subset $D'$ of the data (say 100 points), empirically estimate $\hat p_1(w)$ and $\hat p_2(w)$ from observed collisions, form $\hat\rho(w)$, and grid-search $w$ for the smallest $\hat\rho(w)$.
Practice — Unit 03
MCQA family is $(2, 3, 0.7, 0.2)$-sensitive. Two points are at distance $5$. What does the definition guarantee about their collision probability?
- AIt is at least $0.7$
- BIt is at most $0.2$
- CIt is between $0.2$ and $0.7$
- DNothing is guaranteed
Here $r = 2$ and $cr = 3\times2 = 6$. Distance $5$ satisfies neither $\le 2$ nor $\ge 6$ — it sits in the annulus $(2, 6)$, so… wait: check again. $5 < 6$, so the far condition does not apply.
The correct answer is D. Distance $5$ lies strictly inside the annulus $r < 5 < cr$, where the definition asserts nothing at all. This is exactly the trap: you must compute $cr$ (not compare against $c$) and then check which of the two regimes the distance falls into. Had the distance been $7 \ge 6$, the answer would be B.
NATWith $p_1 = 0.9$, $p_2 = 0.3$, compute $\rho$ to three decimals.
$\rho = \dfrac{\log(1/0.9)}{\log(1/0.3)} = \dfrac{0.10536}{1.20397} = \mathbf{0.0875}$.
The base of the logarithm cancels — use whichever you like. Note how a wide $p_1/p_2$ gap gives a tiny $\rho$, hence very few tables: $L = \theta n^{0.0875}$ is almost constant.
MSQIncreasing $k$ (the number of AND-ed hashes), holding $L$ fixed:
- Adecreases the FPR
- Bdecreases the TPR
- Cincreases the number of hash tables
- Dmakes collisions harder
AND requires all $k$ coordinates to match, so collisions get strictly harder — both $p_1^k$ and $p_2^k$ shrink. C confuses the two knobs: $k$ is the depth of each table, $L$ is the number of tables. Increasing $k$ does not change $L$.
The mnemonic: AND ↓ both rates (fixes FPR, damages TPR). OR ↑ both rates (fixes TPR, damages FPR). You need both, in that order.
NATA dataset has $n = 10^6$ points and the family has $p_2 = 0.5$. Using $k = \log n/\log(1/p_2)$ with base-2 logarithms, what is $k$?
$\log_2(10^6) = 6\log_2 10 = 6 \times 3.3219 = 19.93$, and $\log_2(1/0.5) = 1$. So $k = 19.93 \approx \mathbf{20}$.
Check it does what it is supposed to: $n\,p_2^k = 10^6 \times 2^{-20} = 10^6/1{,}048{,}576 \approx 0.95 \approx 1$. ✓ The choice of $k$ is precisely "make expected false-positive collisions equal to one".
MCQUnder the AND-then-OR construction with $L = \theta n^\rho$, the TPR $\approx 1 - e^{-\theta}$. What does this tell you?
- ATPR improves as $n$ grows
- BTPR is independent of $n$ and controlled entirely by $\theta$
- CTPR degrades as $n$ grows
- DTPR depends only on $\rho$
The $n$ cancels exactly — that is the point of choosing $L$ proportional to $n^\rho$. You get a fixed recall guarantee that does not degrade as the dataset grows, and you pay for it in $n^\rho$ tables rather than $n$ distance computations. $\rho$ governs cost and FPR, $\theta$ governs recall.
MSQAbout the Datar-style hash $h_{ab}(x) = \lfloor (a^\top x + b)/w\rfloor$, which are true?
- AEach bucket is a slab (a region between two parallel hyperplanes) in $\mathbb{R}^d$.
- BBuckets are convex regions.
- CIncreasing $w$ increases the collision probability for every pair.
- DThe collision probability depends on $x$ and $y$ only through $\|x-y\|$.
A, B: the pre-image of a fixed integer is $\{x : jw \le a^\top x + b < (j+1)w\}$ — the region between two parallel hyperplanes with normal $a$. An intersection of two half-spaces, hence convex.
C: the conditional probability $\max(0, 1-|\Delta|/w)$ increases in $w$ for every $\Delta$, so the average does too. Wider buckets, more collisions — for good and bad pairs alike, which is why $w$ must be tuned via $\hat\rho(w)$ rather than simply maximised.
D: $\Delta \sim \mathcal N(0, \|x-y\|^2)$ depends on the pair only through that norm. The collision probability is rotation- and translation-invariant.
NAT$n = 10^4$, $p_1 = 0.8$, $p_2 = 0.4$, $k = 10$, $L = 20$. What is the expected number of bad points retrieved if there are $8000$ bad points? (Nearest integer.)
Exact: $\mathrm{FPR} = 1 - (1 - 0.4^{10})^{20}$. Since $0.4^{10} = 1.0486\times10^{-4}$, this is $\approx 20 \times 1.0486\times10^{-4} = 2.097\times10^{-3}$. Times $8000$ gives $\mathbf{16.8 \approx 17}$.
The professor's slide quotes $\approx 20$, using the cleaner asymptotic $\theta n^{\rho} = 2 \times 10^{0.2435\times4} \approx 20$, which counts against all $n = 10^4$ points rather than only the $8000$ bad ones. Both are right at this level of precision — but if a paper gives you exact $k$, $L$ and a bad-point count, compute directly from $1-(1-p_2^k)^L$.
Unit 04 · Week 4, Lectures 1–5
SVD & randomized SVD
Exact SVD costs $O(md^2)$. Randomized SVD gets you a near-optimal rank-$k$ approximation for $O(md\ell)$ with $\ell = k+p$ — and the whole trick is that a random sketch of a matrix lands, with high probability, in the subspace that matters.
Throughout Week 4 the professor writes $A \in \mathbb{R}^{m\times d}$ with $m > d$ ($m$ data points, $d$ features). The typeset course notes use $A \in \mathbb{R}^{m \times n}$ for the same object — read $n \leftrightarrow d$. Track shapes obsessively; almost every SVD exam question is really a shape question.
SVD: the statement
- $U, V$ are orthogonal; columns of $U$ are left singular vectors, columns of $V$ are right singular vectors.
- $\Sigma$ carries $\sigma_1 \ge \sigma_2 \ge \cdots \ge \sigma_d \ge 0$ on the diagonal, zeros elsewhere (including the bottom $m-d$ rows).
- If $\mathrm{rank}(A) = r$ then $\sigma_1 \ge \cdots \ge \sigma_r > 0 = \sigma_{r+1} = \cdots$.
- $Av_i = \sigma_i u_i$ and $A^\top u_i = \sigma_i v_i$ for $1 \le i \le r$.
Read $Aw = U\Sigma(V^\top w)$ as three moves: rotate by $V^\top$, scale coordinate-wise by $\Sigma$, rotate by $U$ — the same decomposition you met in the JL linear-algebra lecture.
So: eigenvectors of $A^\top A$ are the right singular vectors; eigenvectors of $AA^\top$ are the left singular vectors; the eigenvalues of both are $\sigma_i^2$. Singular values are the square roots of those eigenvalues, never the squares.
Among all matrices $B$ of rank $k$, the minimiser of $\|A - B\|_2$ is obtained by truncating the SVD sum:
$$B^\star = \sum_{i=1}^{k}\sigma_i u_i v_i^\top = U_k\Sigma_k V_k^\top, \qquad \|A - B^\star\|_2 = \sigma_{k+1}$$The error you pay is exactly the first singular value you threw away. The professor states only the spectral-norm ($\|\cdot\|_2$) version — that is what is in scope.
Applications actually taught
PCA
The covariance/scatter matrix is $A^\top A$ ($d\times d$), whose eigenvectors are $V$. Projecting $a_i \mapsto [a_i^\top v_1, \dots, a_i^\top v_k] \in \mathbb{R}^k$ gives the top-$k$ principal components. PCA is SVD.
Recommender systems
A ratings matrix $A_{m\times d}$ (users × movies), mostly missing, factorised as $A = B_{m\times k}C_{k\times d}$ with $k \ll d$. A row of $B$ is a user's latent taste vector; a column of $C$ is a movie's latent profile. This is matrix completion.
The unifying idea: "data lies near a low-dimensional subspace" and "the matrix is approximately low rank" are the same sentence.
Fast SVD — what an oracle for $u_1,\dots,u_k$ buys you
Suppose someone hands you $Q = [u_1 \cdots u_k] \in \mathbb{R}^{m\times k}$, the top $k$ left singular vectors. Then $QQ^\top$ is the projection onto their span, and:
$$\big(QQ^\top\big)A \;=\; \text{the best rank-}k\text{ approximation of }A, \qquad \big\|A - QQ^\top A\big\|_2 = \sigma_{k+1}$$- $B = Q^\top A$ — shapes $(k\times m)(m\times d) = k \times d$. This is the compression step.
- $\mathrm{SVD}(B) = \tilde U \tilde\Sigma \tilde V^\top$ — cost $O(dk^2)$, because $B$ is tiny.
- Pull back: $\hat U = Q\tilde U$, $\hat\Sigma = \tilde\Sigma$, $\hat V = \tilde V$.
- $\hat A = \hat U\hat\Sigma\hat V^\top = QQ^\top A$.
Cost drops from $O(md^2)$ to $O(dk^2)$ for the decomposition itself — you do the expensive SVD on a $k\times d$ matrix instead of an $m\times d$ one.
Look at what the algorithm actually used: only that $Q$ has orthonormal columns and that $\operatorname{span}(Q) = \operatorname{span}(u_1,\dots,u_k)$. The individual vectors never mattered — only the subspace. And $\operatorname{span}(u_1,\dots,u_k)$ sits inside the column space of $A$. So if we can cheaply grab any orthonormal basis for roughly the right subspace of $\mathrm{col}(A)$, we are done. That is what a random sketch does.
Randomized SVD
Draw $\omega \sim \mathcal N(\vec 0, I_d)$. Then $A\omega = \sum_i \omega_i a_i$ is a random linear combination of the columns of $A$, and:
$$\mathbb{E}[A\omega] = A\,\mathbb{E}[\omega] = \vec 0, \qquad \operatorname{Cov}(A\omega) = A\,\mathbb{E}[\omega\omega^\top]A^\top = AA^\top$$The sketch vector is a zero-mean Gaussian with covariance $AA^\top$ — and the eigenvectors of $AA^\top$ are precisely $u_1,\dots,u_m$, with eigenvalues $\sigma_i^2$. A Gaussian spreads most of its mass along its high-variance directions. So samples $A\omega$ preferentially align with the top singular directions, weighted by $\sigma_i^2$. Draw $\ell$ of them and their span is, with high probability, close to $\operatorname{span}(u_1,\dots,u_\ell)$.
Equivalently, in the rank-1 expansion $A\omega = \sum_i \sigma_i u_i (v_i^\top \omega)$: the coefficients $v_i^\top\omega$ are i.i.d. $\mathcal N(0,1)$ — no direction is favoured by the randomness — so the $\sigma_i$ alone decide which $u_i$ dominate.
Input $A \in \mathbb{R}^{m\times d}$, target rank $k$, oversampling $p$, and $\ell = k + p \;(\ll m, d)$.
| Step | Operation | Result shape | Cost |
|---|---|---|---|
| 1 | Draw $\Omega$ with $\omega_i \sim \mathcal N(\vec0, I_d)$ | $d \times \ell$ | $O(d\ell)$ |
| 2 | Sketch: $Y = A\Omega$ | $m \times \ell$ | $O(md\ell)$ |
| 3 | Orthonormalise: $Q = \mathrm{orth}(Y)$ (QR / Gram–Schmidt) | $m \times \ell$ | $O(m\ell^2)$ |
| 4 | Project: $B = Q^\top A$ | $\ell \times d$ | $O(md\ell)$ |
| 5 | Small SVD: $B = \tilde U\tilde\Sigma\tilde V^\top$ | $\tilde U$ is $\ell\times\ell$ | $O(d\ell^2)$ |
| 6 | Pull back: $\hat U = Q\tilde U_k$, $\hat\Sigma = \tilde\Sigma_k$, $\hat V = \tilde V$ | $\hat U$ is $m\times k$ | $O(m\ell k)$ |
The win is $d^2 \to d\ell$. Steps 2 and 4 dominate; everything else is lower order.
How good is it?
With probability at least $1-\delta$:
$$\big\|A - QQ^\top A\big\|_2 \;\le\; (1+\epsilon)\,\sigma_{k+1}, \qquad \epsilon = 6\sqrt{\frac{k+p}{p}\,\ln\frac{2}{\delta}}$$Compare to the benchmark: the best possible rank-$k$ error is exactly $\sigma_{k+1}$. So you are within a $(1+\epsilon)$ factor of optimal. The professor's illustration: if $\epsilon = 1$, then $\|A - QQ^\top A\| \le 2\sigma_{k+1}$ — within a factor of two of the best any rank-$k$ matrix can do.
Look at where $p$ sits: $\epsilon \propto \sqrt{(k+p)/p}$. Set $p = 0$ and the bound blows up. With $\ell = k$ exactly, the $k$ random vectors must span the top-$k$ subspace perfectly — one unlucky draw that is nearly parallel to another and the sketch misses a direction entirely. A handful of spare columns gives the sketch room to fail on a few directions and still cover the subspace.
Practical values: $p = 5$ or $p = 10$ works well. Note also that $\delta$ enters only as $\ln(2/\delta)$ — very high confidence is very cheap.
The recovered subspace is good exactly when the spectral gap at $k$ is large. If $\sigma_{k+1}/\sigma_k \approx 1$ — a flat spectrum — the sketch cannot tell direction $k$ from direction $k+1$, and the method struggles. (Written "Davidson–Kahan" on the slide.)
Power iteration — fixing a flat spectrum
If the singular values decay slowly, manufacture a gap. The algebra:
$$AA^\top = U\Sigma^2U^\top \quad\Longrightarrow\quad (AA^\top)A = U\Sigma^3V^\top \quad\Longrightarrow\quad (AA^\top)^qA = U\,\Sigma^{2q+1}\,V^\top$$Same singular vectors, singular values raised to $2q+1$. Ratios are driven toward zero geometrically:
$$\left(\frac{\sigma_{k+1}}{\sigma_k}\right) \;\longrightarrow\; \left(\frac{\sigma_{k+1}}{\sigma_k}\right)^{2q+1}$$A mediocre ratio of $0.9$ with $q=1$ (so $2q+1=3$): $0.9^3 = 0.729$. With $q=3$: $0.9^7 = 0.478$. Each power step compounds the separation.
$AA^\top$ is $m\times m$ — for a million rows that is a $10^{12}$-entry matrix, and forming it costs $O(m^2d)$. Instead alternate multiplications by $A^\top$ and $A$, re-orthonormalising each time for numerical stability.
- $Y = A\Omega$ $O(md\ell)$
- for $i = 1 \dots q$:
- $Q = \mathrm{orth}(Y)$ $m\times\ell$
- $Z = A^\top Q$ $d\times\ell$
- $Y = AZ$ $m\times\ell$ — net effect $Y = (AA^\top)Q$
- $Q = \mathrm{orth}(Y)$, then $B = Q^\top A$, $\;\mathrm{SVD}(B) = \tilde U\tilde\Sigma\tilde V^\top$, $\;\hat U = Q\tilde U$, $\;\hat A = \hat U\hat\Sigma\hat V^\top$.
Loop cost $O(md\ell q)$. The improved guarantees:
$$\big\|QQ^\top - U_kU_k^\top\big\|_2 \le \left(\frac{\sigma_{k+1}}{\sigma_k}\right)^{2q+1}, \qquad \big\|A - QQ^\top A\big\|_2 \le \big(1 + \epsilon^{1/(2q+1)}\big)\sigma_{k+1}$$Practice — Unit 04
MCQ$A \in \mathbb{R}^{5000 \times 200}$. What is the shape of $\Sigma$ in the full SVD $A = U\Sigma V^\top$?
- A$200 \times 200$
- B$5000 \times 5000$
- C$5000 \times 200$
- D$200 \times 5000$
In the full SVD, $\Sigma$ has the same shape as $A$: $U$ is $5000\times5000$, $\Sigma$ is $5000\times200$, $V^\top$ is $200\times200$. Only the top $200\times200$ block of $\Sigma$ is non-zero; the bottom $4800$ rows are all zeros. Option A is the shape in the thin/economy SVD — a real distinction, so read which one the question asks for.
MSQ$A \in \mathbb{R}^{m\times d}$ with $m > d$. Which are true?
- AThe eigenvalues of $A^\top A$ are the squares of the singular values of $A$.
- B$AA^\top$ and $A^\top A$ have the same non-zero eigenvalues.
- CThe left singular vectors are the eigenvectors of $A^\top A$.
- D$\|A\|_2 = \sigma_1$.
C is false — and it is the classic swap. $A^\top A = V\Sigma^2V^\top$ gives the right singular vectors; $AA^\top = U\Sigma^2U^\top$ gives the left ones. Mnemonic: "$A^\top A$ is $d\times d$, lives in feature space, gives $V$."
B is true: both equal $\{\sigma_i^2 : \sigma_i > 0\}$; they differ only in how many extra zeros they carry ($AA^\top$ has $m-d$ more).
NAT$A$ has singular values $10, 8, 6, 3, 1$. What is $\min_{\mathrm{rank}(B)=3}\|A - B\|_2$?
Eckart–Young: the error is $\sigma_{k+1}$ with $k = 3$, so $\sigma_4 = \mathbf{3}$.
Traps: $\sigma_3 = 6$ (off-by-one — the error is the first value you discard, not the last you keep) and $\sqrt{3^2+1^2} = \sqrt{10}$ (that would be the Frobenius-norm error, a different theorem that this course does not state).
NATIn randomized SVD with $k = 20$ and oversampling $p = 5$, what is the shape of $B = Q^\top A$ when $A \in \mathbb{R}^{10^6 \times 5000}$? Give the number of rows.
$\ell = k + p = 25$, so $Q$ is $10^6 \times 25$ and $B = Q^\top A$ is $\mathbf{25} \times 5000$. That is the entire point: you run an exact SVD on a $25\times5000$ matrix rather than a $10^6\times5000$ one.
Note $B$ has $\ell$ rows, not $k$. The truncation to $k$ happens later, at the pull-back step.
MCQYour matrix has a nearly flat singular-value spectrum ($\sigma_{k+1}/\sigma_k \approx 0.98$). Which change helps most?
- AIncrease the oversampling parameter $p$
- BApply $q$ steps of power iteration
- CDecrease $\ell$
- DUse a uniform instead of Gaussian $\Omega$
A flat spectrum is precisely the failure mode Davis–Kahan predicts: $\|QQ^\top - U_kU_k^\top\| \lesssim \sigma_{k+1}/\sigma_k \approx 0.98$, i.e. no guarantee at all. Power iteration replaces that ratio with $0.98^{2q+1}$ — with $q = 10$, $0.98^{21} = 0.65$. Oversampling (A) helps the probability of a good sketch but does nothing about an intrinsically indistinguishable spectrum.
MSQWhich statements about randomized SVD are correct?
- A$Q$ has orthonormal columns spanning approximately the top-$\ell$ left singular subspace.
- BThe sketch $Y = A\Omega$ takes random linear combinations of the rows of $A$.
- CTotal cost is $O(md\ell)$, better than the naive $O(md^2)$ since $\ell \ll d$.
- DSetting $p = 0$ still gives the stated $(1+\epsilon)$ guarantee.
B is false: $A\Omega$ combines columns — $A\omega = \sum_i \omega_i a_i$ where $a_i$ are columns. (Row combinations would be $\Omega^\top A$.)
D is false: $\epsilon = 6\sqrt{\frac{k+p}{p}\ln\frac2\delta}$ is undefined at $p=0$ — the bound diverges. Oversampling is structurally required, not a tuning nicety.
NATWith $q = 2$ power iterations, by what power is the gap ratio $\sigma_{k+1}/\sigma_k$ raised in the subspace bound?
$(AA^\top)^qA = U\Sigma^{2q+1}V^\top$, so the exponent is $2q+1 = 2(2)+1 = \mathbf{5}$.
Common slips: answering $2q = 4$, or $q = 2$. Remember the odd power comes from the trailing single $A$ — $q$ full "squarings" plus one.
Unit 05 · Week 5 L1–L3, Week 6 L1
Spectral clustering
k-means can only carve the plane into straight-edged convex cells. Two interlocking moons defeat it. The fix: rebuild the data as a graph, ask for a cheap cut, and discover that the answer is an eigenvector.
Why k-means fails
Lloyd's algorithm alternates two steps — centroid computation and cluster re-assignment — and the partition it produces is always a Voronoi diagram of the centroids. Every cell is therefore convex: for any two points in a cell, the whole segment between them stays in the cell.
A crescent is not convex — draw a segment between its two tips and it exits the shape. So a crescent can never be a k-means cell, no matter the initialisation, no matter how long you run it. Two moons, or a ring around a blob, are structurally out of reach. This is not a convergence problem; it is a representational one.
Note the deeper issue: on the two-moons data, the two facing tips of opposite moons are Euclidean-close while the two ends of the same moon are Euclidean-far. Raw distance is the wrong notion of similarity. What we want is connectedness — and that is a graph question.
Building the graph
One node per data point. Edge weights from the Gaussian (RBF) kernel:
$$w_{ij} = \exp\!\left(-\frac{\|x_i - x_j\|^2}{2\sigma^2}\right)$$with $\sigma$ a hyperparameter. Weight is inversely related to distance: nearby points get weight near $1$, far points near $0$ — but never exactly $0$, so this graph is fully dense. (The scalable alternative, used in Week 6: a $k$-NN graph.)
Degree matrix $D$ is diagonal with $D_{ii} = \sum_j w_{ij}$.
Cuts
A cut is just a subset $A \subseteq S$ of nodes. Its weight is the total weight of edges crossing to the other side:
$$\mathrm{cut}(A, S\setminus A) = \sum_{i \in A,\; j \in S\setminus A} w_{ij}$$Clustering becomes: cut the graph into two pieces so that as little weight as possible crosses. Points in different clusters should be far apart, hence joined by low weights, hence cheap to cut.
From cut to quadratic form
Encode the partition as a binary vector: $f_i = 1$ if $i \in A$, else $0$. Then
$$\mathrm{cut}(A, S\setminus A) = \sum_{i,j} f_i(1-f_j)w_{ij}$$Off-diagonal $L_{ij} = -w_{ij}$; diagonal $L_{ii} = \sum_j w_{ij}$. Every row sums to zero.
Summed over edges. If you instead sum over all ordered pairs $(i,j)$, each edge is counted twice and you need a $\tfrac12$: $\;f^\top Lf = \tfrac12\sum_{i,j}w_{ij}(f_i-f_j)^2$. Both forms appear in the course materials — check which indexing is in front of you.
Three facts fall straight out of this identity:
- $L$ is positive semi-definite — the right side is a sum of non-negative terms whenever $w_{ij} > 0$. So all eigenvalues are $\ge 0$.
- $\lambda_1 = 0$ with eigenvector $\mathbf{1}$ — plug $f = \mathbf 1$: every $(f_i - f_j) = 0$. Equivalently, $L\mathbf 1 = 0$ because each row sums to zero.
- It measures smoothness — $f^\top Lf$ is small when $f$ takes similar values at heavily connected pairs. The Laplacian penalises disagreement across strong edges.
Degrees: $\deg(1)=1$, $\deg(2)=3$, $\deg(3)=2$, $\deg(4)=2$, $\deg(5)=2$, $\deg(6)=2$. So $D = \mathrm{diag}(1,3,2,2,2,2)$ and
$$L = \begin{bmatrix} 1 & -1 & 0 & 0 & 0 & 0\\ -1 & 3 & 0 & -1 & 0 & -1\\ 0 & 0 & 2 & 0 & -1 & -1\\ 0 & -1 & 0 & 2 & -1 & 0\\ 0 & 0 & -1 & -1 & 2 & 0\\ 0 & -1 & -1 & 0 & 0 & 2 \end{bmatrix}$$Verify the cut for $A = \{1,2,4,5\}$, i.e. $f = (1,1,0,1,1,0)^\top$. Using the identity, only edges with differing endpoints contribute: $\{2,6\}$ gives $(1-0)^2 = 1$, $\{3,5\}$ gives $(0-1)^2 = 1$, all others give $0$. So $f^\top Lf = \mathbf{2}$ — matching the direct edge count. ✓
Now the problem: $A = \{1\}$ gives a cut of just $\mathbf{1}$, the smallest possible non-zero value. Plain mincut wants to peel off the single least-connected vertex. That is a useless clustering.
Killing the degenerate solutions
Written as an optimisation, $\min_{f\in\{0,1\}^n} f^\top Lf$ is broken twice over:
- $f = \mathbf 0$ and $f = \mathbf 1$ both give $0$ — "everything in one cluster", not a cut at all.
- Even excluding those, the binary problem is NP-hard.
The course's route (note: not RatioCut or Ncut — those are never introduced here) is to add two constraints and then relax:
- $\|f\|^2 = 1$ rules out the all-zeros solution and fixes the scale.
- $f^\top\mathbf 1 = 0$ forces $f$ orthogonal to the all-ones vector, ruling out the trivial $\mathbf 1$ direction.
- $f \in \mathbb{R}^n$ instead of $\{0,1\}^n$ is the relaxation — it turns an NP-hard combinatorial problem into an eigenvalue problem.
Order the eigenpairs of $L$ by eigenvalue: $(\lambda_1, f_1), (\lambda_2, f_2), \dots$ with $\lambda_1 = 0$ and $f_1 = \tfrac{1}{\sqrt n}\mathbf 1$. Then
$$\min_{\|f\|=1,\, f\perp\mathbf 1} f^\top Lf = \lambda_2, \qquad \arg\min = f_2$$$f_2$ — the eigenvector of the second-smallest eigenvalue — is the Fiedler vector.
Unconstrained, the minimiser of $f^\top Lf$ over unit vectors is the eigenvector of the smallest eigenvalue — which is $\mathbf 1$ at $\lambda_1 = 0$, the degenerate answer. The constraint $f \perp \mathbf 1$ deletes exactly that direction, so the minimum over what remains is the next eigenpair. The constraint and the "second smallest" are the same fact stated twice.
Recovering a clustering from the real-valued $f^\star$: threshold it (the professor suggests $0.5$), or run 1-D k-means on the values $\{f^\star_1,\dots,f^\star_n\}$.
More than two clusters
Take the first $k$ eigenvectors after the trivial one — $f_2, f_3, \dots, f_{k+1}$ — stack them as columns, and read off row $i$ as the embedding of point $x_i$:
$$x_i \;\longmapsto\; f_{x_i} = \big[f_{2,i}\;\; f_{3,i}\;\;\cdots\;\;f_{k+1,i}\big] \in \mathbb{R}^k, \qquad v_i = \frac{f_{x_i}}{\|f_{x_i}\|}$$$f_2$ is the single best way to split the graph in two. $f_3$ is the next-best split orthogonal to it, and so on. Stacking $k$ of them gives each point a $k$-dimensional signature summarising how it falls on each of the $k$ cheapest splits. Points in the same cluster agree across all views, so they land near each other.
Then row-normalise to the unit sphere and run k-means on the embeddings. Which raises the obvious question: why is k-means acceptable now, given we just spent a lecture on how it fails? Because the embedding is exactly the space where k-means' assumption finally holds — the two moons come out as two tight, well-separated, convex blobs. The spectral map does the hard part; k-means only has to finish.
- Build the similarity graph: $w_{ij} = e^{-\|x_i-x_j\|^2/2\sigma^2}$ (or $k$-NN).
- Form $D$ and $L = D - W$.
- Compute eigenvectors $f_1, \dots, f_{k+1}$ for the smallest eigenvalues; discard $f_1$.
- Stack $f_2,\dots,f_{k+1}$ as columns of an $n \times k$ matrix; each row is a point's embedding.
- Normalise each row to unit length.
- Run k-means on the $n$ embeddings.
Unit 06 · Week 6, Lectures 2–4
Spectral sparsification
The Gaussian similarity graph is dense — $\binom{n}{2}$ edges, all non-zero. At $n = 10^6$ that is $5\times10^{11}$ edges before you compute a single eigenvector. Throw most of them away, and reweight the survivors so the spectrum survives.
What must be preserved
The clustering came entirely from eigenvectors of $L$, so the thing to protect is the quadratic form. Here is why that is the same as protecting the spectrum: if $f$ is a unit eigenvector with eigenvalue $\lambda$, then
$$f^\top L f = f^\top(\lambda f) = \lambda\|f\|^2 = \lambda$$Preserve $f^\top Lf$ for all $f$ and you have preserved every eigenvalue — hence the whole spectral structure.
$H = (V, F, W')$ with $F \subseteq E$ is an $\epsilon$-spectral sparsifier of $G = (V,E,W)$ if for all $f \in \mathbb{R}^{|V|}$:
$$(1-\epsilon)\,f^\top L_G f \;\le\; f^\top L_H f \;\le\; (1+\epsilon)\,f^\top L_G f$$Same vertex set, a subset of the edges, and new weights. Note the structural echo of JL: a $(1\pm\epsilon)$ multiplicative sandwich that must hold for everything at once.
Sparsification by downsampling
- Keep each edge $(u,v) \in E$ independently with probability $p_{uv}$.
- If kept, reweight: $\;w'_{uv} = \dfrac{w_{uv}}{p_{uv}}$.
An edge kept with probability $p$ appears a fraction $p$ of the time; scaling its weight by $1/p$ makes its average contribution exactly right. The $p_{ij}$ and the $1/p_{ij}$ cancel identically.
Exam trap: this cancellation happens for any choice of $p_{ij} > 0$. Unbiasedness alone does not tell you how to sample. The clever choice of probabilities is entirely about variance — about making the estimate concentrate, not about making it correct on average. The professor states this explicitly.
Effective resistance — choosing the probabilities
Two pictures make the right notion obvious:
Edge inside a clique
In a near-complete graph on $n$ nodes, edge $(u,v)$ has $n-2$ alternative two-hop routes. Dropping it barely changes anything — it is redundant. Sample it rarely: $p \propto 1/n$.
A bridge between two cliques
Two cliques of 1000 nodes joined by one edge. Delete it and the graph disconnects — the spectrum changes qualitatively. It is irreplaceable. Sample it with $p \approx 1$.
The quantity that measures "how irreplaceable is this edge" is effective resistance — treat the graph as an electrical network where each edge is a resistor. An edge with many parallel paths has low effective resistance; a bridge has high.
where $L_G^\dagger$ is the Moore–Penrose pseudo-inverse (needed because $L$ is singular — $\lambda_1 = 0$) and $e_u - e_v$ is the vector with $+1$ at $u$, $-1$ at $v$, zeros elsewhere. With these probabilities, with high probability the result is an $\epsilon$-sparsifier with
$$|F| = O\!\left(\frac{|V|\log|V|}{\epsilon^2}\right) = O(n\log n)\ \text{edges}$$Down from $O(n^2)$ — a nearly linear-size graph.
Computing $R_{\mathrm{eff}}$ fast — JL comes back
Forming $L^\dagger$ densely is as expensive as the problem you were avoiding. But rewrite, using $L^\dagger L L^\dagger = L^\dagger$ and $L = U\Sigma U^\top$:
$$R_{\mathrm{eff}}(i,j) = e_{ij}^\top L^\dagger L L^\dagger e_{ij} = \big\|\Sigma^{1/2}U^\top L^\dagger e_{ij}\big\|^2 = \big\|\underbrace{\Sigma^{1/2}U^\top L^\dagger e_i}_{y_i} - \underbrace{\Sigma^{1/2}U^\top L^\dagger e_j}_{y_j}\big\|^2$$Effective resistance is a squared Euclidean distance between two vectors $y_i, y_j$. So Johnson–Lindenstrauss applies: project the $y$'s into $O(\log n/\epsilon^2)$ dimensions and every pairwise squared distance — hence every effective resistance — is preserved to within $(1\pm\epsilon)$. You never form $L^\dagger$ densely.
This is the course closing its own loop: the Week 1 lemma is what makes the Week 6 algorithm run.
- Build the similarity graph $G = (V,E,W)$ ($k$-NN, or the Gaussian kernel).
- Estimate $\hat R_{\mathrm{eff}}(i,j)$ for all edges, using the JL trick.
- Sample with $p_{ij} \propto \hat R_{\mathrm{eff}}(i,j)$, reweight $w'_{ij} = w_{ij}/p_{ij}$, giving $H$ with $O(n\log n/\epsilon^2)$ edges.
- Compute $L_H = D_H - W_H$.
- Use a sparse eigenvector solver for $f_1,\dots,f_k$ (this is why sparsity was worth buying).
- Stack, discard $f_1$, row-normalise to get embeddings.
- Run k-means.
Steps 1–3 are the scale-enabling preprocessing; steps 4–7 are spectral clustering as before.
Practice — Units 05 & 06
NATFor the six-node graph above (all weights $1$), what is $\mathrm{cut}(A, A^c)$ for $A = \{1,2\}$?
Edges leaving $\{1,2\}$: $\{2,6\}$ and $\{2,4\}$. The edge $\{1,2\}$ is internal and does not count. So the cut is $\mathbf{2}$.
Check with the quadratic form, $f = (1,1,0,0,0,0)$: contributions from $\{2,6\}$ and $\{2,4\}$ are $1$ each, everything else $0$. ✓
MSQWhich are true of the unnormalized Laplacian $L = D - W$ of a connected graph with positive weights?
- A$L$ is symmetric positive semi-definite.
- BThe smallest eigenvalue is $0$.
- C$L$ is invertible.
- DEvery row of $L$ sums to zero.
C is false, and it follows from B: a zero eigenvalue means $L$ is singular. This is exactly why the sparsification formula needs the pseudo-inverse $L^\dagger$ rather than $L^{-1}$.
D is the reason for B: $L\mathbf 1 = 0$ directly, since $L_{ii} = \sum_j w_{ij}$ and the off-diagonals are $-w_{ij}$.
MCQWhy is the constraint $f^\top\mathbf{1} = 0$ imposed in the relaxed mincut problem?
- ATo make the problem convex
- BTo exclude the trivial all-ones eigenvector at $\lambda_1 = 0$
- CTo ensure $L$ is positive semi-definite
- DTo normalise the embedding
Without it, the minimiser is $f = \tfrac{1}{\sqrt n}\mathbf 1$ with objective $0$ — "put everything in one cluster". Forcing orthogonality to $\mathbf 1$ deletes that direction and promotes the answer to $f_2$. C is a property of $L$ that holds regardless of any constraint.
MCQA dataset consists of two concentric rings. Which is the best description of what happens?
- ABoth k-means and spectral clustering succeed.
- Bk-means fails; spectral clustering succeeds because the rings are connected components in the similarity graph.
- CBoth fail because the rings are not linearly separable.
- Dk-means succeeds if initialised at the common centre.
A ring is not convex, so it can never be a Voronoi cell — k-means will slice both rings along a diameter regardless of initialisation. In the similarity graph, though, each ring is densely connected internally and weakly connected to the other, so the cheapest cut separates them, and the Fiedler vector finds it. Linear separability (C) is irrelevant: after the spectral embedding, the clusters become separable, which is precisely the point.
MSQIn the edge-sampling sparsifier, edge $(u,v)$ has $w_{uv} = 0.6$ and is retained with $p_{uv} = 0.2$. Which are true?
- AIts new weight is $3$.
- BIts new weight is $0.12$.
- C$\mathbb{E}[f^\top L_H f] = f^\top L_G f$ for this and any other choice of positive probabilities.
- DEffective-resistance probabilities are needed for unbiasedness.
$w' = w/p = 0.6/0.2 = \mathbf{3}$ — you divide by $p$, which makes surviving edges heavier, not lighter. B multiplies instead, and is the natural wrong answer.
D is false, and this is the key conceptual point: unbiasedness holds for any $p_{ij} > 0$, since the $p$ and $1/p$ cancel. Effective resistance is chosen to control variance — so the estimate concentrates and the $(1\pm\epsilon)$ guarantee holds w.h.p., with few enough edges.
MCQWhich edge should be sampled with the highest probability?
- AAn edge inside a dense clique of 500 nodes
- BThe single bridge connecting two large clusters
- CThe edge with the largest weight
- DAll edges should be sampled equally to preserve unbiasedness
The bridge has the highest effective resistance — no alternative path exists, so removing it disconnects the graph and destroys the spectrum. It must be kept with probability $\approx 1$. Clique-internal edges are redundant ($p \propto 1/n$). C is a distractor: high weight does not imply high effective resistance — a heavy edge buried in a clique is still replaceable. D is the trap from the previous question.
NATA dense similarity graph on $n = 10^6$ points has $\approx 5\times 10^{11}$ edges. Ignoring constants and the $1/\epsilon^2$ factor, roughly how many edges does the effective-resistance sparsifier keep? Give the exponent $t$ in $10^t$.
$|F| = O(n\log n) = 10^6 \times \log(10^6)$. With natural log, $\ln 10^6 \approx 13.8$, giving $\approx 1.4\times10^7$; with $\log_2$, $\approx 20$, giving $2\times10^7$. Either way the exponent is $t = \mathbf{7}$.
That is a reduction of roughly four orders of magnitude — from $5\times10^{11}$ to $\sim10^7$ — which is the difference between "impossible" and "runs on a laptop".
MCQWhy is the mincut problem over $f \in \{0,1\}^n$ described as NP-hard rather than merely "expensive"?
- ABecause $L$ is singular
- BBecause no polynomial-time algorithm is known for the constrained binary problem
- CBecause computing eigenvectors is slow
- DBecause the graph is dense
The professor is deliberate about this distinction. NP-hard = no polynomial algorithm known, a complexity-theoretic barrier — that describes the balanced binary cut problem. Computationally expensive = polynomial but slow, which is what dense eigen-decomposition (C, D) is, and what sparsification addresses. The relaxation attacks the first problem; sparsification attacks the second.
Reference
Formula cheat sheet
Everything examinable, on one screen. If you can reconstruct this page from memory, you are ready.
Concentration
| Name | Statement | Requires |
|---|---|---|
| Markov | $P(X \ge a) \le \dfrac{\mathbb{E}[X]}{a}$ | $X \ge 0$, $a > 0$ |
| Chebyshev | $P(|X-\mathbb{E}X| \ge k\sigma) \le \dfrac{1}{k^2}$ | finite mean and variance |
| Hoeffding | $P(\bar X - \mathbb{E}\bar X \ge t) \le e^{-2nt^2/(b-a)^2}$ | independent, $X_i \in [a,b]$ |
| Union bound | $P(\cup_i A_i) \le \sum_i P(A_i)$ | nothing |
| Subset | $A \subseteq B \Rightarrow P(A) \le P(B)$ | nothing |
Johnson–Lindenstrauss
- Cost to apply the map to a dataset: $O(ndk)$. Cost to project one query: $O(dk)$.
- $k$ is independent of $d$. Composing with any orthogonal $Q$ preserves the guarantee and the same $\epsilon$.
- Distance version: $\|f(x)-f(y)\| \le \sqrt{1+\epsilon}\,\|x-y\|$ — the lemma is on squared norms.
LSH
Always $\rho < 1$. $\theta = 1,2,3 \Rightarrow$ TPR $= 0.63, 0.86, 0.96$.
SVD & randomized SVD
Spectral clustering & sparsification
Complexity, all in one place
| Task | Naive | Fast / randomized |
|---|---|---|
| Apply JL map to $n$ points | — | $O(ndk)$ |
| Nearest-neighbour query | $O(nd)$ | JL: $O(dk+nk)$ · LSH: $O(n^\rho)$ |
| SVD of $A_{m\times d}$ | $O(md^2)$ | $O(md\ell)$, $\ell = k+p$ |
| Randomized SVD + $q$ power steps | — | $O(md\ell q)$ |
| Fast SVD given $Q$ (small SVD) | — | $O(dk^2)$ |
| Similarity-graph edges | $O(n^2)$ | $O(n\log n/\epsilon^2)$ after sparsification |
Reference
Traps & confusions
Compiled from the professor's own "students get this wrong" remarks and from the wrong options that actually appeared on past papers. Every entry below is a mark someone lost.
Markov bounds $P(X \ge a)$. If the question asks for $P(X \le a)$, you must take the complement, which flips the inequality direction: $P(X \le a) \ge 1 - \mathbb{E}[X]/a$. Both past papers had a Markov question and both required this step.
$P(|X-\mu| \ge k\sigma) \le 1/k^2$. Given an absolute threshold $t$, set $k = t/\sigma$ first. The bound is $\sigma^2/t^2$, never $1/t^2$.
$A^\top A$ is $d\times d$ and gives the right singular vectors $V$ (this is the PCA covariance). $AA^\top$ is $m\times m$ and gives the left singular vectors $U$ (this is the covariance of the sketch $A\omega$). Both have the same non-zero eigenvalues $\sigma_i^2$, so a wrong answer looks symmetric and plausible — check the diagonal, not the off-diagonal.
$\lambda_i(A^\top A) = \sigma_i^2$, so $\sigma_i = \sqrt{\lambda_i}$. A past paper handed over the eigenvalue $12$ as a decoy option when the singular value was $\sqrt{12}$. Take the square root.
$\|A - A_k\|_2 = \sigma_{k+1}$ — the first singular value you discard, not the last you keep. And $\|\cdot\|_2$ means spectral norm: only one value, not a root-sum-of-squares of the discarded tail (that would be Frobenius, which this course does not state).
$(1\pm\epsilon)$ multiplies $\|x-y\|^2$. If you want a bound on the distance itself, take a square root: $\|f(x)-f(y)\| \le \sqrt{1+\epsilon}\,\|x-y\|$. A past paper chose $\epsilon = 0.0201$ precisely so that $\sqrt{1+\epsilon} = 1.01$ exactly — a deliberate signal.
Stated three different ways across the two past papers. Any option where $k$ scales with the ambient dimension is wrong. Corollary: the ambient dimension is frequently a red herring in numeric questions — e.g. computing $\mathbb{E}\|Au\|^2$ for $R$ of shape $25\times10^4$ never uses the $10^4$.
$k$ (AND, hashes per table): pushes BOTH rates DOWN. Fixes FPR, damages TPR.
$L$ (OR, number of tables): pushes BOTH rates UP. Fixes TPR, damages FPR.
A past paper asked exactly this about $L$ and the correct answer was "TPR increases and FPR increases". Students who had memorised "more hashing = better filtering" chose the wrong pair.
Euclidean (Datar) buckets are parallel slabs — infinite stripes, convex, arbitrary random orientation. Cosine buckets are angular wedges through the origin. Concentric circles/squares are always wrong: they hash by norm, so antipodal points on the same ring collide. And a single linear hash can never produce a bounded closed region.
Buckets being convex means the whole segment between two colliding points also collides — but only $\beta \in [0,1]$. Extending to the full line ($\beta \in \mathbb{R}$) leaves the slab. A past paper turned exactly on that one word.
$w' = w/p$, so surviving edges get heavier. Multiplying ($w \cdot p$) is the natural wrong move.
$\mathbb{E}[f^\top L_H f] = f^\top L_G f$ holds for any positive sampling probabilities — the $p$ and $1/p$ cancel identically. Effective resistance is chosen for variance / concentration, so the $(1\pm\epsilon)$ bound holds w.h.p. with few edges. Zero expected error does not mean zero error.
$L = D - W$: diagonal is the weighted degree (sum of incident weights, not the count of neighbours); off-diagonal is $-w_{ij}$. Every row must sum to zero — use this to eliminate options instantly. A past paper offered $-W$ (zero diagonal) as a distractor; the row-sum test kills it in two seconds.
Careful with signs when a question asks for a difference of entries: $L_{11} - L_{42} = 15 - (-2) = 17$, not $13$.
$\mathrm{cut}(A, A^c)$ sums edges with one endpoint on each side. Internal edges do not count. For a singleton $A = \{v\}$, the cut is the weighted degree of $v$. And watch for constraints in the question ("among cuts with $|A| = 1$…") — a disconnected graph has a global mincut of $0$ that the constraint may forbid.
A weight-$10$ edge tempts you to "cut the expensive one". Backwards: the cheapest cut avoids crossing heavy edges, so its endpoints end up on the same side.
$(AA^\top)^q$ rescales directions already present in the sketch's span by positive scalars — which does not change the span. It improves accuracy (sharpens the spectrum, reduces the tail), never coverage. A zero-mark bonus question on a past paper turned entirely on this.
The professor separates these deliberately. The binary constrained mincut is NP-hard → fixed by relaxation to $f\in\mathbb{R}^n$. Dense eigendecomposition is merely expensive (polynomial) → fixed by sparsification. Different problems, different fixes.
No negative marking in either paper. On an MSQ that means a wrong tick costs you nothing extra, but an incomplete set does — several past MSQs had two or three correct options and selecting only the "obvious" one scored zero. When in doubt on an MSQ, evaluate every option independently rather than stopping at the first true one.
Numeric answers are often range-graded (e.g. 0.91 to 0.94), so carry a couple of extra decimal places rather than rounding early, and re-read whether the paper wants $\ln$ or $\log_2$.
Past papers
2025 T2 & T3, solved
Every question from both papers, with the answer key, the derivation, and the trap each wrong option was built to catch.
T2: 11 questions, 50 marks — 6 MCQ, 2 MSQ, 4 numeric. T3: 9 questions, 50 marks — 2 MCQ, 4 MSQ, 10 numeric (T3 leans much harder on comprehension blocks and numeric answers). Neither paper has negative marking.
Both source PDFs are truncated at 9 pages — T2 Q13 and T3 Q95 are absent from the files, and T2 Q12's last two options are cut off. Everything else is complete.
Where the marks actually are
| Topic | Questions | Marks (T2+T3) | What gets asked |
|---|---|---|---|
| JL / random projections | 5 | 21 | $k$ independent of $d$; $AA^\top$ covariance; $\mathbb{E}\|Mu\|^2 = \|u\|^2$; rotation invariance |
| Spectral clustering | 5 | 20 | Build $L = D-W$ for a small graph; compute cuts; find the mincut |
| SVD / randomized SVD | 7 | 18 | Eckart–Young; singular vs eigen values; sketch coverage; oversampling |
| LSH | 5 | 17 | Read the partition off a picture; effect of $L$; bucket convexity |
| Concentration inequalities | 2 | 8 | Always Markov, always with a complement step |
| Probability foundations | 1 | 4 | Venn diagram for $X \Rightarrow Y$ |
| Spectral sparsification | 1 | 3 | Only unbiasedness, $\mathbb{E}[L_H] = L_G$ |
The big four carry roughly 90% of both papers. Note what never appears despite being in the syllabus: Chebyshev and Hoeffding numerics, the Chernoff derivation, effective-resistance machinery. That is a reason to be efficient in revision — not a reason to skip them, since two papers is a small sample and the syllabus is the syllabus.
2025 T2
Q2 · MCQ · 4Markov$X$ is a random vector in $\mathbb{R}^d$ whose mean distance from the origin is $10$. Let $p$ be the probability that the distance of $X$ from the origin is at most $50$. Enter the tightest bound.
- A$p \ge 0.8$
- B$p \le 0.8$
- C$p \ge 0.2$
- D$p \le 0.2$
Let $Z = \|X\| \ge 0$ with $\mathbb{E}[Z] = 10$. Markov: $P(Z \ge 50) \le 10/50 = 0.2$. Complement: $p = P(Z \le 50) \ge 1 - 0.2 = \mathbf{0.8}$.
Traps: D is the raw Markov number without the complement. B has the complement but keeps the inequality direction — an upper bound on the tail is a lower bound on $p$. C is true but weaker, and the question says "tightest".
Q3 · MCQ · 4JLTwo datasets $D_1, D_2$ with the same number of points and $\epsilon = 0.01$, living in $\mathbb{R}^{d_1}$ and $\mathbb{R}^{d_2}$ with $d_1/d_2 = 1000$. Relation between $k_1$ and $k_2$?
- A$k_1 \ge 1000\,k_2$
- B$k_2 \ge 1000\,k_1$
- C$k_1$ can never equal $k_2$
- D$k_1$ and $k_2$ can be chosen equal
$k \in O(\log n/\epsilon^2)$ — no $d$. Same $n$, same $\epsilon$ ⟹ the same $k$ works for both.
Traps: A and B encode "a 1000× bigger space needs a 1000× bigger embedding" — exactly the intuition JL demolishes. The load-bearing phrase is "same number of data-points": that is the only quantity that matters.
Q4 · MCQ · 4ProbabilityWhich Venn diagram represents $X \Rightarrow Y$?
- ATwo disjoint circles
- B$Y$ nested inside $X$
- C$X$ nested inside $Y$
- DTwo overlapping circles
"Whenever $X$ occurs, $Y$ occurs" is set containment $X \subseteq Y$: the smaller event sits inside. Hence $P(X) \le P(Y)$ — the subset inequality used throughout the JL proof.
Trap: B is the reversed containment and is the most common error — the arrow in "$X \to Y$" makes it feel like $X$ should be the bigger, outer set. Implication shrinks the event.
Q5 · MCQ · 4Random matrices$A$ is a $10^4 \times 10^5$ matrix with i.i.d. standard normal entries. What does the histogram of its non-zero singular values look like?
- ASymmetric bell curve
- BFlat / uniform
- CU-shaped "bathtub"
- DA single narrow spike
The singular values of a Gaussian matrix concentrate in a narrow band — for aspect ratio $\beta = 10^4/10^5 = 0.1$ they lie roughly in $\sqrt N(1\pm\sqrt\beta) \approx [0.68, 1.32]\sqrt N$. Plotted from zero, that band is a spike.
This is the matrix-level restatement of JL: $\sigma_{\min} \approx \sigma_{\max}$ means the map is nearly a scaled isometry — the sphere goes to a nearly spherical ellipsoid. Same fact as the "$\sigma_i \approx \sqrt{d/k}$" line in the Week 2 linear-algebra lecture.
Trap: A is the reflex — "Gaussian entries, so Gaussian singular values". Singular values are a highly non-linear function of the entries.
Q6 · MCQ · 4Random projections$A = \begin{bmatrix}1&4\\3&1\end{bmatrix}$ and $\omega \sim \mathcal N(0, I_2)$. Find $\operatorname{Cov}(A\omega)$.
- A$\begin{bmatrix}17&7\\7&10\end{bmatrix}$
- B$\begin{bmatrix}10&7\\7&17\end{bmatrix}$
- C$\begin{bmatrix}1&16\\9&1\end{bmatrix}$
- D$I_2$
$\operatorname{Cov}(A\omega) = A\operatorname{Cov}(\omega)A^\top = AA^\top$. Row 1 of $A$ is $(1,4)$: $1+16 = 17$. Row 2 is $(3,1)$: $9+1 = 10$. Cross: $3+4 = 7$.
Trap: B is $A^\top A$ — same trace, same off-diagonal, only the diagonal order differs, so it survives a glance. This is the identity behind randomized SVD ($\operatorname{Cov}(A\omega) = AA^\top$, whose eigenvectors are the left singular vectors); getting it backwards breaks that whole story. C squares each entry.
Q7 · MSQ · 4LSH$h \sim \mathcal H_{w=2}$, a Datar family on $\mathbb{R}^2$. Which partitionings of $\mathbb{R}^2$ are possible?
- AEvenly spaced parallel diagonal lines
- BConcentric circles about the origin
- CDiagonal lines that bend around a closed ellipse
- DParallel diagonal lines, finer spacing
Level sets of $\lfloor(a^\top x + b)/w\rfloor$ are parallel slabs perpendicular to $a$, of equal width $w$. The direction of $a$ is random (any slope allowed) and $b$ shifts them, so both stripe pictures are realisable.
Traps: B is seductive — "Euclidean LSH, so round buckets" — but rings hash by norm: two antipodal points on the same ring collide despite being maximally far apart. C is half-right: a single linear projection can never carve out a bounded closed region. And since this is an MSQ, ticking only A scores zero.
Q8 · MSQ · 4LSHAn LSH uses $L$ tables of $k$ hashes each; collision if any table matches. Increasing $L$ with everything else fixed:
- ATPR increases
- BFPR increases
- CTPR decreases
- DFPR decreases
$P(p) = 1-(1-p^k)^L$ is strictly increasing in $L$ for every $p \in (0,1)$. So it lifts the rate for near pairs ($p \ge p_1$) and for far pairs ($p \le p_2$) at the same time. More tables buy recall and pay in precision, memory, and candidate-filtering time.
Trap: D comes from conflating $L$ with $k$. It is $k$ (the AND) that drives both rates down. Ticking only A also loses the marks — the point of the question is that both move the same way.
Q9 · NAT · 5JL$n$ points in $\mathbb{R}^d$, all on the unit hypersphere. With $\epsilon = 0.0201$ and a suitable $k$, find an upper bound for the distance between any two points in $\mathbb{R}^k$. Two decimal places.
Step 1 — diameter upstairs. For $x,y$ on the unit sphere, the triangle inequality through the origin gives $\|x-y\| \le \|x\| + \|y\| = 2$.
Step 2 — apply JL, then square-root. $\|f(x)-f(y)\|^2 \le (1+\epsilon)\|x-y\|^2$, so
$$\|f(x)-f(y)\| \le \sqrt{1.0201}\times 2 = 1.01 \times 2 = \mathbf{2.02}$$Traps: (i) Using diameter $1$ instead of $2$ — the points lie on the unit sphere, so the farthest pair is antipodal. (ii) Multiplying the distance by $(1+\epsilon)$ instead of $\sqrt{1+\epsilon}$, giving $2.0402$. The value $\epsilon = 0.0201$ is engineered so $\sqrt{1+\epsilon} = 1.01$ exactly — that is the examiner telling you to take a square root.
Q10 · NAT · 4SVD$A$ has non-zero singular values $50, 20, 10, 1, 0.01, 0.001$. If $B$ is the best rank-4 approximation, compute $\|A-B\|_2$.
Eckart–Young: $\|A - A_k\|_2 = \sigma_{k+1}$. With $k=4$, that is $\sigma_5 = \mathbf{0.01}$.
Traps: $\sigma_4 = 1$ (off-by-one — the error is the first value discarded). Or the Frobenius answer $\sqrt{0.01^2 + 0.001^2} \approx 0.01005$ — the subscript $2$ means spectral norm, so only the largest discarded value counts. The tiny $\sigma_6 = 0.001$ exists purely to make that mistake feel reasonable.
Q11 · NAT · 4CutsComprehension: two disjoint triangles $\{1,2,3\}$ and $\{4,5,6\}$, each with edge weights $1$ (top), $2$ (left), $3$ (right); no edges between them. Among all cuts with $|A| = 1$, find the smallest cut weight.
For a singleton, the cut equals the weighted degree. Degrees: $d_1 = 1+2 = 3$, $d_2 = 1+3 = 4$, $d_3 = 2+3 = 5$, and identically $3, 4, 5$ for vertices $4,5,6$. Minimum is $\mathbf{3}$ at $A = \{1\}$ or $\{4\}$.
Trap: The graph is deliberately disconnected, so the global mincut really is $0$ (take $A = \{1,2,3\}$). The constraint $|A| = 1$ forbids that. Reading past the cardinality constraint is the entire trap. Secondary slip: answering $1$, the smallest single edge weight, instead of summing all edges at the vertex.
Q12 · MCQ · 4LaplacianFind the Laplacian $L$ of the same two-triangle graph.
Diagonal = weighted degrees $(3,4,5,3,4,5)$; off-diagonal $= -w_{ij}$; zeros across the blocks because the components are disconnected. Since there are two components, $\lambda = 0$ has multiplicity $2$.
Trap: The distractor is $-W$ — right off-diagonals, right sparsity, but a zero diagonal. Kill it with the row-sum test: every row of a Laplacian sums to $0$; in $-W$ every row sums to a negative number. (The source PDF is truncated here, so options C and D are not recoverable.)
2025 T3
Q80 · MSQ · 4JL$M \in \mathbb{R}^{k\times d}$ is an approximate isometry per JL, and $Q$ is a $k\times k$ orthogonal matrix. Which are true?
- A$QM$ is an approximate isometry
- B$Q^\top M$ is an approximate isometry
- CExactly one of them is
- DNeither is
For square orthogonal $Q$, $\|Qv\|^2 = v^\top Q^\top Q v = \|v\|^2$ — an exact isometry on $\mathbb{R}^k$. So $\|QMx\| = \|Mx\|$ and $QM$ inherits the identical $\epsilon$. And $Q$ orthogonal ⟹ $Q^\top = Q^{-1}$ is orthogonal too, so the same argument gives B.
Trap: C targets students half-remembering "$Q^\top Q = I$ but $QQ^\top \ne I$". That caveat is for rectangular matrices with orthonormal columns. Here $Q$ is explicitly square, so both products are $I$ and A and B stand or fall together — which makes C self-defeating.
Q81 · MSQ · 3LSH$x_1, x_2$ collide under $g$ (a $k$-fold AND of Datar hashes) and $x_3 = \lambda x_1 + (1-\lambda)x_2$ for some $\lambda \in (0,1)$. Select all that apply.
- A$x_3$ collides with $x_1$
- B$x_3$ collides with $\beta x_1 + (1-\beta)x_2$ for all $\beta \in \mathbb{R}$
- C$x_3 + (1-\lambda)x_1 + \lambda x_2$ collides with $x_1 + x_2$
- D$x_3 - \tfrac\lambda2 x_1 + \tfrac\lambda2 x_2$ collides with both $x_1$ and $x_2$
The structural fact: each hash's level set is a slab (convex), so a bucket of $g$ is an intersection of $k$ slabs — also convex. If $x_1, x_2$ share a bucket, the whole segment between them does.
A: $x_3$ is a convex combination, so it's on the segment. ✓
C: pure algebra — $x_3 + (1-\lambda)x_1 + \lambda x_2 = \lambda x_1 + (1-\lambda)x_2 + (1-\lambda)x_1 + \lambda x_2 = x_1 + x_2$. It is literally the same point, so it trivially collides with itself. Expand before you think geometrically.
D: $= \tfrac\lambda2 x_1 + (1-\tfrac\lambda2)x_2$, a convex combination with $\mu = \lambda/2 \in (0,\tfrac12)$. ✓
Trap — B, and it is one word: $\forall \beta \in \mathbb{R}$. Convexity protects $\beta \in [0,1]$ only. Outside that you are on the line's extension, which walks out of the slab. Convex hull, not affine hull.
Q82 · NAT · 4Markov$X, Y \ge 0$ with $\mathbb{E}[X] = 10$, $\mathbb{E}[Y] = 20$. If $Z = X+Y$ and $P(Z \ge 60) \le b$, find the tightest $b$ with the available information. One decimal place.
$Z \ge 0$, and by linearity of expectation (which needs no independence) $\mathbb{E}[Z] = 30$. Markov: $P(Z \ge 60) \le 30/60 = \mathbf{0.5}$.
Trap: "with the available information" is load-bearing. No variance, no independence ⟹ Chebyshev and Hoeffding are unavailable and $0.5$ genuinely is the tightest derivable bound. Splitting into $P(X\ge20) + P(Y\ge40) \le 1$ via the union bound is legal but strictly weaker.
Q83 · NAT · 4JL$R$ is $25 \times 10000$ with standard normal entries, $u \in \mathbb{R}^{10000}$ with $\|u\| = 10$, and $A = R/5$. Find $\mathbb{E}\big[\|Au\|^2\big]$.
Each row satisfies $r_i^\top u \sim \mathcal N(0, \|u\|^2)$, so $\mathbb{E}[(r_i^\top u)^2] = \|u\|^2 = 100$. Over $k = 25$ rows: $\mathbb{E}\|Ru\|^2 = 25 \times 100 = 2500$. Then $A = R/5$ scales the squared norm by $1/25$:
$$\mathbb{E}\big[\|Au\|^2\big] = \frac{2500}{25} = \mathbf{100} = \|u\|^2$$Note $5 = \sqrt{25} = \sqrt k$ — this is $M = R/\sqrt k$, and the answer coming out as exactly $\|u\|^2$ is the unbiasedness result, not a coincidence.
Traps: forgetting the scaling ($2500$); dividing by $5$ once instead of $25$ ($500$) — the scalar squares inside $\|\cdot\|^2$. The ambient $10000$ is a pure red herring, which is itself the JL punchline.
Q84 · NAT · 3Sparsification$H$ sparsifies $G$: edge $(u,v)$ retained with probability $p_{uv}$ and reweighted $W'[uv] = W[uv]/p_{uv}$. Find $\mathbb{E}\big[f^\top(L_H - L_G)f\big]$.
With $X_{uv} \sim \mathrm{Bernoulli}(p_{uv})$ indicating retention,
$$\mathbb{E}\big[f^\top L_Hf\big] = \sum_{(u,v)\in E} p_{uv}\cdot\frac{w_{uv}}{p_{uv}}(f_u-f_v)^2 = f^\top L_Gf$$so the difference has expectation $\mathbf{0}$, for every fixed $f$.
Trap: grinding out algebra expecting an $f$-dependent mess — the whole design of the $1/p$ reweighting is to make this identically zero. Deeper trap: unbiasedness holds for any $p_{uv} > 0$. Effective resistance buys concentration, not correctness-on-average. Zero expected error is not zero error.
Q85–86 · MCQ · 3+3LSHFour partitions of $\mathbb{R}^2$: (A) concentric tilted ellipses, (B) ~8 lines through the origin making wedges, (C) evenly spaced parallel diagonal strips, (D) concentric axis-aligned squares. Q85: which one means "same bucket ⟹ close in Euclidean distance"? Q86: which one means "same bucket ⟹ high cosine similarity"?
Q85 → C. Euclidean (Datar) LSH buckets are parallel slabs of width $w$ perpendicular to a random direction. Two points in the same slab differ by at most $w$ along that direction; ANDing $k$ of them bounds the separation in $k$ random directions, hence the Euclidean distance w.h.p.
Q86 → B. Cosine similarity depends only on the angle and is scale-invariant, so its buckets must be cones through the origin — exactly what lines through the origin produce (SimHash: $h_a(x) = \mathrm{sign}(a^\top x)$, collision probability $1-\theta/\pi$).
Traps: A and D bucket by norm — antipodal points on the same ring always collide, which is anti-locality-sensitive; and no single linear hash can produce a bounded region. The paired structure is deliberate: answering both with the same partition guarantees losing one. Discriminator: is the similarity scale-invariant? Cosine yes → wedges. Euclidean no → stripes.
Q87–91 · Comprehension · 3+3+3+1+0Randomized SVD$\{v_1,\dots,v_5\}$ orthonormal in $\mathbb{R}^{10}$. Dataset $\mathcal D$ repeats $v_j$ exactly $i_j$ times with $(i_1,\dots,i_5) = (12,9,2,1,1)$; $D$ is the $n\times d$ data matrix. Q87 find $n$. Q88 which of $0, 1, 3, 12$ are singular values of $D$? Q89 $W$ is $n\times\ell$ with 0/1 entries, each column summing to 1; $Z_\ell = D^\top W$. For $k=1, p=0$, find $\Pr[\mathrm{span}(e_1) \subseteq \mathrm{span}(Z_\ell)]$. Q90 same with $p=3$. Q91 after one power step $Z^{(2)} = D^\top D Z^{(1)}$?
Setup. Using the paper's hint $D^\top D = \sum_j i_j v_jv_j^\top$. Since the $v_j$ are orthonormal this is the spectral decomposition: eigenvalues $12, 9, 2, 1, 1$ plus $0$ with multiplicity $d - 5 = 5$.
Q87 → 25. $n = 12+9+2+1+1$. Note $n = 25$, $d = 10$, $\mathrm{rank} = 5$ are three different numbers, each used in a different sub-question.
Q88 → A, B, C ($0$, $1$, $3$). Singular values are square roots: $\sqrt{12}\approx3.46$, $\sqrt9 = 3$, $\sqrt2$, $1$, $1$, and $0$ (five times, since $d > \mathrm{rank}$). $12$ is an eigenvalue of $D^\top D$, not a singular value of $D$ — the multiplicities are handed to you looking like an answer list. Also easy to miss $0$.
Q89 → 0.48. Decode $W$ first: a 0/1 column summing to $1$ is a random standard basis vector, so $D^\top\varepsilon_t$ is the $t$-th row of $D$ — one uniformly sampled data point. This is a sampling sketch, not a Gaussian one. With $\ell=1$, $\mathrm{span}(Z_\ell)$ is a single line, and since the $v_j$ are orthonormal it contains $v_1$ iff the sampled point is $v_1$: $12/25 = \mathbf{0.48}$.
Q90 → 0.93. $\ell = k+p = 4$ draws; $v_1$ is captured iff at least one hits: $1 - 0.52^4 = \mathbf{0.9269}$. Three extra columns take failure from $52\%$ to $7\%$ — the whole argument for oversampling, in one number.
Q91 → 0.93, unchanged. $Z^{(2)} = (D^\top D)Z^{(1)}$ multiplies each sampled column $v_j$ by the positive scalar $i_j$, which does not change the span. Power iteration improves accuracy, never coverage — if no draw was $v_1$, nothing conjures it.
Traps: answering $1$ on Q89 by reading $W$ as Gaussian; answering $0.2$ by sampling uniformly over the 5 directions instead of the 25 points (the multiplicities are the sampling weights — this is why leverage-score sampling exists); $4 \times 0.48 = 1.92 > 1$ on Q90; and expecting Q91 to go up.
Q92–94 · Comprehension · 4+4+4Spectral clusteringWeighted graph on $V = \{1,2,3,4\}$: $w_{12}=3$, $w_{13}=2$, $w_{14}=10$, $w_{24}=2$, $w_{34}=1$, no edge $2$–$3$. Q92 $\mathrm{cut}(\{1,2,3\}, \{4\})$? Q93 which vertices are in $A^*$, the set with the smallest non-zero cut? Q94 $L_{11} - L_{42}$?
Weighted degrees: $d_1 = 3+2+10 = 15$, $d_2 = 3+2 = 5$, $d_3 = 2+1 = 3$, $d_4 = 10+2+1 = 13$.
Q92 → 13. $V\setminus A = \{4\}$, so the cut is just $d_4 = 10+2+1 = \mathbf{13}$. Trap: summing the edges inside $A$ ($3+2+0 = 5$), or missing $w_{34}=1$ (drawn as a long curved arc along the bottom — that layout is deliberate).
Q93 → A, B, D, i.e. $A^* = \{1,2,4\}$. Enumerate: $\mathrm{cut}\{1\} = 15$, $\{2\} = 5$, $\{3\} = 3$, $\{4\} = 13$, $\{1,2\} = 14$, $\{1,3\} = 14$, $\{1,4\} = 8$. The smallest non-zero value is $\mathbf{3}$, achieved by the complementary pair $\{3\}$ and $\{1,2,4\}$; the key commits to the large side. Vertex 3 is the loosely-attached one, so peeling it off is cheapest — exactly what the Fiedler vector would find.
Careful: $\{3\}$ and $\{1,2,4\}$ have identical cut value, so this MSQ is genuinely ambiguous. Reasoning toward the singleton makes you tick only C and score zero. Heuristic: when three of four membership options are true, the large side is intended. Also note "non-zero" — without it, $A = \emptyset$ gives $0$ and the question is degenerate.
Q94 → 17. $L_{11} = d_1 = 15$ and $L_{42} = -w_{42} = -2$, so $15 - (-2) = \mathbf{17}$. The double negative is the whole point of asking for a difference. Secondary traps: using the unweighted degree $3$ for $L_{11}$; and indexing — the paper says "indices start from one" for a reason.
Practice
Mixed practice bank
Twenty questions in random topic order, written in the style of the real papers — including the deliberately ambiguous phrasings and the plausible-looking wrong options. Do these cold, on paper, before checking.
Give yourself 45 minutes for all twenty. Anything you cannot start within 90 seconds, flag and move on — that flagged list is your revision plan.
01 · NATThe waiting time $T$ at a service desk is non-negative with $\mathbb{E}[T] = 4$ minutes. What is the tightest lower bound you can state for $P(T < 25)$? Two decimals.
Markov: $P(T \ge 25) \le 4/25 = 0.16$. Complement: $P(T < 25) \ge 1 - 0.16 = \mathbf{0.84}$.
The complement step is the recurring archetype — it appeared in both past papers.
02 · MSQ$M = R/\sqrt k$ is a JL map from $\mathbb{R}^d \to \mathbb{R}^k$. Which quantities does the required $k$ depend on?
- A$n$, the number of points
- B$d$, the ambient dimension
- C$\epsilon$, the distortion
- D$\delta$, the failure probability
$k \ge \frac{8}{\epsilon^2}\log\frac{2n^2}{\delta}$ involves $n$, $\epsilon$ and $\delta$ — never $d$. $\delta$ counts because it sits inside the log, even though its influence is weak.
If you ticked only A and C you would score zero on an MSQ. Read the full bound, not just the $O(\log n/\epsilon^2)$ headline.
03 · MCQAn LSH family is $(1, 4, 0.9, 0.1)$-sensitive. Two points are $3.5$ apart. What is guaranteed?
- ACollision probability $\ge 0.9$
- BCollision probability $\le 0.1$
- CNothing is guaranteed
- DCollision probability is exactly $0.5$
$r = 1$, $cr = 4\times1 = 4$. Distance $3.5$ satisfies neither $\le 1$ nor $\ge 4$ — it lies in the annulus $(1,4)$, where the definition asserts nothing. Always compute $cr$; never compare against $c$ alone.
04 · NAT$A$ is $6\times4$ with singular values $9, 4, 2, 0$. What is $\mathrm{rank}(A)$, and what is $\|A - A_2\|_2$? Give the product of the two answers.
$\mathrm{rank}(A) = $ number of non-zero singular values $= 3$. And $\|A - A_2\|_2 = \sigma_3 = 2$. Product $= 3 \times 2 = \mathbf 6$.
Trap on the rank: it is not $\min(6,4) = 4$, because $\sigma_4 = 0$.
05 · NATA path graph on 4 vertices: edges $1$–$2$, $2$–$3$, $3$–$4$, all weight $1$. Compute $L_{22} + L_{13}$.
$\deg(2) = 2$ so $L_{22} = 2$. Vertices $1$ and $3$ are not adjacent, so $w_{13} = 0$ and $L_{13} = -0 = \mathbf{0}$. Sum $= \mathbf{2}$.
For reference, $L = \begin{bmatrix}1&-1&0&0\\-1&2&-1&0\\0&-1&2&-1\\0&0&-1&1\end{bmatrix}$ — check each row sums to zero.
06 · MCQ$X_1,\dots,X_n$ are i.i.d. with $X_i \in [2, 6]$. To bound $P(\bar X - \mathbb{E}\bar X \ge 0.5)$ by Hoeffding, what is the exponent?
- A$-2n(0.5)^2/16$
- B$-2n(0.5)^2/4$
- C$-2n(0.5)^2/36$
- D$-2n(0.5)^2$
$(b-a)^2 = (6-2)^2 = 16$. So the bound is $e^{-2n(0.25)/16} = e^{-n/32}$.
Traps: B uses $b-a = 2$ (the lower endpoint, not the range); C uses $b^2 = 36$; D silently assumes $[0,1]$. The range matters, not the endpoints individually — the bound is invariant to shifting the interval.
07 · MSQRandomized SVD is run on $A \in \mathbb{R}^{m\times d}$ with $\ell = k+p$. Which are correct?
- A$Q$ has shape $m \times \ell$.
- BThe exact SVD is computed on a matrix of shape $\ell \times d$.
- C$\hat U = Q\tilde U_k$ has shape $m \times k$.
- D$\Omega$ has shape $m \times \ell$.
D is false: $\Omega$ is $d \times \ell$, so that $Y = A\Omega$ works dimensionally ($m\times d$ times $d\times\ell$). Getting $\Omega$'s orientation wrong breaks the whole pipeline, and it's the easiest shape to invert mentally.
Shape chain to memorise: $\Omega_{d\times\ell} \to Y_{m\times\ell} \to Q_{m\times\ell} \to B_{\ell\times d} \to \hat U_{m\times k}$.
08 · NATAn LSH scheme has $p_1 = 0.5$, $p_2 = 0.25$, $n = 2^{20}$. Using $k = \log n/\log(1/p_2)$, find $k$.
Base-2 throughout: $\log_2 n = 20$, $\log_2(1/0.25) = \log_2 4 = 2$. So $k = 20/2 = \mathbf{10}$.
Check: $n p_2^k = 2^{20} \times 4^{-10} = 2^{20}/2^{20} = 1$. ✓ Bonus: $\rho = \log(1/0.5)/\log(1/0.25) = 1/2$, so $L = \theta n^{0.5} = \theta \cdot 1024$.
09 · MCQWhich is the correct order of steps in spectral clustering?
- Ak-means → build graph → eigenvectors → normalise
- BBuild graph → $L = D-W$ → eigenvectors (drop $f_1$) → normalise rows → k-means
- CBuild graph → $L = D-W$ → eigenvectors (keep $f_1$) → k-means → normalise
- D$L = D-W$ → k-means → eigenvectors → build graph
Two details separate B from C: $f_1$ is discarded (it is the constant vector at $\lambda_1 = 0$ and carries no clustering information), and normalisation comes before k-means, not after — the point of projecting the embeddings onto the unit sphere is to make k-means' job easy.
10 · NATSparsifying a graph, edge $e$ has weight $8$ and is retained with probability $0.25$. If retained, what is its new weight? And what is the expected contribution of $e$ to $f^\top L_Hf$ if $(f_u - f_v)^2 = 3$?
$w' = 8/0.25 = \mathbf{32}$. Expected contribution $= p \cdot w' \cdot (f_u-f_v)^2 = 0.25 \times 32 \times 3 = \mathbf{24}$, which equals $w \cdot (f_u-f_v)^2 = 8 \times 3 = 24$. ✓ Unbiased, as designed.
Note the variance is enormous here: the contribution is $96$ a quarter of the time and $0$ otherwise. That is exactly why the choice of $p$ matters — it controls variance, not the mean.
11 · MSQWhich are valid reasons to prefer randomized SVD over exact SVD?
- ACost drops from $O(md^2)$ to $O(md\ell)$.
- BIt gives the exact top-$k$ singular vectors.
- CIt works well when the spectrum decays quickly.
- DOnly $\ell = k+p$ passes over the data are needed rather than a full factorisation.
B is false — the output is an approximation, guaranteed only to be within $(1+\epsilon)\sigma_{k+1}$ with probability $\ge 1-\delta$. Exactness is precisely what you trade away.
C is the real precondition: if the spectrum is flat, $\sigma_{k+1}/\sigma_k \approx 1$ and the subspace bound is vacuous — you then need power iteration.
12 · MCQWhich is the tightest statement you can make about a random variable $X$ with $\mathbb{E}[X]=0$ and $\mathrm{Var}(X)=9$, regarding $P(X \ge 12)$?
- A$\le 1/16$ by Chebyshev
- B$\le 0$ by Markov
- C$\le e^{-8}$ by Hoeffding
- DCannot bound it at all
$\sigma = 3$, so $12 = 4\sigma$ and Chebyshev gives $P(|X| \ge 12) \le 1/16$, hence $P(X \ge 12) \le 1/16$ too.
B is wrong because Markov needs $X \ge 0$, and a mean-zero non-degenerate variable is not non-negative. C is wrong because Hoeffding needs many independent bounded variables — you have one variable of unknown range. This question is really asking: which hypotheses do you actually have?
13 · NATTriangle graph on $\{1,2,3\}$ with $w_{12} = 5$, $w_{13} = 1$, $w_{23} = 1$. Find the smallest non-zero cut value.
Singleton cuts are the weighted degrees: $d_1 = 5+1 = 6$, $d_2 = 5+1 = 6$, $d_3 = 1+1 = \mathbf 2$. On three vertices every non-trivial cut is a singleton (or its complement), so the minimum is $\mathbf 2$, at $A = \{3\}$.
Note where the heavy edge ends up: the mincut keeps $1$ and $2$ together precisely because $w_{12} = 5$ is expensive to cross.
14 · MCQIn the JL proof, the Chernoff step applies Markov's inequality to which quantity?
- A$\|x\|^2$ directly
- B$e^{\lambda\|x\|^2}$ for a free parameter $\lambda > 0$
- C$\|x\|$
- D$\log\|x\|^2$
Exponentiating first is what turns Markov's weak $1/a$ decay into exponential decay: the free $\lambda$ can then be optimised, giving $\lambda = \epsilon/4$ and the bound $e^{-k\epsilon^2/8}$. Applying Markov to $\|x\|^2$ directly (A) gives only $1/(1+\epsilon)$ — useless.
The MGF of each $x_i^2 \sim \chi^2_1$ is $(1-2\lambda)^{-1/2}$, and independence lets you take the product over the $k$ coordinates.
15 · NATWith $p_1 = 0.8$, $p_2 = 0.2$, $n = 10^6$ and $\theta = 3$: find $\rho$ to two decimals, then $L$ to the nearest integer.
$\rho = \dfrac{\ln(1/0.8)}{\ln(1/0.2)} = \dfrac{0.2231}{1.6094} = \mathbf{0.1386} \approx 0.14$.
$L = \theta n^\rho = 3 \times (10^6)^{0.1386} = 3 \times 10^{0.8316} = 3 \times 6.78 \approx \mathbf{20}$.
Sanity: $\theta = 3$ ⟹ TPR $= 1 - e^{-3} = 0.95$. Twenty tables gives 95% recall on a million points — that is the headline result of the whole unit.
16 · MSQWhich are true of the Fiedler vector $f_2$?
- AIt is orthogonal to the all-ones vector.
- BIt minimises $f^\top Lf$ among unit vectors orthogonal to $\mathbf 1$.
- CIts entries are all in $\{0,1\}$.
- DIts eigenvalue $\lambda_2$ equals the minimum value of the relaxed objective.
C is false and is the crux of the relaxation: we abandoned $\{0,1\}^n$ (NP-hard) for $\mathbb{R}^n$. The entries are arbitrary reals, which is exactly why a thresholding or 1-D k-means step is needed afterwards to recover a discrete partition.
A and D restate each other: orthogonality to $\mathbf 1$ deletes the trivial $\lambda_1 = 0$ direction, so the constrained minimum is $\lambda_2$.
17 · MCQA JL map with $\epsilon = 0.04$ is applied to points on a sphere of radius $5$. What is the tightest upper bound on the distance between two images?
- A$10.2$
- B$10.4$
- C$5.1$
- D$10.0$
Diameter upstairs is $2\times 5 = 10$. JL is on squared distances, so the multiplier on the distance is $\sqrt{1+\epsilon} = \sqrt{1.04} = 1.0198$. Bound $= 10 \times 1.0198 = \mathbf{10.198} \approx 10.2$.
B is $(1+\epsilon)\times10$ — forgetting the square root. C uses the radius instead of the diameter. This is the T2 Q9 archetype with different numbers.
18 · NATRandomized SVD with $k=10$, $p=5$, $\delta = 0.01$. Compute $\epsilon = 6\sqrt{\frac{k+p}{p}\ln\frac2\delta}$ to one decimal, and state the resulting bound as a multiple of $\sigma_{11}$.
$\dfrac{k+p}{p} = \dfrac{15}{5} = 3$ and $\ln\dfrac{2}{0.01} = \ln 200 = 5.298$. So
$$\epsilon = 6\sqrt{3 \times 5.298} = 6\sqrt{15.894} = 6 \times 3.987 = \mathbf{23.9}$$and $\|A - QQ^\top A\|_2 \le (1+\epsilon)\sigma_{11} \approx \mathbf{24.9\,\sigma_{11}}$.
The lesson is the constant, not the arithmetic: this theoretical bound is wildly pessimistic — a factor of ~25 rather than the ~2 the professor's illustrative $\epsilon = 1$ suggests. In practice randomized SVD performs far better than this worst-case guarantee. Exam-wise, know the form of $\epsilon$ (how $p$ and $\delta$ enter) rather than trusting a memorised number.
19 · MSQWhich failures of k-means does spectral clustering fix, and how?
- ANon-convex clusters — because the graph captures connectivity, not straight-line distance.
- BThe need to specify the number of clusters $k$.
- CConcentric rings — each ring is densely connected internally, weakly to the other.
- DThe two-moons dataset, where the closest pair of points spans the two clusters.
B is false: spectral clustering still needs $k$ — you choose how many eigenvectors to keep, and you still run k-means at the end. It fixes the shape limitation, not the model-selection problem.
All of A, C, D are the same fact in three costumes: Euclidean proximity is the wrong similarity; graph connectivity is the right one.
20 · MCQWhich chain correctly traces how randomness is used across the whole course?
- ARandom matrix → preserves distances (JL) → random hash → sub-linear NN (LSH) → random sketch → fast SVD → random edge sample → sparse graph
- BRandom sampling → exact answers everywhere
- CRandomness reduces memory but never affects running time
- DRandomness is only used in JL
That is the course in one line, and the same three-beat pattern each time: exact is too expensive → randomize → concentrate. The concentration inequalities of Week 1 are the shared engine; the union bound is what upgrades a per-item guarantee into an all-items-at-once guarantee.
And the loop closes: JL (Week 1) is the tool used to compute effective resistances quickly (Week 6), which is what makes sparsification — and hence spectral clustering at scale — practical.
The last thirty minutes
Night-before checklist
If you can answer these out loud without looking, close the laptop.
Concentration
State all three bounds with their hypotheses. Which needs non-negativity? Which needs independence? Which is two-sided? Convert an absolute threshold into $\sigma$-units. Take a complement.
JL
Why no exact isometry when $k < d$. Write $M = R/\sqrt k$ and say where the $\sqrt k$ comes from. State $k \ge \frac{8}{\epsilon^2}\log\frac{2n^2}{\delta}$. Why the union bound and not $1-(1-p)^m$. Squared vs unsquared distances.
LSH
Both inequalities in the right direction. The Datar hash and $\Delta \sim \mathcal N(0,\|x-y\|^2)$. AND lowers both rates, OR raises both. Derive $k$, $\rho$, $L$. Know $\rho < 1$ and why that gives sub-linearity.
SVD
$A^\top A \to V$, $AA^\top \to U$, eigenvalues $= \sigma^2$. Eckart–Young gives $\sigma_{k+1}$. The six-step algorithm with every shape. Why $p > 0$. What power iteration does and does not fix.
Spectral clustering
Why k-means cannot do crescents. Derive $L = D-W$ from the cut. The $f^\top Lf$ identity. Why $\lambda_1 = 0$ is useless and $f_2$ is the answer. The full seven-step scaled algorithm.
Sparsification
The $(1\pm\epsilon)$ quadratic-form condition. $w' = w/p$ and the cancellation. Unbiased for any $p$ — effective resistance is about variance. $O(n\log n/\epsilon^2)$ edges.
- Compute $cr$, not $c$. Every LSH regime question turns on which side of $r$ / $cr$ the distance falls — and on remembering the annulus guarantees nothing.
- Row-sum test every Laplacian. Two seconds, eliminates whole options.
- Ask "squared or not?" JL is on squared distances; Eckart–Young is on the spectral norm; Chebyshev is in $\sigma$-units.
- On MSQs, evaluate every option. No negative marking, but under-selecting scores zero. Several past MSQs had three correct options.
- Write the shapes down. For any SVD question, write $m\times d$, $d\times\ell$, $m\times\ell$, $\ell\times d$ in the margin before touching the algebra.
Every algorithm in this course is the same move. The exact computation is too expensive, so you replace it with a random one that is right in expectation, then use a tail bound to show it is right with high probability, and a union bound to make that hold for everything at once. Markov, Chebyshev, Hoeffding and the union bound are not a preamble to the course — they are its load-bearing structure.