1: Regular languages and FSAs Flashcards

1
Q

What is a FSA?

A

Finite state automaton = a model of a simple computer that moves between one of each of a finite set of states according to external inputs.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is an alphabet?

A

A finite set of symbols, called letters.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is a letter?

A

One item (symbol) within an alphabet.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is a word? What is the empty word?

A

A finite sequence of letters over (within) an alphabet. Word aka string. The empty word has a length of 0 so has no letters.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

If A is an alphabet, what is A*?

A

A* = the set of all words over (that can be built from) the alphabet A, including the empty word. Words are built from 0 or more letters from the alphabet. Languages from the alphabet A will be subsets of A*.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is a DFA?

A

A deterministic finite state automaton is a variant of a FSA. It is the “default” and cannot be (modelled as being) in more than 1 state simultaneously, as a nondeterministic finite state automaton is able to be.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How do you define a DFA?

A

You define DFAs as tuples of 5 items as M = (A, S, F, s0, T).

A = alphabet
S = set of states
F = transition function, which takes a non-empty input letter and current state and returns (and goes to) another state
s0 = start state; s0 ∈ S
T = set of accept states, aka terminals. T is a subset of all states: T ⊆ S.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is a terminal also known as?

A

A terminal is aka an accept state.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is a transition function?

A

Transition functions are used to translate between current states to the next ones according to inputs in FSAs.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is a regular language?

A

Languages are regular when there is a DFA whose language is the same as the language in question.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is an NFA?

A

A nondeterministic finite state automaton (NFA) is a variant of a FSA which can be modelled as being in more than one state simultaneously. Thinking of the current states of machines as brances of a tree, only one leaf node needs to accept at some point for the NFA to accept the input.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

How do you define an NFA?

A

You define NFAs as a tuple of 5 items such that M = (A,
S, F, s0, T).

A = alphabet
S = set of states
F = transition function, which takes an input letter (which can now also be empty) and current state and returns (and goes to) another state in the power set of S, P(S), which is the set of all subsets of S (since some may become cut off)
s0 = start state; s0 ∈ S
T = set of accept states, aka terminals. T is a subset of all states: T ⊆ S.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is the language defined by an NFA?

A

The language will consist of all the words that the NFA accepts.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Prove that if a language is accepted by an NFA if and only if it is accepted by a DFA.

A

Let N = (A, S, F, s0, T) be an NFA. We construct a DFA M that accepts L(N). We let M = (A,P(S), F’, S0, T’), where:

• The transition function F’ : A x P(S) → P(S) is given by:
F’(a, X) = {y ∈ S : ∃ x ∈ X with a path labelled ϵ ^ i a ϵ ^ j = a from x to y in N, for some i, j ≥ 0}.

  • The start state is S0 = {s0} ∪ {s : there exists a path labelled only with ϵs from s0 to s}.
  • The new set of accept states is T’ = {Y ⊆ S : Y ∩ T ≠ ∅}, which is all sets of states containing at least one accept state of N.

To finish the proof, we need to show that L(M) = L(N). To do this, we first show that L(N) ⊆ L(M) and then that L(M) ⊆ L(N). To see that L(N) ⊆ L(M), let w = a1 a2 … an ∈ L(N). Then there is a path in N: S0 → a1 S1→ a2 S2 → ··· → an Sn ∈ T’.

Let S1 = F’(a1, S0), S2 = F’(a2, S1), …, Sn = F’(an, Sn-1). Then s1 ∈ S1, s2 ∈ S2, …, sn ∈ Sn ∈ T’. So there is a path in M: S0 → a1 S1 → a2 S2 → ··· → an Sn ∈ T’. So w ∈ L(M). Therefore L(N) ⊆ L(M).

We finish the proof by showing that L(M) ⊆ L(N). Let w = a1 a2 … an ∈ L(M). Then there is a path in N:
S0 → a1 S1 → a2 S2 → ··· → an Sn ∈ T’.

By definition of T’, there exists some sn ∈ Sn ∩ T. Hence there exists some sn-1 ∈ Sn-1 such that sn-1 → an Sn is a transition in N.

Continuing in this fashion, we eventually conclude that s0 ∈ S0 = {s0} and there exists a transition s0 → a1 s1 in
N.

Therefore we can conclude that in N there is the path:
s0 → a1 si1 → ··· → an sin ∈ T and so w ∈ L(N).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

How do you convert an NFA into a DFA?

A

