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.
Theory

Finite-state machines and DFAs

A finite-state machine reads its input one symbol at a time and remembers only which of a fixed number of states it is in. That tiny amount of memory is enough for lexers, protocols, vending machines and regular expressions, and the limits it imposes are the first real result in the theory of computation.

Interactive: DFA builder and step-by-step string testerUpdated

The idea

Think of a turnstile. It is either locked or unlocked. A coin unlocks it; a push while unlocked lets you through and locks it again; a push while locked does nothing. Two states and a rule for each (state, input) pair describe it completely. A deterministic finite automaton, or DFA, is that idea made precise, with some states marked as accepting so that the machine can answer yes or no about the input it has read.

Definition

A DFA is a 5-tuple (Q,Σ,δ,q0,F)(Q, \Sigma, \delta, q_0, F) where

  • QQ is a finite set of states,
  • Σ\Sigma is a finite alphabet of input symbols,
  • δ:Q×Σ→Q\delta : Q \times \Sigma \to Q is the transition function,
  • q0∈Qq_0 \in Q is the start state, and
  • F⊆QF \subseteq Q is the set of accepting states.

The DFA accepts a string if, starting in q0q_0 and following δ\delta for each symbol in turn, it ends in a state of FF. The set of strings it accepts is its language.

“Deterministic” means there is exactly one next state for each state and symbol, so a given input always produces the same run. In diagrams, states are circles, accepting states have a double ring, the start state has an incoming arrow, and each transition is an arrow labelled with its symbol.

Build one and run it

The builder starts with a machine for “binary strings with an even number of 0s”. Edit the transition table, rename states, tick accepting states, or start from another preset. Then type a string and step through the run: the tape shows which symbol is being read and the diagram highlights the transition taken. A transition left as “— (dead)” sends the run to an implicit dead state that rejects whatever follows.

DFA builder and testerEdit the transition table, drag states to tidy the diagram, then run a string through it.

single characters, separated by commas

Pseudocode

  1. q ← start state
  2. for each symbol c of the input, left to right:
  3. if δ(q, c) is undefined: reject (fall into the dead state)
  4. q ← δ(q, c)
  5. accept if q is an accepting state, otherwise reject

Result

Run a string to see the verdict.

Checks

    Shortest accepted strings

    Test many strings

    Designing a DFA: decide what to remember

    The whole art is choosing the states. Ask: what is the least I need to remember about the input so far to finish the job? Each distinct thing you might need to remember becomes a state.

    • For “an even number of 0s”, only the parity of the 0s matters: two states.
    • For “ends in ab”, you need to know how much of ab you have just seen: nothing, a, or ab. Three states.
    • For “contains 101”, you track the longest prefix of 101 that the input currently ends with, plus a final “seen it” state that loops on everything.

    Worked example: binary multiples of 3

    Read a binary number from its most significant bit. If the value so far is vv, reading bit bb makes it 2v+b2v + b. To decide divisibility by 3 we only need v mod 3v \bmod 3, which takes 3 values. So the states are the remainders r0,r1,r2r_0, r_1, r_2, with

    δ(ri,b)=r(2i+b) mod 3,\delta(r_i, b) = r_{(2i + b) \bmod 3},

    start state r0r_0 and accepting state r0r_0. On input 110 (six): r0→1r1→1r0→0r0r_0 \xrightarrow{1} r_1 \xrightarrow{1} r_0 \xrightarrow{0} r_0, accept. On 111 (seven): r0→1r1→1r0→1r1r_0 \xrightarrow{1} r_1 \xrightarrow{1} r_0 \xrightarrow{1} r_1, reject. Load the “Binary multiple of 3” preset to check.

    Regular languages

    A language is regular if some DFA accepts it. Regular languages have useful closure properties:

    • Complement. Swap accepting and non-accepting states (after filling in any missing transitions).
    • Intersection and union. Run two DFAs side by side. The product construction uses pairs of states (p,q)(p, q) and moves both components at once; it accepts when both (for intersection) or either (for union) would.
    • Concatenation and repetition (Kleene star) are also regular, though the construction goes through nondeterministic automata.

    An NFA may have several possible next states, or none, and accepts if any run ends in an accepting state. NFAs are often far smaller and easier to design, but Rabin and Scott showed in 1959 that they recognise exactly the same languages: the subset construction builds a DFA whose states are sets of NFA states. The price can be steep, up to 2n2^n DFA states for an nn-state NFA.

    Kleene’s theorem completes the picture: regular expressions, NFAs and DFAs all describe the same class of languages. This is why a regular-expression engine can compile a pattern into an automaton and match text in a single pass.

    What a DFA cannot do

    A DFA with kk states remembers at most kk different things about the past. So it cannot recognise a language that requires unbounded counting. The standard example is

    L={0n1n:n≥0}={ε,01,0011,000111,… }.L = \{ 0^n 1^n : n \ge 0 \} = \{\varepsilon, 01, 0011, 000111, \dots\}.

    Suppose a DFA with kk states accepted LL. Feed it 00,01,…,0k0^0, 0^1, \dots, 0^k: that is k+1k + 1 strings and only kk states, so by the pigeonhole principle two of them, 0i0^i and 0j0^j with i≠ji \ne j, leave it in the same state. From then on it cannot tell them apart, so it treats 0i1i0^i 1^i and 0j1i0^j 1^i the same way. But the first is in LL and the second isn’t. Contradiction: no DFA accepts LL.

    That argument is a special case of the Myhill–Nerode theorem, which says a language is regular exactly when it has finitely many “distinguishable” classes of prefixes, and that the number of classes is the size of the smallest DFA for it. Balanced parentheses, palindromes and correctly nested HTML are all non-regular for the same reason. Recognising them needs a stack, which leads to pushdown automata and context-free grammars.

    Minimisation

    Two states are equivalent if no input string can tell them apart: from either one, exactly the same strings lead to acceptance. Merging equivalent states (and removing unreachable ones) gives the unique smallest DFA for the language. The classic algorithm starts by splitting states into accepting and non-accepting, then keeps refining the groups whenever two states in a group go to different groups on some symbol.

    Where finite-state machines are used

    • Lexical analysis. A compiler’s first phase turns characters into tokens (identifiers, numbers, keywords) with a DFA generated from regular expressions.
    • Protocols. TCP connections move through named states such as LISTEN, SYN-SENT and ESTABLISHED.
    • User interfaces and games. A form that can be editing, submitting, failed or done is a state machine; writing it as one makes impossible states impossible.
    • Hardware. Sequential circuits are finite-state machines built from flip-flops and logic gates, designed with Boolean algebra.

    References

    1. 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
    2. A. Nerode, “Linear automaton transformations”, Proceedings of the American Mathematical Society 9(4), 1958. doi:10.1090/S0002-9939-1958-0135681-9
    3. M. Sipser, Introduction to the Theory of Computation, 3rd ed., Cengage, 2012. Chapter 1.
    4. J. E. Hopcroft, R. Motwani and J. D. Ullman, Introduction to Automata Theory, Languages, and Computation, 3rd ed., Pearson, 2006.