Theories of computation Flashcards
what is a regexp?
a regular expression defines a language which is a subset of Σ* which is the set of all words (combinations of letters in the alphabet)
if E and F are regexps, what does EF, E|F and E* mean?
EF: a word that is a concatenation of a word that matches E and a word that matches F
E|F: a word that matches either E or F
E* a word that is made of 0 or more words that match E
what is the precedence of juxtaposition (two regexps next to each other), | and *?
highest to lowest:
* , | , justaposition
what is an NFA and DFA?
they are both ways of representing a regexp. they show states that can be accepting or non-accepting to show whether the word is valid or not. a DFA is partial if there isn’t always a state that comes after adding a new letter. NFAs can have multiple paths from a state with the same letter and can also have multiple initial states. all DFAs are NFAs and all NFAs can be converted into DFAs
what is Kleene’s theorem?
every regular language can be converted into a DFA and every DFA can be converted into a regular language
how do you go about proving by course-of-values induction that if a graph is connected, V(G) ≤ E(G) + 1 where V(G) is number of vertices and E(G) is number of edges?
show that it works for a graph with only one vertex and no edges
show that it works by taking away an edge if the result is another connected graph or if it splits into two graphs Gₓ and Gᵧ
how do you convert a natural language to a DFA?
dont need to know
first convert it into a εNFA shown below:
EF: make all ending points of E unstable and point to the start point of F with an ε-edge
E*: make the start point of E point to a new arbitrary state which points to where the start point pointed to and the end points link to the arbitrary state with ε-edges
E|F is just E and F unconnected next to each other
then convert the εNFA into an NFA and then into a DFA
what is a generalised NFA?
an NFA where each arrow might not just represent a letter like a but might represent a regexp like (aa)b*
how to you turn a generalised NFA into a regexp?
if there is no loop on each vertex, add a 0 loop
if there is no arrow from x to y add a 0 arrow
make a start point that connects to the previous initial vertices with an ε-edge and a 0-edge to the others
make an end point and connect every previous end point to it with an ε-edge and every other vertex to it with a 0 arrow
remove each vertex (V) one-by-one by making a new arrow to replace each two arrows that went from x to v to y and then combine the arrows from x to y with an |.
do this until the graph is just a start and end joined with a single arrow and that will be labelled with the regexp.
how do you find the complement of a language?
flip the state of each vertex in the equivalent DFA and convert back
how do you minimise a DFA (remove unnecessary parts)
remove unreachable states (states that have a path from initial state)
remove hopeless states (states that do not have a path to an accepting state)
combine equal states (states that have the same set of words that come off from it) and combine arrows that go to and from the same states.
how do you represent the resulting state of adding the letter a to the state s?
𝛿(s,a)
what does aa* mean in a regexp?
at least one a because a* can be empty
how do you check if two DFAs represent the same language?
make an initial compound state a,b of the two initial states of the DFAs. add arrows for each of the letters (l) in the language to a state with x,y where l takes the first DFA from a to x and the second from b to y. If the state xy already exists, make the arrow point to that. keep doing this until all states have arrows for each letter of the language. They represent the same language if each state is double accept or double reject.
what does it mean for a set to be countably infinite?
when there is a bijection (one to one correspondence) with the infinite set of natural numbers. integers (by ordering them 0, -1, 1, 2, -2 …) and regexps are countable but real numbers and languages are uncountable for example
what is a context free language?
a language that can be defined using Backus-Naur form (A ::= a|b|c) made of a 4-Tuple: (V,Σ,R,S) representing (variables/ non-terminals, terminals, rules, starting variable)
what is a derivation/parse tree?
a tree stemming from the starting variable that branches out to what it transforms into in each stage of the generation of the word using the BNF. the leaves make up the final word
how do you turn a regexp into a CFG?
- Create a variable Rᵢ for each state qᵢ of the DFA.
- Add the rule Rᵢ ::= aRⱼ to the CFG, if δ(qᵢ, a) = qⱼ is a transition in the DFA.
- Add the rule Rᵢ ::= ε, if qᵢ is an accepting state of the DFA.
- Add the rule Rᵢ ::= aRᵢ if there is a loop
- Make R₀ the start variable of the grammar, where q₀ is the start state of the machine.
do questions on course of values induction
watch video on np=p