<-- go back

Theory of Computation Notes

 — 22 min read

Introduction


These are my notes on theory of computation.

Mathematical Notions and Terminology


This section covers the fundamental building blocks.

Sets

A set is a group of objects. It can contain any type of object like numbers, symbols, and other sets. The objects in a set are called elements or members. In a set, the ordering of elements and repetition doesn't matter.

For example:

S={7,21,57}S = \{7, 21, 57\}

Definitions

  • \in and \notin means membership and nonmembership
    • 7{7,21,57}7 \in \{7, 21, 57\} and 8{7,21,57}8 \notin \{7, 21, 57\}
  • ABA \subseteq B is read as AA is a subset of BB. It means that all elements of AA is also in BB.
  • ABA \subsetneq B is read as AA is a proper subset of BB. It means that all elements of AA is also in BB, BUT AA is not exactly the same as BB, that is, AA has fewer elements.
  • {nrule about n}\{n \mid \text{rule about }n\} describes a set containing elements according to a rule.
  • ABA \cup B describes the union of two sets AA and BB, combining all elements from both into a single set.
  • ABA \cap B describes the intersection of two sets AA and BB, containing only the elements common to both.
  • A\overline{A} is the complement of A, containing all elements not in AA.
  • P(A)\mathcal{P}(A) is the power set of AA, containing all possible subsets of AA, including the empty set and AA itself.
  • A×BA \times B is the Cartesian product or cross product of AA and BB, is the set containing all ordered pairs (a,b)(a, b) where the first element aAa \in A and the second element bBb \in B. Read as AA cross BB.
    • Cartesian products can involve more than just pairs: A1×A2××An={(a1,a2,,an)aiAi for each i{1,2,,n}}A_1 \times A_2 \times \cdots \times A_n = \{(a_1, a_2, \dots, a_n) \mid a_i \in A_i \text{ for each } i \in \{1, 2, \dots, n\}\}
  • A×A××Ak=Ak\underbrace{A \times A \times \cdots \times A}_{k} = A^k is a Cartesian product of a set with itself.

Examples

  • Natural numbers: N\mathbb{N} = {1, 2, 3, ...}
  • Integers: Z\mathbb{Z} = {..., -2, -1, 0, 1, 2, ...}
  • Empty set: \varnothing
  • Singleton set: a set with one element, e.g., {a}\{a\}
  • Unordered pair: a set with two elements, e.g., {a,b}\{a, b\}
  • {nn=m2 for some mN}\{n \mid n=m^2 \text{ for some } m\in\mathbb{N}\}: the set of perfect squares
  • If A={0,1}A = \{0, 1\}, then P(A)={,{0},{1},{0,1}}\mathcal{P}(A) = \{\varnothing, \{0\}, \{1\}, \{0, 1\}\}.
  • {(0,0),(0,1),(1,0),(1,1)}\{(0, 0), (0, 1), (1, 0), (1, 1)\} is the set of all ordered pairs whose elements are 0s and 1s.
  • Let A={1,2}A = \{1, 2\} and B={x,y}B = \{x, y\}
    • A×B={(1,x),(1,y),(2,x),(2,y)}A \times B = \{(1, x), (1, y), (2, x), (2, y)\}
  • N2=N×N={(i,j)i,j1}\mathbb{N}^2 = \mathbb{N} \times \mathbb{N} = \{(i,j) \mid i,j \geq 1\}

Sequences and Tuples

A sequence is a list of objects in some order designated with parentheses. In sequences, order and repetition matters.

For example:

(7,21,57)(57,7,21)(7,7,21,57)(7,21,57)(7, 21, 57) \neq (57, 7, 21) \\ (7, 7, 21, 57) \neq (7, 21, 57)

However:

{7,21,57}={7,21,7,57}\{7, 21, 57\} = \{7, 21, 7, 57\}
  • Finite sequences are called tuples.
  • A kk-tuple is a sequence with kk elements. (7,21,57)(7, 21, 57) is a 3-tuple.
  • A 2-tuple is called an ordered pair.

