Everything on the site.

Big-O notationAlgorithms · Count the steps in real loops, then compare n, n log n, n² and 2ⁿ on a live chart.RecursionAlgorithms · Watch frames push and pop on the call stack for factorial and Fibonacci.BFS vs DFSAlgorithms · A queue against a stack: draw a graph and see which order each search visits it in.Sorting algorithmsAlgorithms · Seven sorts on the same input, with comparison, swap and write counts side by side.Binary searchAlgorithms · Halve the range, probe the middle, repeat: with lo, mid and hi drawn on the array.Sets, relations and functionsDiscrete maths · Shade any set expression on a Venn diagram and test a relation for its properties.Proof by inductionDiscrete maths · Four worked proofs revealed one step at a time, and a broken one to diagnose.CombinatoricsDiscrete maths · An exact nPr and nCr calculator, and a Pascal’s triangle that shows its own addition rule.Boolean algebraDiscrete maths · The laws, De Morgan, and normal forms, with a truth-table generator built in.Finite-state machinesTheory · Build a DFA in a table, see it drawn, and run strings through it one symbol at a time.Domain theoryTheory · Why recursion needs least fixed points, and how CPOs, Scott continuity and powerdomains supply them.Truth table generatorTools · Expression in, truth table out: with DNF, CNF, a minimal form and LaTeX.Graph traversal visualiserTools · Draw a graph, then animate BFS, DFS and Dijkstra with the frontier shown.Recursion tree visualiserTools · Paste a recursive function or a recurrence and see its call tree and call count.Gradient descentML maths · Drag the starting point, set the learning rate, and watch it converge or blow up.Vectors and embeddingsML maths · Bend the plane with a 2×2 matrix and measure how close toy word vectors are.Softmax and cross-entropyML maths · Edit the logits and watch the probabilities, the loss and the gradient update live.AttentionML maths · Q, K and V for three tokens, a live score heatmap, and the weighted sum of values.Formatting a CS paper in LaTeXLaTeX · Page limits, \documentclass, front matter, theorem environments and the bibliography.Camera-ready checklistLaTeX · Fonts embedded, PDF/A, copyright form, source bundle, and why final versions get rejected.LaTeX templatesLaTeX · Where the official classes live, plus a minimal article template you can copy.AlgorithmsSection · Step-through visualisations of sorting, searching, recursion, graph traversal and Big-O growth, each with pseudocode that highlights the line being run.Discrete mathsSection · Sets, relations and functions, proof by induction, counting, and Boolean algebra, explained with worked examples and small interactive checkers.TheorySection · Finite-state machines, automata and the mathematical semantics of programming languages, explained from first principles.ML mathsSection · Gradient descent, vectors and embeddings, softmax and cross-entropy, and attention, each with a formula, a worked numeric example and a live version.ToolsSection · A truth-table generator with CNF, DNF and LaTeX output, a graph-traversal visualiser for BFS, DFS and Dijkstra, and a recursion-tree visualiser.LaTeXSection · How to format a CS conference or workshop paper in LaTeX, a camera-ready checklist, and a minimal template you can adapt.
Discrete maths

Permutations, combinations and Pascal’s triangle

Combinatorics is the mathematics of counting without listing. Two questions decide almost every basic counting problem: does the order of the choices matter, and can the same item be chosen twice? The calculator below answers all four combinations of those questions exactly.

Interactive: nPr / nCr calculator with enumeration, and Pascal’s triangleUpdated

Two rules everything is built on

The product rule. If a task is done in two stages, with mm ways to do the first and, for each of them, nn ways to do the second, there are m×nm \times n ways overall. A shirt (5 choices) and trousers (3 choices) make 1515 outfits.

The sum rule. If a task can be done in one of two ways that don’t overlap, with mm options for the first and nn for the second, there are m+nm + n options. If the ways do overlap, subtract the overlap: ∣A∪B∣=∣A∣+∣B∣−∣A∩B∣|A \cup B| = |A| + |B| - |A \cap B|. That correction, extended to more sets, is the inclusion–exclusion principle.

The four basic counts

Choose kk items from nn distinct ones.

RepetitionOrder mattersOrder does not matter
No repetitionP(n,k)=n!(n−k)!P(n,k) = \dfrac{n!}{(n-k)!}(nk)=n!k! (n−k)!\dbinom{n}{k} = \dfrac{n!}{k!\,(n-k)!}
Repetition allowednkn^k(n+k−1k)\dbinom{n+k-1}{k}

Order matters, no repetition: permutations

