Prove/n androidGet App
menu_book Review / The material behind the questions

Brush up before you prove it.

Every Prove/n question comes from the topics below. Each section gives the key definitions, formulas and theorems, a worked example, and free textbooks to go deeper. It's a refresher, not a course.

functionsMath

From arithmetic to university topics. Questions are answered in your head, so the examples use small numbers.

Arithmetic1 Level 1

Rules

  • Order of operations: brackets first, then multiplication and division (left to right), then addition and subtraction (left to right). So \(6+2\times3=12\), not 24.
  • Division with a remainder: \(23\div4\) is 5 remainder 3, because \(4\times5=20\) and \(23-20=3\). The remainder is always smaller than the number you divide by.
  • Making change: change = amount paid − total cost. Add up everything bought first.
  • Rounding to the nearest ten: look at the ones digit. 5 or more rounds up (67 becomes 70), less rounds down (63 becomes 60).
Divisiondividend = divisor × quotient + remainder
Common anglesright angle 90°, straight line 180°, three quarter turns 270°, full turn 360°

Pens cost $3 and notebooks $4. Sam buys 7 pens and 2 notebooks and pays with $50. How much change?

  1. Pens: \(7\times3=21\). Notebooks: \(2\times4=8\).
  2. Total: \(21+8=29\).
  3. Change: \(50-29\).

$21

A clock's minute hand turns clockwise from 12 to 9. How many degrees is that?

  1. Each quarter of the clock face is 90°.
  2. 12 to 9 is three quarters: \(3\times90\).

270°

Algebra1 Levels 2–3

Fractions, decimals and percentages

  • Fractions: to add or subtract, rewrite over a common denominator. To divide, multiply by the reciprocal.
  • Percent means "per hundred": \(p\%\) of \(x\) is \(\tfrac{p}{100}\cdot x\).
Adding fractions\(\dfrac{a}{b}+\dfrac{c}{d}=\dfrac{ad+bc}{bd}\)
Percent change\(\dfrac{\text{new}-\text{old}}{\text{old}}\times 100\%\)

What is \(\tfrac{3}{4}+\tfrac{1}{6}\)?

  1. Common denominator 12: \(\tfrac{9}{12}+\tfrac{2}{12}\).
  2. Add the numerators.

\(\tfrac{11}{12}\)

Linear equations and inequalities

  • Solve by doing the same inverse operation to both sides until \(x\) is alone.
  • Multiplying or dividing an inequality by a negative number flips its direction.
  • A line is \(y=mx+b\): slope \(m\), y-intercept \(b\).
Slope through two points\(m=\dfrac{y_2-y_1}{x_2-x_1}\)
Exponent rules\(a^m a^n=a^{m+n},\ (a^m)^n=a^{mn},\ a^{-n}=\tfrac{1}{a^n},\ a^0=1\)

Quadratics

  • Factoring \(x^2+bx+c\): find \(p,q\) with \(p+q=b\) and \(pq=c\), then \(x^2+bx+c=(x+p)(x+q)\).
  • Difference of squares: \(a^2-b^2=(a-b)(a+b)\).
  • Zero-product rule: if \(AB=0\) then \(A=0\) or \(B=0\). So \((x-5)(x-2)=0\) gives \(x=5\) or \(x=2\).
  • The graph of \(y=ax^2+bx+c\) is a parabola: it opens up if \(a>0\), down if \(a<0\), with its vertex at \(x=-\tfrac{b}{2a}\).
Quadratic formula\(x=\dfrac{-b\pm\sqrt{b^2-4ac}}{2a}\)
Discriminant \(\Delta=b^2-4ac\)\(\Delta>0\): two real roots, \(\Delta=0\): one, \(\Delta<0\): none

Logarithms

Definition\(\log_b x=y \iff b^y=x\)
Rules\(\log_b(xy)=\log_b x+\log_b y,\ \log_b x^k=k\log_b x\)

Solve \(x^2-5x+6=0\).

  1. Find two numbers with sum \(-5\) and product \(6\): \(-2\) and \(-3\).
  2. \((x-2)(x-3)=0\).
  3. Zero-product rule.

\(x=2\) or \(x=3\)

What is \(\log_2 32\)?

  1. Ask: 2 to what power is 32? \(2^5=32\).

5

Precalculus1 Level 4

Functions and trigonometry

  • Composition: \((f\circ g)(x)=f(g(x))\). Apply \(g\) first.
  • Radians: \(\pi\text{ rad}=180^\circ\).
  • Unit circle: \(\sin\tfrac{\pi}{6}=\tfrac12\), \(\cos\tfrac{\pi}{3}=\tfrac12\), \(\sin\tfrac{\pi}{4}=\cos\tfrac{\pi}{4}=\tfrac{\sqrt2}{2}\), \(\sin 0=0\), \(\cos 0=1\).
Pythagorean identity\(\sin^2\theta+\cos^2\theta=1\)
Tangent\(\tan\theta=\dfrac{\sin\theta}{\cos\theta}\)