Functions and Relations

A function is a thing that takes an input and produces and output. Similarly, given f(a)=bf(a) = b, ff is a mapping, that is, ff maps aa to bb. The same input always yields the same output.

  • Domain: the set of all possible inputs of a function
  • Range: the set of all possible outputs of a function, also called the codomain
  • Given a domain DD and a range RR, f:DRf : D \to R, is read as ff maps DD to RR. This is called a function notation or mapping notation. Writing this function notation is also said to be "defining the codomain".
  • A function is onto or surjective if all elements in the output set RR is matched or mapped by at least one element from the input set DD. This means the function reaches every possible output. The codomain must be defined in order to determine if a function is onto or not.
  • A binary relation R is reflexive if for every xx, xRxxRx
  • A binary relation R is symmetric if for every xx and yy, xRyxRy implies yRxyRx
  • A binary relation R is transitive if for every xx, yy, and zz, xRyxRy and yRzyRz implies xRzxRz
  • A binary relation R is an equivalence relation if RR is reflexive, symmetric, AND transitive.

Examples

  • f:RRf : \mathbb{R} \to \mathbb{R} defined by f(x)=xf(x) = x is onto.
  • f:R[0,)f : \mathbb{R} \to [0, \infty) defined by f(x)=xf(x) = x is NOT onto.

Graphs

  • An undirected graph or graph is a set of points with lines connecting (or not) the points.
  • The points are referred to as vertices or nodes.
  • The lines are called edges.
  • The degree of a node refers to the number of edges at that node.
  • A self-loop is an edge from a node to itself.
  • Given a graph GG containing nodes ii and jj, the pair (i,j)(i,j) represents the edge connecting ii and jj. The order of the pair doesn't matter in an undirected graph, i.e., (i,j)(i,j) and (j,i)(j,i) is the same edge. Another way to describe these undirected edges with unordered pairs is with set notation: {i,j}\{i,j\}
  • Given a graph GG, VV being the set of nodes of GG, and EE being the set of edges of GG, G=(V,E)G = (V, E). This can be used to formally describe graphs.
  • A labeled graph is a graph with labels on nodes and/or edges.
  • Given a graph GG, a graph HH is considered to be a subgraph of GG if HH is formed by a subset of the vertices and edges of GG.
  • A path is a sequence of nodes connected by edges in a graph.
  • A simple path is a path that doesn't repeat any nodes.
  • A graph is connected if every two nodes in that graph have a path between them.
  • A cycle is a path that starts and ends at the same vertex.
  • A simple cycle is one that contains at least three nodes and repeats only the first and last nodes.
  • A tree is a graph that is connected and has no simple cycles.
  • The leaves of a tree are nodes with a degree 1.
  • A directed graph uses arrows instead of lines. This set of edges in directed graphs have ordered pairs.
  • Outdegree refers to the number of arrows pointing out from a node.
  • Indegree refers to the number of arrows pointing into a node.
  • A directed path refers to a path in which all the arrows point in the same direction as it steps.
  • A directed graph is strongly connected if a directed path connects every two nodes.

Strings and Languages

An alphabet is a nonempty finite set whose members are called symbols.

Examples of alphabets:

Σ1={0,1}Σ2={a,b,c,,z}Γ={0,1,x,y,z}\begin{align*} \Sigma_1 &= \{0, 1\} \\ \Sigma_2 &= \{\text{a}, \text{b}, \text{c}, \ldots, \text{z}\} \\ \Gamma &= \{0, 1, \text{x}, \text{y}, \text{z}\} \end{align*}

