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.Attention mechanismML 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.Boolean algebra calculatorTools · A Boolean expression simplifier that names the law used at every step.K-map solverTools · Fill in a Karnaugh map and see the groups, the minimal SOP and POS, and the essential terms.Logic gate simulatorTools · Wire up gates, flip the switches, and get the truth table and expression of your circuit.Regex to NFA converterTools · Type a regular expression and watch Thompson’s construction build its NFA, fragment by fragment.NFA to DFA converterTools · Enter an NFA or a regex and step through the subset construction, then minimise the DFA.DFA simulatorTools · Edit a DFA, run strings through it step by step, batch-test them and share the machine as a link.Regular expressions to automataTheory · Regex to NFA to DFA to minimal DFA, worked through on one example with every set shown.The halting problemTheory · Why no program can tell whether every program halts, with the paradox program played out.Pigeonhole principleDiscrete maths · n pigeons, k holes: why some hole gets ⌈n/k⌉, and the surprising things that follows from it.Dijkstra’s algorithmAlgorithms · Shortest paths with a priority queue: a worked table, a proof, and a graph you can redraw.Hash functionsAlgorithms · Keys in, buckets out: hash a word four ways, then watch chaining and probing handle collisions.Sorting algorithm visualizerTools · Up to seven sorts race on the same data, then step through any one of them line by line.LaTeX table generatorTools · Type or paste a table, merge cells, pick booktabs, and copy clean tabular code.Combination calculatorTools · Exact nCr with the cancelling shown, combinations with repetition, and a full list for small n.Permutation calculatorTools · nPr, nʳ, anagrams like MISSISSIPPI and round-table seatings, with exact working.AlgorithmsSection · Step-through visualisations of sorting, searching, recursion, graph traversal, Dijkstra’s algorithm, hash functions and Big-O growth, with pseudocode that follows along.Discrete mathsSection · Sets, relations and functions, proof by induction, counting, the pigeonhole principle and Boolean algebra, explained with worked examples and interactive checkers.TheorySection · Finite-state machines, regular expressions and automata, the halting problem, 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 · Free browser tools: truth tables, Boolean simplification, K-maps, logic gates, nCr and nPr, regex to NFA to DFA, sorting and graph visualisers, and LaTeX tables.LaTeXSection · How to format a CS conference or workshop paper in LaTeX, a camera-ready checklist, and a minimal template you can adapt.
Theory

Regular expressions to automata, from Thompson to minimal DFAs

Every regular expression can be turned into a finite automaton that recognises the same strings, and every finite automaton back into a regular expression. This page follows one expression, (a|b)*abb, all the way from text to a minimal DFA: Thompson’s construction, ε-closures, the subset construction and minimisation, with every set written out.

Interactive: Regex-to-NFA builder and subset-construction stepperUpdated

Three descriptions of the same languages

A regular expression describes a set of strings with three operations: union R∣SR \mid S, concatenation RSRS and the Kleene star R∗R^*, starting from single symbols, ε and ∅\varnothing. A DFA recognises a set of strings by reading them one symbol at a time with a fixed amount of memory. An NFA is like a DFA that may have several moves (or none) for a symbol, and ε-moves that read nothing; it accepts if some sequence of choices ends in an accepting state.

Kleene’s theorem (1956) A language is described by a regular expression if and only if it is recognised by a finite automaton. Together with Rabin and Scott’s result that NFAs and DFAs recognise the same languages, this means regular expressions, NFAs and DFAs are three notations for one class: the regular languages.

The theorem is proved by constructions that convert one notation into another, and those constructions are exactly what lexer generators and regular-expression engines run:

regex→ Thompson NFA with ε→ subsets DFA→ minimise minimal DFA.\text{regex} \xrightarrow{\ \text{Thompson}\ } \text{NFA with } \varepsilon \xrightarrow{\ \text{subsets}\ } \text{DFA} \xrightarrow{\ \text{minimise}\ } \text{minimal DFA}.

The opposite direction, from an automaton back to an expression, uses state elimination: remove states one at a time, labelling the edges that bypass them with regular expressions, until only a start and an accepting state remain.

Step 1: regular expression to NFA

Thompson’s construction builds an NFA for each sub-expression and glues them together. A symbol becomes two states joined by that symbol. Concatenation links one fragment’s end to the next one’s start with an ε-move. Union adds a new start state that branches by ε into both alternatives, and a new end state they both lead to. Star adds a back edge for repetition and a skip edge for zero repetitions.

For (a|b)*abb the result has 14 states and 16 transitions, 11 of them ε-moves. States 0–3 are the fragments for a and b, 4 and 5 are the union, 6 and 7 the star, and the three symbols a, b, b follow. The start state is 6 and the only accepting state is 13. The regex to NFA converter builds it one fragment at a time.