Complex numbers

  • \(i^2=-1\). Powers of \(i\) repeat every four: \(i,\,-1,\,-i,\,1\).
  • The conjugate of \(a+bi\) is \(a-bi\), and \((a+bi)(a-bi)=a^2+b^2\).
Multiplication\((a+bi)(c+di)=(ac-bd)+(ad+bc)i\)
Modulus\(|a+bi|=\sqrt{a^2+b^2}\)
Polar form and De Moivre\(\big(r(\cos\theta+i\sin\theta)\big)^n=r^n(\cos n\theta+i\sin n\theta)\)

What is \((2+3i)(1-i)\)?

  1. Expand: \(2-2i+3i-3i^2\).
  2. \(i^2=-1\), so \(-3i^2=3\).
  3. Collect: \(5+i\).

\(5+i\)

Solve \(2^{x+1}=16\).

  1. \(16=2^4\), so \(x+1=4\).

\(x=3\)

Calculus 12 Level 5

Limits and continuity

Limit:
\(\lim_{x\to a}f(x)=L\) means \(f(x)\) gets arbitrarily close to \(L\) as \(x\) approaches \(a\). It exists only if both one-sided limits exist and are equal.
Continuous at \(a\):
\(f(a)\) is defined and \(\lim_{x\to a}f(x)=f(a)\).

Derivatives