A string over an alphabet is a finite sequence of symbols from that alphabet. For example, given Σ1\Sigma_1 from above, then "01001" is a string over Σ1\Sigma_1. Another example, given Σ2\Sigma_2 from above, "abracadabra" is a string over Σ2\Sigma_2.

  • w|w| is the length or number of symbols in the string ww over Σ\Sigma.
  • A string of length zero is called the empty string denoted by ϵ\epsilon. It plays the role of a 0 in a number system. For example: if w="hello"w="\text{hello}", then wϵ=ϵw="hello"w \cdot \epsilon = \epsilon \cdot w = "\text{hello}". The \cdot here indicates string concatenation.
  • If string ww has length nn, then w=w1w2wnw = w_1w_2\cdots w_n where each wiΣw_i\in \Sigma. For example: w="cat"w = "\text{cat}" then w1="c"w_1 = "\text{c}", w2="a"w_2 = "\text{a}", and w3="t"w_3 = "\text{t}".
  • wRw^\mathcal{R} is the reverse of ww, i.e., wnwn1w1w_nw_{n-1}\cdots w_1
  • wkw^k concatenates a string with itself kk times, e.g., xxxk\underbrace{xx\cdots x}_k
  • Lexicographic order is a way of ordering strings, e.g., a dictionary.
  • Shortlex order or string order orders strings with shorter strings always coming first. E.g., the string ordering of all strings over the alphabet {0,1}\{0, 1\} is (ϵ,0,1,00,01,10,11,000,)(\epsilon, 0, 1, 00, 01, 10, 11, 000, \ldots).
  • A string xx is considered to be a prefix of string yy if a string zz exists where xz=yxz = y. In other words, string xx is a prefix of another string yy if you can append some string zz to xx to get yy. E.g., let x="pre"x = "\text{pre}" and y="prefix"y = "\text{prefix}", then z="fix"z = "\text{fix}".
  • A string xx is a proper prefix of string yy if xx is a prefix of yy and xyx \neq y. This means zz must be non-empty.
  • A language is a set of strings formed from an alphabet.
  • A prefix-free language is a language where no strings in the language is a proper prefix of any other string in the language. E.g., L={"a","ab","abc"}L = \{"\text{a}", "\text{ab}", "\text{abc}"\} is NOT prefix-free because "a" is a proper prefix of both "ab" and "abc". But, L={"a","bb","cba"}L' = \{"\text{a}", "\text{bb}", "\text{cba}"\} is considered to be prefix-free.

Boolean Logic

Boolean logic is a mathematical system based on the values TRUE and FALSE represented as 1 and 0.

Boolean Operations

  • Negation (NOT): The operation that inverts a Boolean value.

    • ¬0=1\neg 0 = 1
    • ¬1=0\neg 1 = 0
  • Conjunction (AND): The operation that results in 1 if both operands are 1.

    • 00=00 \land 0 = 0
    • 01=00 \land 1 = 0
    • 10=01 \land 0 = 0
    • 11=11 \land 1 = 1
  • Disjunction (OR): The operation that results in 1 if at least one operand is 1.

    • 00=00 \lor 0 = 0
    • 01=10 \lor 1 = 1
    • 10=11 \lor 0 = 1
    • 11=11 \lor 1 = 1
  • Exclusive OR (XOR): The operation that results in 1 if one operand is 1 and the other is 0.

    • 00=00 \oplus 0 = 0
    • 01=10 \oplus 1 = 1
    • 10=11 \oplus 0 = 1
    • 11=01 \oplus 1 = 0
  • Equality (XNOR): The operation that results in 1 if both operands are the same.

    • 00=10 \leftrightarrow 0 = 1
    • 01=00 \leftrightarrow 1 = 0
    • 10=01 \leftrightarrow 0 = 0
    • 11=11 \leftrightarrow 1 = 1
  • Implication: The operation that results in 0 only if the first operand is 1 and the second is 0.

    • 00=10 \rightarrow 0 = 1
    • 01=10 \rightarrow 1 = 1
    • 10=01 \rightarrow 0 = 0
    • 11=11 \rightarrow 1 = 1

Boolean Identities

Boolean operations can be expressed in terms of AND and NOT:

  • PQ=¬(¬P¬Q)P \lor Q = \neg(\neg P \land \neg Q)
  • PQ=¬PQP \rightarrow Q = \neg P \lor Q
  • PQ=(PQ)(QP)P \leftrightarrow Q = (P \rightarrow Q) \land (Q \rightarrow P)
  • PQ=¬(PQ)P \oplus Q = \neg(P \leftrightarrow Q)