For the first position there are nn choices, then n−1n - 1, down to n−k+1n - k + 1. By the product rule that is n(n−1)⋯(n−k+1)=n!/(n−k)!n(n-1)\cdots(n-k+1) = n!/(n-k)!. Arranging all nn items is the special case k=nk = n: n!n! orderings. Gold, silver and bronze among 8 finalists: 8⋅7⋅68 \cdot 7 \cdot 6 = 336 podiums.

Order doesn’t matter, no repetition: combinations

Each unordered selection of kk items can be put in order in k!k! ways, so every combination is counted k!k! times among the permutations. Divide it out: (nk)=P(n,k)/k!\binom{n}{k} = P(n,k)/k!. A committee of 3 from 10 people: 720/6720 / 6 = 120. A five-card poker hand from a 52-card deck: (525)\binom{52}{5} = 2,598,960.

Order matters, repetition allowed: sequences

Each of the kk positions independently takes any of nn values: nkn^k. Eight-letter lowercase passwords: 26826^8 = 208,827,064,576. Binary strings of length kk: 2k2^k.

Order doesn’t matter, repetition allowed: multisets

Four scoops of ice cream from 3 flavours, where only how many of each flavour counts. The trick, called stars and bars, is to write a selection as kk stars (the scoops) separated by n−1n - 1 bars (the boundaries between flavours): ★★|★|★ means two of the first flavour, one of the second, one of the third. Every arrangement of kk stars and n−1n - 1 bars is one selection, so the count is (k+n−1k)\binom{k + n - 1}{k}. For the ice cream, (64)\binom{6}{4} = 15.

Counting calculator: choose k from n

RepetitionOrder mattersOrder does not matter
No repetition
Repetition allowed

Click a cell to list every selection it counts (when there are at most 120).

Which formula? Ask two questions about the objects you are counting. Would rearranging the chosen items give a different outcome? Then order matters. Can the same item appear more than once? Then repetition is allowed. A PIN is ordered with repetition; a lottery ticket is unordered without; a bag of sweets picked from a few kinds is unordered with.

Pascal’s triangle

Write the binomial coefficients in rows, row nn holding (n0),(n1),…,(nn)\binom{n}{0}, \binom{n}{1}, \dots, \binom{n}{n}. Each entry is the sum of the two above it:

(nk)=(n−1k−1)+(n−1k).\binom{n}{k} = \binom{n-1}{k-1} + \binom{n-1}{k}.

There is a one-line counting proof. Fix one particular item. A kk-element selection either includes it, and then the other k−1k-1 come from the remaining n−1n - 1 items, or it doesn’t, and then all kk come from the remaining n−1n - 1. The two cases don’t overlap, so the sum rule gives the identity. Click any entry below to see it applied.

Pascal’s triangle

Click any number to see where it comes from.

A few patterns to look for in the triangle:

  • Row sums are powers of 2. ∑k(nk)=2n\sum_k \binom{n}{k} = 2^n, because both sides count the subsets of an nn-element set.
  • Symmetry. (nk)=(nn−k)\binom{n}{k} = \binom{n}{n-k}: choosing which kk to take is the same as choosing which n−kn - k to leave.
  • The binomial theorem. Row nn holds the coefficients of (x+y)n=∑k=0n(nk)xkyn−k(x + y)^n = \sum_{k=0}^{n} \binom{n}{k} x^{k} y^{n-k}. Row 4 is 1, 4, 6, 4, 1, and (x+y)4=x4+4x3y+6x2y2+4xy3+y4(x+y)^4 = x^4 + 4x^3y + 6x^2y^2 + 4xy^3 + y^4.
  • Odd entries form a fractal. Turn on “Colour the odd numbers” and add rows: the pattern is Sierpiński’s triangle.

Counting in computer science

Counting is how you size a search space before deciding how to search it. There are 2n2^n subsets of nn items, n!n! orderings, and (n2)=n(n−1)/2\binom{n}{2} = n(n-1)/2 pairs, which is exactly the number of comparisons a naive “compare every pair” loop makes. The n!n! orderings also give the Ω(nlog⁡n)\Omega(n \log n) lower bound for comparison sorting explained on the sorting page. And because (nk)\binom{n}{k} appears in probability, “how likely is this hash collision?” and “how many test cases cover every pair of options?” are counting questions too.

References

  1. R. L. Graham, D. E. Knuth and O. Patashnik, Concrete Mathematics, 2nd ed., Addison-Wesley, 1994. Chapter 5 is about binomial coefficients.
  2. K. H. Rosen, Discrete Mathematics and Its Applications, 8th ed., McGraw-Hill, 2019. Chapter 6.
  3. “Stars and bars (combinatorics)”, Wikipedia.