The construction is linear: each symbol or operator adds at most two states, so an expression of length mm gives at most 2m2m states. Every state has at most two outgoing transitions, and the single accepting state has none.

Step 2: ε-closures

Before reading any input, the NFA can already drift along ε-moves. The ε-closure of a set of states is everything reachable from it by ε-moves alone. From the start state 6:

ε-closure({6})={0,2,4,6,7,8}.\varepsilon\text{-closure}(\{6\}) = \{0, 2, 4, 6, 7, 8\}.

Reading a from any of those states is possible only from the states with an a-transition, which gives move(⋅,a)={1,9}\text{move}(\cdot, a) = \{1, 9\}; then the closure is taken again. Simulating an NFA is just this, repeated: keep the set of live states, and after each symbol replace it with the ε-closure of its moves.

Step 3: the subset construction

A DFA cannot be in several states at once, but it can have one state for each set of NFA states. The subset construction names each reachable set, starting from the closure of the start state, and fills in a table of moves until no new sets appear. For our example it finds 5 sets:

DFA stateNFA stateson aon b
→A{0, 2, 4, 6, 7, 8}BC
B{0, 1, 2, 4, 5, 7, 8, 9, 10}BD
C{0, 2, 3, 4, 5, 7, 8}BC
D{0, 2, 3, 4, 5, 7, 8, 11, 12}BE
*E{0, 2, 3, 4, 5, 7, 8, 13}BC

Only E contains the NFA’s accepting state 13, so it is the only accepting DFA state. In the worst case the construction can produce 2n2^n states from an nn-state NFA, but here, as usual, only a handful of the 2142^{14} possible subsets are reachable.

NFA to DFA converterThe subset construction, one transition at a time.

NFA

DFA being built

Pseudocode

  1. A ← ε-closure({start}); mark A as unprocessed
  2. while some DFA state T is unprocessed:
  3. for each symbol c:
  4. U ← ε-closure(move(T, c))
  5. if U is empty: no transition (dead state)
  6. else if U is new: name it and add it, unprocessed
  7. δ(T, c) ← U
  8. accepting DFA states: those containing an accepting NFA state

This step

Result

Step 4: minimisation

Two DFA states are equivalent when every string leads both to acceptance or both to rejection. Merging equivalent states never changes the language. Moore’s algorithm finds them by refining a partition:

  1. accepting vs not: {A, B, C, D} {E}
  2. round 1: {A, B, C} {D} {E}
  3. round 2: {A, C} {B} {D} {E}

Each round splits a group whenever two of its states move into different groups on the same symbol. When no group splits, each group is one state of the minimal DFA. Here states A and C are merged, leaving 4 states: one for each of “no progress”, “just read a”, “just read ab” and “just read abb”. That is the DFA you would design by hand for “ends in abb”.

The minimal DFA is unique up to the names of its states (the Myhill–Nerode theorem). So to test whether two regular expressions mean the same thing, minimise both DFAs and compare: an algorithm that decides regex equivalence.

Where this pipeline runs

  • Lexer generators such as lex and its descendants take a list of token patterns, build one NFA for all of them, determinise and minimise it, and emit a table-driven scanner that reads each character once.
  • Regular-expression engines choose different points on the pipeline. Some simulate the NFA directly (Thompson’s original approach, linear time in the input). Others build DFA states lazily as the input demands them, to avoid the exponential worst case. Backtracking engines, used where back-references are needed, can take exponential time on patterns such as (a|a)*b.
  • Verification and network filtering use the closure properties: intersect, complement and test for emptiness, all on DFAs.
Regex syntax in programming languages Programming-language “regexes” add features that go beyond regular languages. Back-references such as (a*)b\1 can describe {anban}\{a^n b a^n\}, which no finite automaton recognises. Character classes, +, ? and bounded repetition {2,5} are only shorthand, and stay regular.

Try it

References

  1. S. C. Kleene, “Representation of events in nerve nets and finite automata”, in Automata Studies, Princeton University Press, 1956.
  2. K. Thompson, “Programming techniques: Regular expression search algorithm”, Communications of the ACM 11(6), 1968. doi:10.1145/363347.363387
  3. M. O. Rabin and D. Scott, “Finite automata and their decision problems”, IBM Journal of Research and Development 3(2), 1959. doi:10.1147/rd.32.0114
  4. A. V. Aho, M. S. Lam, R. Sethi and J. D. Ullman, Compilers: Principles, Techniques, and Tools, 2nd ed., Pearson, 2006. Chapter 3.