Distributive Law

Boolean logic follows distributive laws similar to arithmetic:

  • P(QR)=(PQ)(PR)P \land (Q \lor R) = (P \land Q) \lor (P \land R)
  • P(QR)=(PQ)(PR)P \lor (Q \land R) = (P \lor Q) \land (P \lor R)

Theory of Computation


There three are central areas of the theory of computation:

  • Automata theory
  • Computability theory
  • Complexity theory

This question connects all three areas:

What are the fundamental capabilities and limitations of computers?

Automata Theory


Automata theory is about the definitions and properties of mathematical properties of computation.

DFA

DFA (deterministic finite automata) is a state machine with states (nodes) and transitions (edges) labeled with symbols.

DFA Formal Definition

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

  1. QQ is a finite set of states
  2. Σ\Sigma is a finite alphabet
  3. δ:Q×ΣQ\delta : Q \times \Sigma \to Q is the transition function
  4. q0Qq_0 \in Q is the start state
  5. FQF \subseteq Q is the set of accepting states

If AA is the set of all strings that machine MM accepts, we say that AA is the language of machine MM and write L(M)=AL(M) = A. We say that MM recognizes AA or that MM accepts AA.

Formal Definition of Computation

A language is called a regular language if some finite automaton recognizes it.

Regular Operations

Let AA and BB be languages. We define regular operations union, concatenation, and star:

  • Union: AB={xxA or xB}A \cup B = \{x \mid x \in A \text{ or } x \in B\}
  • Concatenation: AB={xyxA and yB}A \circ B = \{ xy \mid x \in A \text{ and } y \in B \}
  • Star: A={x1x2xkk0 and each xiA}A^* = \{ x_1 x_2 \ldots x_k \mid k \geq 0 \text{ and each } x_i \in A \}, the empty string ϵ\epsilon is always a member of AA^* no matter what AA is

NFA

NFA (non-deterministic finite automata) is a type of state machine where the machine may transition into multiple possible states from a given state and input symbol. It can also have transitions that occur without consuming any input called ϵ\epsilon-transitions.

Differences Between DFA and NFA

  • Every state of a DFA always has exactly one exiting transition arrow for each symbol in the alphabet.
  • In an NFA, a state may have zero, one, or many exiting arrows for each alphabet symbol.
  • NFAs can have ϵ\epsilon-transitions. In particular, a state with only one transition, that being an ϵ\epsilon-transition, can split into two copies, one that follows the exiting ϵ\epsilon-transition and one staying at the current state.

NFA Formal Definition

Similar to DFA except the transition function takes a state and an input symbol or the empty string and produces the set of possible next states.

  1. QQ is a finite set of states
  2. Σ\Sigma is a finite alphabet
  3. δ:Q×ΣϵP(Q)\delta : Q \times \Sigma_\epsilon \to \mathcal{P}(Q) is the transition function
  4. q0Qq_0 \in Q is the start state
  5. FQF \subseteq Q is the set of accepting states

Union Operation Proof

There are two versions of this proof, one that doesn't use nondeterminism and one that does.

Deterministic Version

Let DFA M1=(Q1,Σ,δ1,q1,F1)M_1 = (Q_1, \Sigma, \delta_1, q_1, F_1) recognize A1A_1.

Let DFA M2=(Q2,Σ,δ2,q2,F2)M_2 = (Q_2, \Sigma, \delta_2, q_2, F_2) recognize A2A_2.