To make a DFA M from an NFA N = (A, S, F, s0, T). The alphabet of M is A.

  1. Begin with a new start state S0 labelled by {s0} ∪ {s : there exists a path labelled only by ϵ-arrows from s0 to s}.
  2. For each newly constructed state Si, and for each a ∈ A:
    (a) For each s ∈ Si, find all states s’ that can be reached from s by reading (ϵ ^ i)a(ϵ ^ j) (for any i and j).
    (b) Let Sj be the set of all of these states s’. (The set Sj may be the empty
    set ∅) Put an arrow labelled a from Si to Sj .
  3. Repeat Step 2 until every new state Si has one arrow leaving it for each letter a ∈ A.
  4. Make each state Si that contains at least one state from T into an accept state for M.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is a regular expression?

A

A sequence of letters in a given pattern used to define a language in a compact manner.

17
Q

Why are the definitions of regular expressions recursive?

A

The empty word and all single letters are regular expressions. All concatenated pairs of regular expressions, unions of regular expressions, one or more concatenated copies of a regular expression are also regular expressions.

R1 + R2 = R1 | R2 = R1 ∪ R2 = union of R1 and R2.

R1R2 = concatenation of R1 and R2.

R1* = one or more concatenated copies of R1, aka Kleene closure of R1.

18
Q

True/false: if L1 and L2 are languages over an alphabet A that are both defined
by regular expressions, then so are L1 ∪ L2, L1, L1 ∩ L2, L3 = {w ∈ A : w ∉ L1}
and L1 \ L2 = {w : w ∈ L1, w ∉ L2}.

A

True.

19
Q

Prove that if L1 and L2 are languages over an alphabet A that are both defined
by regular expressions, then so are L1 ∪ L2, L1, L1 ∩ L2, L3 = {w ∈ A : w ∉ L1}
and L1 \ L2 = {w : w ∈ L1, w ∉ L2}.

A

??

20
Q

What is Kleene’s theorem?

A

A language is described by a regular expression if and only if there is a DFA which defines it.

21
Q

What is the proof of Kleene’s theorem?

A

??

22
Q

How do you convert from a regular expression to an NFA?

A
  1. To start, draw a diagram with two states – a start state s and an accept state t, with an arrow from s to t labelled with the whole regular expression. This diagram is not, in general, an NFA, but we will make it into one.
  2. We slowly break down the labels on the arrows until each label is either a single
    letter or Ɛ. To break down an arrow labelled R1 + R2, introduce 2 new arrows, R1 and R2, with the same start and end nodes.
  3. To break down an arrow labelled R1R2, introduce a new intermediate state, s’, connected to from the first node with R1 and to the second node with R2.
  4. To simplify an arrow labelled R*1 introduce a new state s’ with two epsilon connections from the first node and s’ and s’ to the second node, and with R1 being a connection from s’ to itself.

Continue until each arrow is labelled by a single letter (or Ɛ). The resulting diagram will be of an NFA. It can then be turned into a DFA, if necessary, using the NFA to DFA conversion method.

23
Q

How do you convert from an NFA to a regular expression?

A

Here’s a method to go from an NFA (A, S, F, s0, T = {t1,…,tk}) to a regular expression.

  1. The first step is to add a new start state s, connected to s0 by a Ɛ-arrow.
  2. Next, we add a new accept state, t, with a Ɛ-arrow from each state ti ∈ T to t, and turn each state ti 2 T into a non-accepting state.
  3. Eliminate multiple arrows between any pair of states si and sj, R1, R2 .. Rn, into a single arrow R1 + R2 … + Rn going from si to sj.
  4. To eliminate a state sj between si and sk, combine all arrows from si to sj, sj to sj, and sj to sk, R1, R2 .. Rn as a single arrow between si and sk R1+R2 … +Rn

Repeat steps 3 and 4 until only states s and t remain, with a single arrow between them; that single will be labelled with the desired regular expression.

24
Q

What is the pumping lemma?

A

A set of moves that can be performed to show whether a language is regular or not. All sufficiently long words in any regular language can repeatedly have their middle sections repeated an arbitrary number of times - pumped - to make new words that will also lie within the same language.

25
Q

How do we show whether a language is regular?

A

??

26
Q

What is the proof of the pumping lemma?

A

??

27
Q

How does the pumping lemma work?

A

??

28
Q

How do you use the pumping lemma to show a language is regular?

A

??

29
Q

How do you use the pumping lemma to show a language is not regular?

A

??

30
Q

True/false: all finite languages are regular

A

True.

31
Q

Prove that all finite languages are regular.

A

If a language, L, is finite, there exists an alphabet A and w1, w2,…, wn ∈ A* such that L = {w1, w2,…,wn}. A regular expression for L is w1 + w2 + ··· + wn. Since the language can be expressed with a regular expression, the language is regular.