Definition\(f'(x)=\lim_{h\to0}\dfrac{f(x+h)-f(x)}{h}\)
Power rule\(\dfrac{d}{dx}x^n=nx^{n-1}\)
Product rule\((fg)'=f'g+fg'\)
Quotient rule\(\left(\dfrac{f}{g}\right)'=\dfrac{f'g-fg'}{g^2}\)
Chain rule\(\dfrac{d}{dx}f(g(x))=f'(g(x))\,g'(x)\)
Common derivatives\((\sin x)'=\cos x,\ (\cos x)'=-\sin x,\ (e^x)'=e^x,\ (\ln x)'=\tfrac1x\)

Theorems

L'Hôpital's rule. If \(\tfrac{f(x)}{g(x)}\) gives \(\tfrac00\) or \(\tfrac{\infty}{\infty}\) at \(a\), then \(\lim_{x\to a}\tfrac{f(x)}{g(x)}=\lim_{x\to a}\tfrac{f'(x)}{g'(x)}\), if the second limit exists.
Mean Value Theorem. If \(f\) is continuous on \([a,b]\) and differentiable on \((a,b)\), some \(c\) in \((a,b)\) has \(f'(c)=\tfrac{f(b)-f(a)}{b-a}\).
Extrema. Local maxima and minima of a differentiable function occur where \(f'(x)=0\). If \(f''(x)>0\) there it's a minimum, if \(f''(x)<0\) a maximum.

Find \(\lim_{x\to1}\dfrac{x^2-1}{x-1}\).

  1. Factor: \(\tfrac{(x-1)(x+1)}{x-1}=x+1\) for \(x\ne1\).
  2. Substitute \(x=1\).

2

Differentiate \((3x^2+1)^5\).

  1. Chain rule: outer \(u^5\) gives \(5u^4\), inner \(3x^2+1\) gives \(6x\).
  2. Multiply.

\(30x(3x^2+1)^4\)

Calculus 22 Level 6

Integrals

Fundamental Theorem of Calculus. If \(F'=f\), then \(\int_a^b f(x)\,dx=F(b)-F(a)\). Also, \(\tfrac{d}{dx}\int_a^x f(t)\,dt=f(x)\).
Power rule\(\int x^n\,dx=\dfrac{x^{n+1}}{n+1}+C,\ n\ne-1\)
Integration by parts\(\int u\,dv=uv-\int v\,du\)
Substitution\(\int f(g(x))g'(x)\,dx=\int f(u)\,du\)
Improper integral\(\int_a^\infty f\,dx=\lim_{t\to\infty}\int_a^t f\,dx\)

Sequences and series

Geometric series, \(|r|<1\)\(\sum_{n=0}^{\infty}ar^n=\dfrac{a}{1-r}\)
p-series\(\sum \tfrac{1}{n^p}\) converges if and only if \(p>1\)
Taylor series at \(a\)\(f(x)=\sum_{n=0}^{\infty}\dfrac{f^{(n)}(a)}{n!}(x-a)^n\)
Maclaurin series\(e^x=\sum \tfrac{x^n}{n!},\ \sin x=x-\tfrac{x^3}{3!}+\tfrac{x^5}{5!}-\cdots\)

Find \(\int_0^3 2x\,dx\).

  1. An antiderivative of \(2x\) is \(x^2\).
  2. \(3^2-0^2\).

9

Sum \(3+1+\tfrac13+\tfrac19+\cdots\)

  1. Geometric with \(a=3\), \(r=\tfrac13\).
  2. \(\tfrac{3}{1-1/3}=\tfrac{3}{2/3}\).

\(\tfrac92\)

Linear algebra3 Level 6

Linearly independent:
no vector in the set is a combination of the others.
Rank:
the number of linearly independent rows (equivalently, columns).
Eigenvector:
a nonzero \(v\) with \(Av=\lambda v\). The scalar \(\lambda\) is its eigenvalue.
Dot product\(u\cdot v=\sum u_iv_i=|u||v|\cos\theta\)
2×2 determinant\(\det\begin{pmatrix}a&b\\c&d\end{pmatrix}=ad-bc\)
2×2 inverse\(\dfrac{1}{ad-bc}\begin{pmatrix}d&-b\\-c&a\end{pmatrix}\)
Eigenvalues\(\det(A-\lambda I)=0\)
Rank–nullity theorem.3 For an \(m\times n\) matrix, \(\operatorname{rank}+\operatorname{nullity}=n\), the number of columns.
Trace and determinant. The eigenvalues sum to the trace and multiply to the determinant. Matrix multiplication is generally not commutative: \(AB\ne BA\).

Find the eigenvalues of \(\begin{pmatrix}4&1\\2&3\end{pmatrix}\).

  1. \(\det\begin{pmatrix}4-\lambda&1\\2&3-\lambda\end{pmatrix}=(4-\lambda)(3-\lambda)-2\).
  2. \(\lambda^2-7\lambda+10=0\), so \((\lambda-5)(\lambda-2)=0\).
  3. Check: \(5+2=7\) (trace), \(5\cdot2=10\) (determinant).

\(\lambda=5\) and \(\lambda=2\)

Advanced topics2,4,5 Level 7

Hard questions at this level are mostly conceptual: what a theorem says and what it implies.

Multivariable calculus and differential equations

Gradient\(\nabla f=\left(\tfrac{\partial f}{\partial x},\tfrac{\partial f}{\partial y},\tfrac{\partial f}{\partial z}\right)\)
Divergence\(\nabla\cdot F=\tfrac{\partial F_1}{\partial x}+\tfrac{\partial F_2}{\partial y}+\tfrac{\partial F_3}{\partial z}\)
Exponential growth\(y'=ky \Rightarrow y=Ce^{kx}\)

Abstract algebra

Group:
a set with an operation that is closed and associative, with an identity element and an inverse for every element.
Field:
a set where you can add, subtract, multiply, and divide by anything nonzero, such as \(\mathbb{Q}\), \(\mathbb{R}\), \(\mathbb{C}\).
Lagrange's theorem.4 In a finite group, the order of every subgroup divides the order of the group. A group of order 12 has no subgroup of order 5.
Galois theory links field extensions to groups4: each polynomial has a Galois group of symmetries of its roots, and the polynomial is solvable by radicals exactly when that group is solvable. That's why there is no general formula in radicals for degree 5 and up (the Abel–Ruffini theorem).

Analysis and number theory

Cauchy's integral theorem.5 If \(f\) is holomorphic (complex differentiable) on a simply connected region, its integral around any closed curve in that region is 0.
Residue theorem.5 \(\oint_\gamma f(z)\,dz=2\pi i\sum \operatorname{Res}(f,z_k)\) over the poles inside \(\gamma\). For example, \(\oint_{|z|=1}\tfrac{1}{z}\,dz=2\pi i\).
Completeness of \(\mathbb{R}\). Every Cauchy sequence of real numbers converges. That's not true in \(\mathbb{Q}\).
Fermat's little theorem. If \(p\) is prime, \(a^p\equiv a \pmod p\).

memoryComputer Science

From how a computer works to algorithms and complexity theory.

Computer basics4 Level 1

CPU:
the processor that executes program instructions.
RAM:
fast working memory for running programs. It's volatile: it loses its contents when power is off.
Storage (SSD, hard drive):
keeps files when the power is off (non-volatile), but is slower than RAM.
Operating system:
manages hardware, memory, files and running programs (Android, Windows, macOS, Linux).
Bit and byte:
a bit is a 0 or 1. A byte is 8 bits.
IP address and DNS:
every device on the internet has an IP address. DNS turns names like example.com into IP addresses.
Decimal (SI) units1 KB = 1000 B, 1 MB = 1000 KB, 1 GB = 1000 MB
Binary units41 KiB = 1024 B, 1 MiB = 1024 KiB

How many 3 MB photos fit on 1.5 GB (1 GB = 1000 MB)?

  1. 1.5 GB = 1500 MB.
  2. 1500 ÷ 3.

500

Programming basics4 Level 2

  • Binary place values are powers of 2: \(1011_2=8+0+2+1=11\).
  • Loops: in Python, range(n) gives \(0,1,\dots,n-1\), so the body runs \(n\) times.
  • Arrays are usually indexed from 0: the last of \(n\) items is at index \(n-1\).
  • Linear search checks items one by one: up to \(n\) comparisons.

What does this print?

x = 3
for i in range(4):
    x += i
print(x)
  1. i takes 0, 1, 2, 3.
  2. \(3+0+1+2+3\).

9

Data structures1,2 Levels 2–6

StructureKey ideaTypical costs
Arraycontiguous, indexedindex \(O(1)\), search \(O(n)\)
Dynamic arraydoubles when fullappend \(O(1)\) amortized
Linked listnodes with pointersinsert/delete at a known node \(O(1)\), search \(O(n)\)
Stacklast in, first out (LIFO)push, pop \(O(1)\)
Queuefirst in, first out (FIFO)enqueue, dequeue \(O(1)\)
Hash tablekey → bucket by a hashlookup \(O(1)\) average, \(O(n)\) worst
Binary heapparent ≤ children (min-heap)peek \(O(1)\), insert/extract \(O(\log n)\)
Union-finddisjoint setsnearly \(O(1)\) with path compression and union by rank
  • Load factor \(\alpha=n/m\) (keys per bucket). Collisions are handled by chaining (lists in buckets) or open addressing (probing for a free slot).
  • In a heap stored in an array from index 0, node \(i\) has children \(2i+1\) and \(2i+2\), and parent \(\lfloor (i-1)/2\rfloor\).

Push 1, 2, 3 onto an empty stack, pop once, push 4. What's on top?

  1. After the pushes, the stack is [1, 2, 3] with 3 on top.
  2. Pop removes 3. Push 4.

4

Search algorithms1,2 Levels 2–6

  • Linear search: \(O(n)\), works on any list.
  • Binary search: \(O(\log n)\), but only on sorted data. It halves the range each step, so it needs at most \(\lfloor\log_2 n\rfloor+1\) comparisons.
  • Two pointers: on sorted data, move inward from both ends, \(O(n)\).
  • BFS and DFS visit every vertex and edge of a graph: \(O(V+E)\).

Binary search for 7 in [1, 3, 5, 7, 9, 11].

  1. Middle is 5. 7 > 5, so search [7, 9, 11].
  2. Middle is 9. 7 < 9, so search [7].
  3. Found.

3 comparisons

Sorting1,2 Levels 3–6

AlgorithmBestAverageWorstStableIn place
Bubble\(O(n)\)\(O(n^2)\)\(O(n^2)\)yesyes
Selection\(O(n^2)\)\(O(n^2)\)\(O(n^2)\)noyes
Insertion\(O(n)\)\(O(n^2)\)\(O(n^2)\)yesyes
Merge\(O(n\log n)\)\(O(n\log n)\)\(O(n\log n)\)yesno
Quick\(O(n\log n)\)\(O(n\log n)\)\(O(n^2)\)noyes
Heap\(O(n\log n)\)\(O(n\log n)\)\(O(n\log n)\)noyes
  • Stable: equal keys keep their original order.
  • Quicksort hits \(O(n^2)\) with consistently bad pivots, such as always picking the last element of already sorted input.
  • Insertion sort is fast on nearly sorted data: its work is proportional to the number of out-of-order pairs (inversions).
  • Counting sort \(O(n+k)\) and radix sort \(O(d(n+k))\) don't compare elements.
Comparison sorting lower bound.1 Any comparison sort needs at least \(\lceil\log_2 n!\rceil\) comparisons in the worst case, which is \(\Omega(n\log n)\). For 4 items, that's \(\lceil\log_2 24\rceil=5\).

Trees1,2 Levels 4–6

Height:
edges on the longest path from the root to a leaf (a single node has height 0).
Binary search tree (BST):
every key in the left subtree is smaller than the node, and every key in the right subtree is larger. Search and insert take \(O(h)\).
AVL tree:
a BST where subtree heights differ by at most 1, restored by rotations, so \(h=O(\log n)\).
  • A tree with \(n\) nodes has \(n-1\) edges. A binary tree of height \(h\) has at most \(2^{h+1}-1\) nodes.
  • Preorder: root, left, right. Inorder: left, root, right (sorted order for a BST). Postorder: left, right, root. Level order: breadth-first.
  • Deleting a BST node with two children: replace it with its inorder successor (the smallest key in its right subtree).

Insert 5, 3, 8, 1, 4 into an empty BST. Give its traversals and height.

  1. 5 is the root. 3 goes left, 8 right, 1 left of 3, 4 right of 3.
  2. Inorder: 1 3 4 5 8. Preorder: 5 3 1 4 8.
  3. The longest path is 5 → 3 → 1.

Height 2

Graphs1 Levels 5–6

  • Handshake lemma: the degrees add up to \(2|E|\). A complete graph on \(n\) vertices has \(\tfrac{n(n-1)}{2}\) edges.
  • Adjacency list: \(O(V+E)\) space. Adjacency matrix: \(O(V^2)\) space, \(O(1)\) edge lookup.
  • BFS finds shortest paths by edge count. Dijkstra finds shortest paths with non-negative weights, \(O((V+E)\log V)\) with a binary heap.
  • Bellman-Ford allows negative weights and detects negative cycles, \(O(VE)\).
  • A minimum spanning tree (Kruskal, Prim) of a connected graph has \(V-1\) edges.
  • Topological sort orders a directed acyclic graph so every edge points forward. A graph is bipartite exactly when it has no odd cycle.

Edges A–B 4, A–C 1, C–B 2, B–D 5, C–D 8. Shortest distance from A to D?

  1. Settle C at 1. Through C, B is \(1+2=3\), better than 4.
  2. Through B, D is \(3+5=8\). Through C, D would be 9.

8 (A → C → B → D)

Theory of computation3 Level 7

P:
decision problems solvable in polynomial time.
NP:
decision problems whose "yes" answers can be verified in polynomial time, given a certificate. \(P\subseteq NP\).
NP-hard:
every NP problem reduces to it in polynomial time. It need not be in NP itself.
NP-complete:
both in NP and NP-hard. Examples: SAT, 3-SAT, Hamiltonian cycle, subset sum.
Decidable:
some Turing machine always halts with the right yes/no answer.
Cook–Levin theorem.3 SAT is NP-complete. A polynomial-time algorithm for any one NP-complete problem would give one for all of NP, proving \(P=NP\), which is still an open question.
The halting problem is undecidable3 (Turing, 1936). No program can decide, for every program and input, whether it eventually halts.

codeSoftware

Everyday knowledge for writing, storing and serving code, from object-oriented basics to system design.

Coding1

  • Recursion needs a base case that stops it. Each call should move toward that case.
  • Integer division and modulo in Python: 7 // 2 == 3, 7 % 2 == 1, and -7 // 2 == -4 (it rounds down).
  • Short-circuiting: a and b skips b if a is false. a or b skips b if a is true.
  • Off-by-one: range(1, 5) is 1, 2, 3, 4. The end isn't included.
  • Object-oriented ideas: encapsulation (hide state behind methods), inheritance (a subclass reuses a parent), polymorphism (one call, behaviour chosen by the object's type).
  • Git: a commit is a snapshot, a branch is a movable pointer to commits, and a merge joins two branches' histories.

What does f(4) return?

def f(n):
    return 1 if n <= 1 else n * f(n - 1)
  1. \(f(4)=4\cdot f(3)=4\cdot3\cdot f(2)=4\cdot3\cdot2\cdot f(1)\).
  2. \(f(1)=1\).

24

Object-oriented programming5

Class and object:
a class is a blueprint, and an object is one instance built from it.
Encapsulation:
bundle data with the methods that use it, and hide the data behind those methods (private fields, public methods).
Abstraction:
expose what an object does and hide how it does it.
Inheritance:
a subclass reuses and extends a parent class ("is-a": a Dog is an Animal).
Polymorphism:
one call, different behaviour depending on the object's actual type.
  • Overriding: a subclass replaces a parent's method with the same signature. Overloading: several methods share a name but take different parameters.
  • Interface: declares methods without implementing them. Abstract class: may mix implemented and unimplemented methods, and can't be instantiated.
  • Composition ("has-a": a Car has an Engine) is often preferred to inheritance because it couples classes less.
  • Access modifiers: public (anyone), protected (the class and its subclasses), private (the class only). Exact rules vary by language.
  • SOLID: single responsibility, open-closed, Liskov substitution, interface segregation, dependency inversion.

What does this print?

class Shape:
    def area(self): return 0
class Square(Shape):
    def __init__(self, s): self.s = s
    def area(self): return self.s * self.s

shapes = [Shape(), Square(3)]
print(sum(x.area() for x in shapes))
  1. Square overrides area, so each object runs its own version (polymorphism).
  2. \(0+9\).

9

Databases and SQL2

  • WHERE filters rows before grouping. HAVING filters groups after GROUP BY.
  • INNER JOIN keeps matching rows only. LEFT JOIN keeps every left row, with NULLs where there's no match.
  • Primary key: unique and not null. Foreign key: must match a key in another table.
  • NULL isn't equal to anything, even NULL: test it with IS NULL. COUNT(col) skips NULLs, and COUNT(*) counts every row.
  • Indexes speed up reads but slow down writes. Normalization removes duplicated data.
  • ACID: atomicity, consistency, isolation, durability. The isolation levels, from weakest: read uncommitted, read committed, repeatable read, serializable.2

Table orders(customer, amount) has rows (ann, 10), (ann, 30), (bo, 5). What does this return?

SELECT customer, SUM(amount) FROM orders
GROUP BY customer HAVING SUM(amount) > 20;
  1. Groups: ann = 40, bo = 5.
  2. HAVING keeps the groups over 20.

One row: (ann, 40)

Frontend3

  • Box model: content, then padding, border and margin. With box-sizing: border-box, width includes padding and border.
  • Specificity (strongest first): inline styles, IDs, then classes, attributes and pseudo-classes, then elements.3
  • Flexbox: justify-content aligns along the main axis, align-items along the cross axis. Grid lays out rows and columns together.
  • rem is relative to the root font size, em to the element's font size (the parent's, when setting font-size itself).
  • Most DOM events bubble from the target up through its ancestors.
  • In JavaScript, === compares without type conversion: 0 == "0" is true but 0 === "0" is false.
  • Accessibility: use semantic elements, give images alt text, and label form fields.

Which rule wins for the link: #nav .item a or .nav .item a?

  1. Specificity, counted as (IDs, classes, elements): (1, 1, 1) against (0, 2, 1).
  2. An ID beats any number of classes.

#nav .item a

Backend4

StatusMeaning
200 / 201 / 204OK / Created / No Content
301 / 304Moved Permanently / Not Modified
400Bad Request
401Unauthorized: not authenticated (who are you?)
403Forbidden: authenticated but not allowed
404 / 409 / 429Not Found / Conflict / Too Many Requests
500 / 503Internal Server Error / Service Unavailable
  • Idempotent methods give the same result when repeated: GET, PUT and DELETE are, POST isn't. GET is also safe: it changes nothing.4
  • Authentication proves who you are. Authorization decides what you may do.
  • Store passwords as slow, salted hashes (bcrypt, Argon2), never as plain text or fast hashes.4
  • Horizontal scaling adds machines behind a load balancer. Vertical scaling makes one machine bigger.
  • Common web vulnerabilities: injection, cross-site scripting (XSS), broken access control.

System design basics3,6 Medium–Hard

Load balancer:
spreads incoming requests across several servers, and stops sending to ones that fail health checks.
Reverse proxy:
sits in front of servers and receives clients' requests for them (for TLS, caching, routing). A forward proxy sits in front of clients and sends requests on their behalf.
Cache:
a fast copy of data close to where it's needed. A TTL (time to live) sets how long an entry stays. Invalidation removes entries that are out of date, and a stale cache serves old data.
CDN (content delivery network):
servers around the world that cache content near users, cutting latency and load on the origin server.
DNS:
turns domain names into IP addresses.
TLS and HTTPS:
TLS encrypts and authenticates a connection, and HTTPS is HTTP over TLS. SSL is TLS's older, deprecated predecessor, which is why people still say "SSL/TLS".
FTP and SFTP:
FTP transfers files with no encryption (port 21). SFTP transfers files over an encrypted SSH connection (port 22).
API gateway:
a single entry point that routes requests to back-end services and handles shared concerns like authentication and rate limiting.
IdeaIn short
Horizontal vs vertical scalingadd more machines vs make one machine bigger
Stateless servicekeeps no per-user state, so any instance can serve any request and scaling out is easy
Replicationcopies of the same data on several machines, for reads and failover
Shardingsplits data across machines, each holding part of it
CAP theoremduring a network partition, a distributed store must choose consistency or availability
Message queuelets work be done later and absorbs bursts, separating producers from consumers
Monolith vs microservicesone deployable app vs many small services that communicate over the network
Latency vs throughputtime for one request vs requests handled per second
Redundancy and failoverspare copies take over when one fails, so there's no single point of failure
WebSockets vs pollingone open two-way connection the server can push on vs the client asking repeatedly

A site's users are worldwide, but its one server is in Europe. Pages load slowly in Asia. What helps most?

  1. The delay comes from distance (latency), not from the server's capacity.
  2. A CDN caches the content on servers near each user.

Put a CDN in front of the site

trending_upEconomics

Markets, the whole economy, banks and investing.

Microeconomics1

  • Law of demand: when the price rises, the quantity demanded falls. Equilibrium is where supply equals demand.
  • A price ceiling below equilibrium causes a shortage. A price floor above it causes a surplus.
  • A tax drives a wedge between what buyers pay and what sellers keep, creating deadweight loss.
  • Opportunity cost is the value of the next best alternative given up.
  • Firms maximize profit where marginal revenue = marginal cost. In perfect competition, \(P=MC\). A monopoly prices above \(MC\).
  • Public goods are non-rival and non-excludable. Externalities are costs or benefits that fall on others.
Price elasticity of demand\(E_d=\dfrac{\%\Delta Q_d}{\%\Delta P}\). \(|E_d|>1\) is elastic.

Demand \(Q_d=100-2P\), supply \(Q_s=20+2P\). Find the equilibrium.

  1. \(100-2P=20+2P\), so \(4P=80\).
  2. \(P=20\), and \(Q=100-40\).

\(P=20\), \(Q=60\)

Macroeconomics1

GDP (expenditure)\(Y=C+I+G+(X-M)\)
Inflation rate\(\dfrac{CPI_2-CPI_1}{CPI_1}\times100\%\)
Unemployment rate\(\dfrac{\text{unemployed}}{\text{labor force}}\times100\%\)
Spending multiplier\(\dfrac{1}{1-MPC}\)
  • Real GDP adjusts nominal GDP for price changes.
  • The three types of unemployment are frictional, structural and cyclical.
  • Fiscal policy uses government spending and taxes. Monetary policy uses interest rates and the money supply.
  • The short-run Phillips curve shows a trade-off between inflation and unemployment.

MPC is 0.8. By how much can $10 billion of new government spending raise GDP?

  1. Multiplier \(=\tfrac{1}{1-0.8}=5\).
  2. \(5\times 10\).

$50 billion (in the simple model)

Banking1,2

  • Fractional reserve banking: banks lend out most deposits. The simple money multiplier is \(\tfrac{1}{\text{reserve ratio}}\).
  • A bank balance sheet: assets = liabilities + equity. Deposits are the bank's liabilities, and loans are its assets.
  • Central bank tools (the US Federal Reserve): open market operations, the policy rate target, and interest on reserve balances. The Fed cut reserve requirements to 0% in March 2020.2
  • FDIC deposit insurance covers $250,000 per depositor, per insured bank, per ownership category.2
  • APR is the yearly rate without compounding. APY includes compounding.
Simple interest\(A=P(1+rt)\)
Compound interest\(A=P\left(1+\tfrac{r}{n}\right)^{nt}\)

$1000 at 10% a year for 2 years: compound against simple?

  1. Compound: \(1000\times1.1^2=1210\).
  2. Simple: \(1000\times(1+0.2)=1200\).

$1210 against $1200

Trading and investing1,3

  • Stocks are ownership (equity). Bonds are loans (debt). When interest rates rise, existing bond prices fall.
  • A market order fills right away at the best available price. A limit order fills only at your price or better.
  • The bid-ask spread is the gap between the highest bid and the lowest ask.
  • A call option is the right to buy at the strike price, and a put the right to sell. A future is an obligation to trade later at a set price.
  • Short selling: sell borrowed shares, hoping to buy them back cheaper.
  • Diversification reduces company-specific risk, but not market-wide risk.
Price-to-earnings ratio\(P/E=\dfrac{\text{share price}}{\text{earnings per share}}\)
Dividend yield\(\dfrac{\text{annual dividend}}{\text{share price}}\)

A $50 stock earns $2.50 per share. What is its P/E?

  1. \(50\div2.5\).

20

precision_manufacturingEngineering

Mechanics, circuits and heat. Many questions ask what a formula means, not just how to use it.

Statics1,2

  • Equilibrium: \(\sum F=0\) and \(\sum M=0\). Start with a free-body diagram.
  • Moment: \(M=F\cdot d\), with \(d\) the perpendicular distance to the point.
  • A couple (two equal, opposite, offset forces) creates a pure moment and no net force.
  • Supports in 2D: a roller gives 1 reaction, a pin 2, a fixed support 3.
  • Friction: \(f\le\mu_s N\). A block about to slip on an incline has \(\mu_s=\tan\theta\).
  • Trusses: solve with the method of joints (equilibrium at each pin) or the method of sections (cut and take moments).
Rectangle, centroidal axis\(I=\dfrac{bh^3}{12}\)

A 4 m beam on supports A and B carries 10 N at 1 m from A. Find the reactions.

  1. Moments about A: \(R_B\cdot4=10\cdot1\), so \(R_B=2.5\) N.
  2. Vertical forces: \(R_A=10-2.5\).

\(R_A=7.5\) N, \(R_B=2.5\) N

Dynamics1

Constant acceleration\(v=v_0+at,\quad x=v_0t+\tfrac12at^2,\quad v^2=v_0^2+2a\Delta x\)
Newton's second law\(F=ma\)
Momentum and impulse\(p=mv,\quad J=F\Delta t=\Delta p\)
Energy\(KE=\tfrac12mv^2,\quad PE=mgh,\quad W=Fd\cos\theta,\quad P=\tfrac{W}{t}\)
Circular motion\(a_c=\dfrac{v^2}{r}\)
Torque and springs\(\tau=rF\sin\theta,\quad \omega=\sqrt{k/m}\)
  • Momentum is conserved in every collision. Kinetic energy is conserved only in elastic ones.
  • Doubling speed doubles momentum but quadruples kinetic energy.

A 2 kg cart at 3 m/s is stopped in 1 s. What average force stopped it?

  1. \(\Delta p=2\times3=6\) kg·m/s.
  2. \(F=\Delta p/\Delta t=6/1\).

6 N

Electrical circuits1

Ohm's law and power\(V=IR,\quad P=VI=I^2R=\tfrac{V^2}{R}\)
Series and parallel\(R_s=R_1+R_2,\quad \tfrac{1}{R_p}=\tfrac{1}{R_1}+\tfrac{1}{R_2}\)
Voltage divider\(V_2=V\dfrac{R_2}{R_1+R_2}\)
Capacitor\(Q=CV,\quad E=\tfrac12CV^2,\quad \tau=RC\)
Inductor\(V=L\dfrac{di}{dt}\)
Sine wave RMS\(V_{rms}=\dfrac{V_{peak}}{\sqrt2}\)
  • Kirchhoff's current law: the current into a node equals the current out. Voltage law: the voltages around any loop sum to zero.
  • In series the current is the same through each part. In parallel the voltage is the same across each branch.
  • Thevenin equivalent: \(V_{th}\) is the open-circuit voltage, and \(R_{th}\) is the resistance seen with independent sources turned off.
  • After one time constant \(\tau=RC\), a charging capacitor reaches about 63% of its final voltage.

12 V across 2 Ω and 4 Ω in series. Current, and voltage across the 4 Ω?

  1. \(R=6\) Ω, so \(I=12/6=2\) A.
  2. \(V=2\times4\).

2 A and 8 V

Thermodynamics1

Kelvin\(T_K=T_{^\circ C}+273.15\)
Heat\(Q=mc\Delta T,\quad Q=mL\) (phase change)
First law\(\Delta U=Q-W\) (\(W\) done by the system)
Ideal gas\(PV=nRT\)
Efficiency and COP\(e=\dfrac{W}{Q_H},\quad e_{Carnot}=1-\dfrac{T_C}{T_H},\quad COP=\dfrac{Q_C}{W}\)
Conduction\(\dfrac{Q}{t}=\dfrac{kA\Delta T}{L}\)
  • Processes: isothermal (constant \(T\), so \(\Delta U=0\) for an ideal gas), isochoric (constant \(V\), \(W=0\)), isobaric (constant \(P\), \(W=P\Delta V\)), adiabatic (\(Q=0\)).
  • Second law: the entropy of an isolated system never decreases. No engine beats the Carnot efficiency.1
  • During a phase change, added heat changes the internal energy, not the temperature.

What is the best possible efficiency of an engine between 600 K and 300 K?

  1. \(1-\tfrac{300}{600}\).

50%

biotechBiology

Cells, energy and inheritance.

Cell biology1

PartJob
Nucleusholds the DNA (eukaryotes only; prokaryotes have none)
Mitochondriamake ATP by cellular respiration
Chloroplastsphotosynthesis (plants and algae)
Ribosomesbuild proteins
Rough / smooth ERprotein processing / lipid synthesis
Golgi apparatusmodifies, sorts and ships proteins
Lysosomesbreak down waste
Cell membranephospholipid bilayer, selectively permeable
Cellular respiration\(C_6H_{12}O_6+6O_2\rightarrow6CO_2+6H_2O+\text{ATP}\)
Photosynthesis\(6CO_2+6H_2O\xrightarrow{\text{light}}C_6H_{12}O_6+6O_2\)
  • Osmosis: water moves across a membrane toward the side with more solute. Active transport moves substances against their gradient using ATP.
  • Respiration runs glycolysis, then the Krebs cycle, then the electron transport chain.
  • Mitosis makes 2 identical diploid cells. Meiosis makes 4 genetically different haploid cells, with crossing over.

A human body cell has 46 chromosomes. How many does a human egg cell have?

  1. Meiosis halves the chromosome number.

23

Genetics1

  • DNA base pairing: A–T and G–C. In RNA, U replaces T.
  • Replication is semi-conservative: each new double helix keeps one old strand.
  • Central dogma: DNA → (transcription) → mRNA → (translation) → protein.
  • There are 64 codons. AUG is the start codon, and 3 codons are stops.
  • Genotype is the alleles (AA, Aa, aa). Phenotype is the observed trait.
  • X-linked recessive traits show up more often in males, who have one X.
  • PCR copies a DNA segment many times.
Monohybrid cross Aa × Aagenotypes 1 AA : 2 Aa : 1 aa, phenotypes 3 : 1
Dihybrid cross AaBb × AaBbphenotypes 9 : 3 : 3 : 1

DNA is 30% adenine. What percent is guanine?

  1. A pairs with T, so T = 30% and A + T = 60%.
  2. G + C = 40%, split equally.

20%

scienceChemistry

What atoms are made of, and how much reacts with what.

Atomic structure1

  • Atomic number \(Z\) = protons. Mass number \(A\) = protons + neutrons. A neutral atom has \(Z\) electrons.
  • Isotopes have the same \(Z\) but different numbers of neutrons. Ions have gained or lost electrons.
  • Electron configuration fills 1s, 2s, 2p, 3s, 3p, 4s, 3d… Valence electrons are those in the outermost shell.
  • Quantum numbers: \(n\) (shell), \(l\) (subshell), \(m_l\) (orbital), \(m_s\) (spin).
  • Periodic trends: atomic radius shrinks across a period and grows down a group. Ionization energy and electronegativity do the opposite. Fluorine is the most electronegative element.
Average atomic mass\(\sum(\text{abundance}\times\text{isotope mass})\)

How many neutrons and electrons are in \(^{35}\text{Cl}^-\)?

  1. Chlorine has \(Z=17\): neutrons \(=35-17=18\).
  2. The charge −1 means one extra electron: \(17+1=18\).

18 neutrons, 18 electrons

Stoichiometry1

Moles2\(n=\dfrac{m}{M},\quad N_A=6.022\times10^{23}\ \text{mol}^{-1}\)
Molarity and dilution\(c=\dfrac{n}{V},\quad c_1V_1=c_2V_2\)
Percent yield\(\dfrac{\text{actual}}{\text{theoretical}}\times100\%\)
Ideal gas at 0 °C and 1 atmabout 22.4 L per mole
  • Balance equations so each element has the same number of atoms on both sides. Then the coefficients give mole ratios.
  • The limiting reagent runs out first and sets the theoretical yield.
  • An empirical formula is the simplest whole-number ratio (CH₂O). A molecular formula is the actual count (C₆H₁₂O₆).

\(2H_2+O_2\rightarrow2H_2O\). With 4 g of H₂ and 16 g of O₂, how much water forms?

  1. H₂: \(4/2=2\) mol. O₂: \(16/32=0.5\) mol.
  2. 0.5 mol of O₂ needs only 1 mol of H₂, so O₂ is limiting.
  3. 0.5 mol of O₂ gives 1 mol of H₂O, which is 18 g.

18 g