Construct DFA M=(Q,Σ,δ,q0,F)M = (Q, \Sigma, \delta, q_0, F) to recognize A1A2A_1 \cup A_2.

  1. Q={(r1,r2)r1Q1r2Q2}Q = \{(r_1, r_2) \mid r_1 \in Q_1 \land r_2 \in Q_2\}. This set is the Cartesian product of sets Q1Q_1 and Q2Q_2 and is written Q1×Q2Q_1 \times Q_2. It is the set of all pairs of states, the first from Q1Q_1 and the second from Q2Q_2.
  2. Σ\Sigma, the alphabet, is the same as in M1M_1 and M2M_2.
  3. For each (r1,r2)Q(r_1, r_2) \in Q and aΣa \in \Sigma, let δ((r1,r2),a)=(δ1(r1,a),δ2(r2,a))\delta((r_1,r_2), a) = (\delta_1(r_1, a), \delta_2(r_2, a)).
  4. q0q_0 is the pair (q1,q2)(q_1, q_2).
  5. FF is the set of pairs in which either member is an accept state of M1M_1 or M2M2: F={(r1,r2)r1F1r2F2}F = \{(r_1, r_2) \mid r_1 \in F_1 \lor r_2 \in F_2\}. This can be also written as F=(F1×Q2)(Q1×F2)F = (F_1 \times Q_2) \cup (Q_1 \times F_2).
/theory-of-computation-union-1.png
/theory-of-computation-union-2.png
/theory-of-computation-union-3.png
/theory-of-computation-union-4.png
/theory-of-computation-union-5.png

Nondeterministic Version

Let N1=(Q1,Σ,δ1,q1,F1)N_1 = (Q_1, \Sigma, \delta_1, q_1, F_1) recognize A1A_1.

Let N2=(Q2,Σ,δ2,q2,F2)N_2 = (Q_2, \Sigma, \delta_2, q_2, F_2) recognize A2A_2.

Construct NFA N=(Q,Σ,δ,q0,F)N = (Q, \Sigma, \delta, q_0, F) to recognize A1A2A_1 \cup A_2.

  1. Q={q0}Q1Q2Q = \{q_0\} \cup Q_1 \cup Q_2
  2. q0q_0 is the new start state of NN
  3. F=F1F2F = F_1 \cup F_2
  4. Define δ\delta so that for any qQq \in Q and any aΣϵa \in \Sigma_\epsilon:
