Regular and Context-Free Languages Find the RegEx for the given DFA Finite Automata
Every regular language is context-free. For each character in the input alphabet, a finite automaton must have a transition out of
every node labelled with that character: True for all deterministic finite automata.
If G is a context-free grammar, there may be two different left-most
derivations to produce a given string. (an ambiguous grammar) A transition function for an NFA maps a state and input character to a state. (this is False).
Pushdown Automata (PDA)
In a PDA, the operation which reads a symbol on the stack also removes it from the stack.
Which conditions must be true at the same time for a PDA to accept the string w?
All characters of w have been read from left to right
The PDA is in an accept state
It doesn’t matter if the stack is empty or not
Write the equations for each state
q_1 = ε (start) + q_2b + q_3a
q_2 = q_1a
q_3 = q_1b
q_4 = q_2a + q_3b + q_4a + q_4b
Simplify the final state to get regex: q_1 = ε + q_1ab + q_1ba (sub in q_2 and q_3)
q_1 = ε + q_1(ab + ba)
This is in the form: R = Q + RP (Arden's Theorem)
R = QP*
Thus, the regex is: ε + (ab + ba)*
Chomsky-Normal Form and CYK Algorithm Set Theory
CFG for balanced parentheses:
If instead of Chomsky-Normal form, we allowed 2 or 3 variables on the right hand side of a rule in a CFG then a version of the CYK algorithm Let A and B be two sets. The complement of ( (complement of A) union the (complement
Remember VESPA - G = {V, Σ, S, P} of B)) is the intersection of A and B.
could decide if a string w of length n is generated by the CFG: yes, but it could require O(n4) time. There would be n2 positions in the table as
V => Set of variabls (nonterminals) before but to fill in each box, you would need to consider all ways to partition a string of length k on level k into 3 or 2 parts, which is ~ (n+2
If there is a computation on a string w in an NFA M which ends in a non-final state, then w
Σ => set of terminals choose 2) or O(n2). is not in L(M). (this is false).
S = Start symbol
P = Production Rules Regular Languages If A={0, ε, 11} and B={1,11}, then AB={0, 01, 011, 1,11,111,1111}, this is false as the strings
0 and 11 do not have a suffix from B. The answer would have been true if B contained the
Show that the following CFG generates the language a^nb^n: The set of regular languages are closed under both complementation and union but not concatenation. (this is false). empty string.
G = ({S,A}, {a, b}, S, {S → aAb, A → aAb, S → ε})
If start symbol not specified, assume S. We know language a^nb^n is not Does ε={}? No!
regular (proved via pumping lemma)
Start with Symbol S. We know: For any language L, L* is contained in LL* (this is false).
S → aAb
→ aaAbb (because we know A → aAb) If the input alphabet is {0,1}, and L1 is the set of even length strings over {0,1} and L2 =
→ aabb (because we know A → ε) {1}, what is L1 intersect L2? Empty set.
Therefore, the CFG generates the language a^nb^n.
The set of all CFLs is equivalent to the set of languages accepted by PDAs
Deterministic Finite Automata (DFA) Pumping Lemma for CFLs Pumping Lemma
Given a DFA M with n states where the input alphabet has k characters, we The pumping lemma states that if a language L is regular, then there exists a pumping length p such that any string s in L with length at least p In a proof using the pumping lemma to show that language L isn't regular, it suffices to
can determine if the L(M) =ø in time: nk (Need to do a search on a graph can be divided into three parts xyz, satisfying: show that there is a string w in L and some decomposition of w, w=xyz, y not equal to
with nk edges to see if final state is reached). epsilon where xy2z is not in L. (this is false).
|xy| ≤ p (the first p characters contain x and y)
In a DFA M, two states p and q are distinguishable if there are two distinct |y| > 0 (i.e., y is not empty) When proving a language L is not regular using the pumping lemma and the string w, your
strings x and y such that δ(q0, x)=p and δ(q0, y)=q and p≠q (this is False). xynz ∈ L for all n ≥ 0 (pumping y any number of times must produce a valid string in L) proof must consider:
Every pair of states in a minimal DFA is distinguishable. The pumping lemma for CFLs states that for a sufficiently long string s ∈ L, we can split s = uvwxy such that: Strings w of arbitrarily large length
All ways that w can be decomposed into xyz where y is not equal to epsilon
If state p is distinguishable from state q and state q is distinguishable from |vwx| ≤ p (a bounded "pumpable" section) and |xy|<= n for n the pumping length.
state r, then state p is distinguishable from state r (this is false). vx ≠ ε (at least one of them is non-empty)
If there is a set of strings of size k which are pairwise distinguishable by a uvnwxny ∈ L for all n ≥ 0
language L then every DFA for L must contain at least k states.
DFAs are 5-tuples: (Q, Σ, δ, q0, F) Q = set of states
Σ = input alphabet
δ = transition function
q0 = start state
F = set of final states
Deciding Algorithm for L L1 = {0^n1^m, n,m ≥ 0}
S → 0S | P A CFG is a set of production rules used to describe a language. It consists of:
Check if the input length is even. P → 1P | ε
Non-terminal symbols (e.g., S, A, B)
If the input string is of odd length, reject immediately (since w always has We got to P because if we do 1S, that would mean we could flip flop between 0 and 1, which we can't do Terminal symbols (e.g., a, b)
an even length). S => 0S => 00S => 00P => 001P => 001 (001 is in Chomsky Normal Form) Start symbol (e.g., S)
Production rules: A → α (where A is a non-terminal and α is a string of
Split the input into two halves. L3 = {palindromes over {0,1}} terminals and/or non-terminals)
S → 0S0 | 1S1 | 0 | 1 | ε
Given input s, divide it into two equal-length parts: s = w1w2 where w1 and Key Definitions:
w2 are of the same length.
1. Terminal symbols: Basic symbols of the language.
Compare the two halves.
2. Non-terminal symbols: Variables that can be replaced by other strings.
3. Start symbol: The symbol from which derivation begins.
If w1 = w2, accept. Otherwise, reject.
4. Production: A → α, where A is a non-terminal and α is a string of
terminals/non-terminals.
Pushdown Automata (PDA) State minimisations
Key Concept:
A PDA is an automaton that has a stack to store symbols in addition to its We can’t collapse p and q if q ∈ F and p /∈ F
input tape. It is used to recognize context-free languages.
Context-free languages are exactly the languages that can be accepted by a
deterministic PDA (DPDA) or non-deterministic PDA (NPDA).
Components:
What is a Pushdown Automaton (PDA)?
1. States: Set of possible states.
2. Input alphabet: Set of symbols from which the input string is
A PDA is like an NFA (Non-deterministic Finite Automaton) but with an
formed.
added stack (pushdown store) for unbounded memory.
3. Stack alphabet: Set of symbols that can be stored in the stack. It reads input left to right, like an NFA.
4. Transition function: Describes state transitions, stack At each step, the PDA:
operations based on the current state and input symbol. Reads an input symbol.
Reads and pops the top of the stack (atomic operation).
Operations: Pops when no more of the symbol is left on the stack.
A PDA moves between states based on input symbols and manipulates the
stack (push or pop).
Acceptance can be done in two ways:
1. Final State Acceptance: Accept if the automaton reaches a
final state.
2. Empty Stack Acceptance: Accept if the stack is empty after
processing the entire input.
Example:
PDA for strings with equal numbers of a's and b's:
Push a onto the stack.
Pop a when encountering b.