δ(q,a)={δ1(q,a)qQ1δ2(q,a)qQ2{q1,q2}q=q0a=ϵq=q0aϵ\delta(q, a) = \begin{cases} \delta_1(q, a) & q \in Q_1 \\ \delta_2(q, a) & q \in Q_2 \\ \{q_1, q_2\} & q = q_0 \land a = \epsilon \\ \varnothing & q = q_0 \land a \neq \epsilon \end{cases}

Concatenation Operation Proof

Let N1=(Q1,Σ,δ1,q1,F1)N_1 = (Q_1, \Sigma, \delta_1, q_1, F_1) recognize A1A_1.

Let N2=(Q2,Σ,δ2,q2,F2)N_2 = (Q_2, \Sigma, \delta_2, q_2, F_2) recognize A2A_2.

Construct NFA N=(Q,Σ,δ,q0,F)N = (Q, \Sigma, \delta, q_0, F) to recognize A1A2A_1 \circ A_2.

  1. Q=Q1Q2Q = Q_1 \cup Q_2
  2. Σ=Σ1Σ2\Sigma = \Sigma_1 \cup \Sigma_2
  3. q0=q1q_0 = q_1
  4. F=F2F = F_2
  5. Define δ\delta so that for any qQq \in Q and any aΣϵa \in \Sigma_\epsilon:
δ(q,a)={δ1(q,a)qQ1qF1δ1(q,a)qF1aϵδ1(q,a){q2}qF1a=ϵδ2(q,a)qQ2\delta(q, a) = \begin{cases} \delta_1(q, a) & q \in Q_1 \land q \notin F_1 \\ \delta_1(q, a) & q \in F_1 \land a \neq \epsilon \\ \delta_1(q, a) \cup \{q_2\} & q \in F_1 \land a = \epsilon \\ \delta_2(q, a) & q \in Q_2 \end{cases}

Kleene Star Operation Proof

Let N1=(Q1,Σ,δ1,q1,F1)N_1 = (Q_1, \Sigma, \delta_1, q_1, F_1) recognize A1A_1.

Construct NFA N=(Q,Σ,δ,q0,F)N = (Q, \Sigma, \delta, q_0, F) to recognize A1A_1^*.

  1. Q={q0}Q1Q = \{q_0\} \cup Q_1. The states of NN are also the states of N1N_1 plus a newly added state.
  2. The state q0q_0 (the newly added state) is the new start state.
  3. F={q0}F1F = \{q_0\} \cup F_1. The newly added state is then added to the set of old accept states.
  4. Define δ\delta so that for any qQq \in Q and any aΣϵa \in \Sigma_\epsilon:
δ(q,a)={δ1(q,a)qQ1qF1δ1(q,a)qF1aϵδ1(q,a){q1}qF1a=ϵ{q1}q=q0a=ϵq=q0aϵ\delta(q,a) = \begin{cases} \delta_1(q,a) & q \in Q_1 \land q \notin F_1 \\ \delta_1(q,a) & q \in F_1 \land a \neq \epsilon \\ \delta_1(q,a) \cup \{q_1\} & q \in F_1 \land a = \epsilon \\ \{q_1\} & q = q_0 \land a = \epsilon \\ \varnothing & q = q_0 \land a \neq \epsilon \end{cases}

Reverse Operation Proof

Let N1=(Q1,Σ,δ1,q1,F1)N_1 = (Q_1, \Sigma, \delta_1, q_1, F_1) that recognizes A1A_1.

Construct NFA N=(Q,Σ,δ,q0,F)N = (Q, \Sigma, \delta, q_0, F) to recognize A1RA_1^R.

  1. Q=Q1{q0}Q = Q_1 \cup \{q_0\}
  2. q0q_0 is the new start state
  3. F={q1}F = \{q_1\}
  4. For any aΣϵa \in \Sigma_\epsilon, δ(r,a)q\delta(r, a) \to q if δ1(q,a)r\delta_1(q, a) \to r and δ(q0,ϵ)F1\delta(q_0, \epsilon) \to F_1

Perfect Shuffle Proof

Let DA=(QA,Σ,δA,q0,A,FA)D_A = (Q_A, \Sigma, \delta_A, q_{0,A}, F_A) recognize AA.

Let DB=(QB,Σ,δB,q0,B,FB)D_B = (Q_B, \Sigma, \delta_B, q_{0,B}, F_B) recognize BB.

Let S={ww=a1b1a2b2akbk where a1a2akA and b1b2bkB}S = \{w \mid w = a_1b_1a_2b_2 \cdots a_kb_k \text{ where } a_1a_2\cdots a_k \in A \text{ and } b_1b_2\cdots b_k \in B\}

Construct DFA N=(Q,Σ,δ,q0,F)N = (Q, \Sigma, \delta, q_0, F) to recognize SS.

  1. Q=QA×QB×{A,B}Q = Q_A \times Q_B \times \{A, B\}
  2. q0=(q0,A,q0,B,A)q_0 = (q_{0,A},q_{0,B}, A)
  3. F=FA×FB×{A,B}F = F_A \times F_B \times \{A, B\}
  4. Define δ\delta so that for any qQAq \in Q_A, any rQBr \in Q_B, and any aΣa \in \Sigma:
δ((q,r,A),a)=(δA(q,a),r,B)δ((q,r,B),a)=(q,δB(r,a),A)\delta((q, r, A), a) = (\delta_A(q, a), r, B) \\ \delta((q, r, B), a) = (q, \delta_B(r, a), A)

NFA to DFA

Given an NFA, there is an equivalent DFA.

Let NFA N=(Q,Σ,δ,q0,F)N = (Q, \Sigma, \delta, q_0, F) recognize AA.

Construct DFA M=(Q,Σ,δ,q0,F)M = (Q', \Sigma, \delta', q_0', F') to recognize AA.

Assuming No Epsilon Transitions

  1. Q=P(Q)Q' = \mathcal{P}(Q), note that P(Q)=2Q|\mathcal{P}(Q)| = 2^{|Q|} where Q|Q| is the size of QQ
  2. For RQR \in Q' and aΣa \in \Sigma,
δ(R,a)=rRδ(r,a)\delta'(R, a) = \bigcup_{r \in R}\delta(r, a)
  1. q0={q0}q_0' = \{q_0\}
  2. F={RQR contains an accept state of N}F' = \{R \in Q' \mid R \text{ contains an accept state of } N\}

Assuming Epsilon Transitions

i am lost, this proof omg

NFA to DFA Example

Given the above example NFA N=((q0,q1,q2),{a,b},δ,q0,{q0})N = ((q_0, q_1, q_2), \{a, b\}, \delta, q_0, \{q_0\}) (ϵ\epsilon is implicitly in the language), we construct a DFA M=(Q=P(Q),{a,b},δ,q0,F)M = (Q' = \mathcal{P}(Q), \{a, b\}, \delta', q_0', F') in the following:

  1. Build NFA δ\delta table.
aabbϵ\epsilon
q0q_0{q0,q1}\{q_0, q_1\}\varnothing{q1}\{q_1\}
q1q_1{q2}\{q_2\}{q0}\{q_0\}\varnothing
q2q_2\varnothing{q0,q2}\{q_0, q_2\}{q0}\{q_0\}
  1. Define initial state to be the states reachable from q0q_0 on epsilon transitions: q0=(q0,q1)q_0' = (q_0, q_1).
  2. Draw MM with initial state q0=(q0,q1)q_0' = (q_0, q_1). And, the state \varnothing self loops when reading any symbol in the alphabet.
  3. Draw transitions whereafter the first transition, look to the epsilon column and, if it's not an empty set (epsilon column entry), include it in the tuple.
  4. Define accepting states to be the states containing q0q_0.
/theory-of-computation-nfa2dfa-2.png
/theory-of-computation-nfa2dfa-3.png
/theory-of-computation-nfa2dfa-4.png
/theory-of-computation-nfa2dfa-5.png
/theory-of-computation-nfa2dfa-6.png
/theory-of-computation-nfa2dfa-7.png
/theory-of-computation-nfa2dfa-8.png

Regular Expressions

RR is a regular expression if RR is

  1. aa for some aa in the alphabet Σ\Sigma
  2. ϵ\epsilon, representing the language containing a single string—the empty string
  3. \varnothing, representing the language containing no strings
  4. (R1R2)(R_1 \cup R_2) where R1R_1 and R2R_2 are regular expressions
  5. (R1R2)(R_1 \circ R_2) where R1R_1 and R2R_2 are regular expressions
  6. (R1)(R_1^*) where R1R_1 is a regular expression

Regex Examples

Given Σ={0,1}\Sigma = \{0, 1\}, in the format {ww  <condition>}\{w \mid w \; \text{<condition>}\}:

  • ww contains a single 1: 0100^*10^*, star means zero or more
  • ww has at least one 1: Σ1Σ\Sigma^*1\Sigma^*, Σ\Sigma means any symbol in the alphabet
  • ww contains the substring 001: Σ001Σ\Sigma^*001\Sigma^*
  • every 0 in ww is followed by at least one 1: 1(01+)1^*(01+)^*, plus means one or more
  • ww is a string of even length: (ΣΣ)(\Sigma\Sigma)^*, a string of 0 length is even
  • the length of ww is a multiple of 3: (ΣΣΣ)(\Sigma\Sigma\Sigma)^*
  • the language {01,10}\{01, 10\}: 011001 \cup 10
  • ww starts and ends with the same symbol: 0Σ01Σ1010\Sigma^*0 \cup 1\Sigma^*1 \cup 0 \cup 1
  • (0ϵ)1=011(0 \cup \epsilon)1^* = 01^* \cup 1^*, 0ϵ0 \cup \epsilon describes {0,ϵ}\{0, \epsilon\}, and the concatenation adds either 0 or ϵ\epsilon before every string in 11^*
  • (0ϵ)(1ϵ)={ϵ,0,1,01}(0 \cup \epsilon)(1 \cup \epsilon) = \{\epsilon, 0, 1, 01\}, it's kind of like the FOIL method
  • 1=1^*\varnothing = \varnothing, concatenating the empty set to any set yields the empty set
  • ={ϵ}\varnothing^* = \{\epsilon\}

Let RR be any expression, we have the following identities:

  • R=RR \cup \varnothing = R, adding the empty language to any other language will not change it
  • Rϵ=RR \circ \epsilon = R, joining any string to the empty string will not change it
  • RϵR \cup \epsilon may not equal RR, e.g., if R=0R = 0, then L(R)={0}L(R) = \{0\} but L(Rϵ)={0,ϵ}L(R \cup \epsilon) = \{0, \epsilon\}
  • RR \circ \varnothing may not equal RR, e.g., if R=0R = 0, then L(R)={0}L(R) = \{0\} but L(R)=L(R \circ \varnothing) = \varnothing

Regex to NFA

Let regular expression RR describe some language AA.

Convert RR into an NFA recognizing AA.

There are six cases:

  1. R=a,aΣ,L(R)={a}R = a, a \in \Sigma, L(R) = \{a\}
  2. R=ϵ,L(R)={ϵ}R = \epsilon, L(R) = \{\epsilon\}
  3. R=,L(R)=R = \varnothing, L(R) = \varnothing
  4. R=R1R2R = R_1 \cup R_2, see nondeterministic version of the union operation proof
  5. R=R1R2R = R_1 \circ R_2, see concatenation operation proof
  6. R=R1R = R_1^*, see kleene star operation proof
/theory-of-computation-regex2nfa-1.png
/theory-of-computation-regex2nfa-2.png
/theory-of-computation-regex2nfa-3.png

DFA to Regex

Let a DFA recognize a language AA.

Convert the DFA into equivalent regular expressions in following steps:

Step 1. Convert DFA into a GNFA (generalized nondeterministic finite automaton)

Let DFA D1=(Q1,Σ,δ1,q1,F1)D_1 = (Q_1, \Sigma, \delta_1, q_1, F_1) recognize AA.

We construct GNFA G=(Q,Σ,δ,qs,F)G = (Q', \Sigma, \delta', q_s', F'):

  1. Q=Q{qs,qf}Q' = Q \cup \{q_s', q_f'\}
  2. Σ\Sigma remains the same
  3. qsq_s' is the new start state
  4. F={qf}F = \{q_f'\}
  5. Define δ\delta' so that for any qQq \in Q' and any aΣϵa \in \Sigma_\epsilon:
δ(q,a)={{q1}q=qsa=ϵ{qf}qF1a=ϵδ1(q,a)qQ1aΣotherwise\delta'(q,a) = \begin{cases} \{q1\} & q = q_s' \land a = \epsilon \\ \{q_f'\} & q \in F_1 \land a = \epsilon \\ \delta_1(q, a) & q \in Q_1 \land a \in \Sigma \\ \varnothing & \text{otherwise} \end{cases}

This construction does not explicitly redefine the transitions into regular expressions over Σ\Sigma. We just do that in our heads.

Step 2. Convert GNFA into regular expressions

There are two rules when collapsing a GNFA into a 2-state:

/theory-of-computation-dfa2regex-1.png
/theory-of-computation-dfa2regex-2.png

DFA to Regex Example

/theory-of-computation-dfa2regex-3.png
/theory-of-computation-dfa2regex-4.png
/theory-of-computation-dfa2regex-5.png
/theory-of-computation-dfa2regex-6.png
/theory-of-computation-dfa2regex-7.png
/theory-of-computation-dfa2regex-8.png
/theory-of-computation-dfa2regex-9.png
/theory-of-computation-dfa2regex-10.png

Computability Theory


The main objective of computability theory is to classify problems as solvable or unsolvable

Complexity Theory


The main objective of complexity theory is to classify problems as easy or hard.

An important question capturing this idea:

What makes some problems computationally hard and others easy?

<-- go back