deterministic finite, Lecture notes of Computer Engineering and Programming

In the theory of computation, a branch of theoretical computer science, a deterministic finite automaton (DFA)—also known as deterministic finite

Typology: Lecture notes

2018/2019

Uploaded on 02/27/2019

kath8970
kath8970 🇳🇵

1 document

1 / 18

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
The job of an FA is to accept or reject an input depending on whether the pattern defined by the FA
occurs in the input.
1. Design a DFA in which set of all strings can be accepted which start with ab.
Given: Input alphabet, Σ={a, b}
Language L ={ab, aba, abaabbb, abba, ….}
Clearly the language is innite because there is innite number of strings.
The idea behind this
approach is very simple, follow the steps below and you will understand.
1. First we will make DFA for accepting the smallest string that is ‘ab’ and after that whatever
comes we don’t care as the condition is satised.
2. In DFA we have to take care of all the input alphabets at every state.
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12

Partial preview of the text

Download deterministic finite and more Lecture notes Computer Engineering and Programming in PDF only on Docsity!

The job of an FA is to accept or reject an input depending on whether the pattern defined by the FA

occurs in the input.

  1. Design a DFA in which set of all strings can be accepted which start with ab. Given: Input alphabet, Σ={a, b} Language L ={ab, aba, abaabbb, abba, ….}

Clearly the language is infinite because there is infinite number of strings.

The idea behind this approach is very simple, follow the steps below and you will understand.

  1. First we will make DFA for accepting the smallest string that is ‘ab’ and after that whatever comes we don’t care as the condition is satisfied.
  2. In DFA we have to take care of all the input alphabets at every state.
  1. so we have to take care of input symbol ‘b’ on state A, that is we have to reject it cause first ‘a’ should come then ‘b’.
  2. So we will make one more state D to take care of ‘b’ from state A
  3. On state B if a comes then we have to reject it, so we will direct this input to state D
  4. On state D for input a and b we do not care so we will make one self-loop

Testing

  1. Lets take one input string abab
  2. First input is a, so from state A we will go to state B
  3. Second input is b, so from state B we will go to state C
  4. Third input is a, so from state C we will go to state C itself
  5. Fourth input is b, so from state C we will go to state C itself (final state)

After end of the string we are at final state so string is accepted.

DFA for binary No divisible by 2

Construct a minimal DFA, which accepts set of all strings over {0,

1}, which when interpreted as binary number is divisible by ‘2’.

Means 110 in binary is equivalent to 6 in decimal and 6 is

divisible by 2.

Answer So if you think in the way of considering remainders if you divide by 2 that is {0, 1}

Answer So if you think in the way of considering remainders if you divide by 3 that is {0, 1, 2}

As you can see that binary number which is divisible by 2 is appearing on left state. Short Trick to create such DFAs Create Transition Table as below

State 0 1

q0 q0 q

q1 q2 q

q2 q1 q

Table creation rules

  1. (^) first write the input alphabets, example 0, 1
  2. there will n states for given number which is divisor.
  3. start writing states, as for n=3: q0 under 0, q1 under 1
  4. q2 under 0 and q0 under 1
  5. q1under 0 and q2 under 1

If the input alphabets are 0, 1, 2 then table will expand accordingly with same rules above. Example For ternary pattern and n=4, table will be as follows ;

State 0 1 2

q0 q0 q1 q

q1 q3 q0 q

q2 q2 q3 q

q3 q1 q2 q

set of all strings can be accepted which start

with 'a'

Design a DFA in which set of all strings can be accepted which

start with a.

Given: Input alphabet, Σ={a, b}

Language L = {a, ab, aba, aabb, aaabbba, …..}

Clearly the language is infinite because there is infinite number of strings.

The idea behind this approach is very simple, follow the steps below and you will understand.

  1. We know that first input must be a and from start state on a we should go to final state, so two states are confirmed: start state and final state.
  2. And if the first input is something else than ‘a’ then string should not be accepted. And we don’t care whatever comes on state C as state C now will work as dead state.
  3. Once we reach final state we accept everything that is why we have a loop

Set of all strings can be accepted which end

with ‘a’

Design a DFA in which set of all strings can be accepted which

end with ‘a’.

Given: Input alphabet, Σ={a, b}

Language L ={aa, aba, aaabbba, abba,baba ….}

Clearly the language is infinite because there is infinite number of strings.

The idea behind this approach is very simple, follow the steps below and you will understand.

  1. We will first start accepting ‘b’ on start state itself and then on a we will go to final state.
  2. And on final state we do not care for a’s so we have to put a self-loop.
  3. On final state if ‘b’ comes then we will redirect it start state so that any string which does not end with ‘a’ should not get accepted.

Testing

  1. Lets take one input string baba
  2. First input is b, so from state A we will go to state A itself
  3. Second input is a, so from state A we will go to state B
  4. Third input is b, so from state B we will go to state A
  5. Fourth input is a, so from state A we will go to state B (final state)

After end of the string we are at final state so string is accepted.

Set of all strings can be accepted which start with ab

Design a DFA in which set of all strings can be accepted which

start with ab.

Given: Input alphabet, Σ={a, b}

Language L ={ab, aba, abaabbb, abba, ….}

Clearly the language is infinite because there is infinite number of strings.

The idea behind this approach is very simple, follow the steps below and you will understand.

  1. First we will make DFA for accepting the smallest string that is ‘ab’ and after that whatever comes we don’t care as the condition is satisfied.
  2. In DFA we have to take care of all the input alphabets at every state.
  3. so we have to take care of input symbol ‘b’ on state A, that is we have to reject it cause first ‘a’ should come then ‘b’.
  4. So we will make one more state D to take care of ‘b’ from state A
  5. On state B if a comes then we have to reject it, so we will direct this input to state D
  6. On state D for input a and b we do not care so we will make one self-loop

Testing

  1. Lets take one input string abab
  2. First input is a, so from state A we will go to state B
  3. Second input is b, so from state B we will go to state C
  4. Third input is a, so from state C we will go to state C itself
  5. Fourth input is b, so from state C we will go to state C itself (final state)

After end of the string we are at final state so string is accepted.

Set of all strings can be accepted which

contain ab

Design a DFA in which set of all strings can be accepted which

ends with ab.

Given: Input alphabet, Σ={a, b}

Language L ={ab, abab, abaabbab, abbab, bbabaabab ….}

Clearly the language is infinite because there is infinite number of strings.

The idea behind this approach is very simple, follow the steps below and you will understand.

  1. First we will make DFA for accepting the smallest string that is ‘ab’
  2. (^) In DFA we have to take care of all the input alphabets at every state.
  3. so we have to take care of input symbol ‘b’ on state A, that is we made self-loop on start state.
  4. On state B if a comes then we will accept it as repetition of ‘a’ after a will not ruin anything. Because we want ab in the end.
  5. on State C if b comes then that will be a problem as we only want ab in the end not bb, so we will direct b to state A.
  6. If ‘a’ comes on state C then we will direct it to state B and if one ‘b’ comes then we will be good by getting ‘ab’ in the end

Testing

  1. Lets take one input string baababab
  2. First input is b, so from state A we will go to state A itself
  3. Second input is a, so from state A we will go to state B
  4. Third input is a, so from state B we will go to state B itself
  5. Fourth input is b, so from state B we will go to state C
  6. Fifth input is a, so from state C we will go to state B
  7. Sixth input is b, so from state B we will go to state C
  8. Seventh input is a, so from state C we will go to state B
  9. (^) Eighth input is b, so from state B we will go to state C (final state)

After end of the string we are at final state so string is accepted.

Start and end symbol must be different

Design a DFA in which start and end symbol must be different

Given: Input alphabet, Σ={a, b}

Language L = {ab, ab, abab, aabb, aaabbb,...}

Clearly the language is infinite because there is infinite number of strings.

The idea behind this approach is very simple, follow the steps below and you will understand.

  1. We know that if the first input is 'a' then the last input cannot be 'a', so we start two flows form start state, one for staring with 'a' and another for starting with 'b'
  2. This is also clear that there will be two final states
  3. In the first flow starting with 'a' we have already discussed the process in the previous examples. We will accept the input 'a' on state B for multiple times and then on b we will go to final state.
  4. On final state we will direct the input 'a' to state B so that the last symbol should not be 'a'
  5. The same mechanism will be for another flow staring from start state A on input 'a'.

Testing 1

Clearly the language is infinite because there is infinite number of strings.

This DFA is complement of the previous example. We will explain complementation in the next section. The idea behind this approach is very simple, follow the steps below and you will understand.

  1. We know that if the first input is 'a' then the last input should be 'a', so we start two flows form start state, one for staring with 'a' and another for starting with 'b'
  2. Now just design the very basic DFA accepting for ε, that means the start state should final state.
  3. In the first flow when 'a' comes form the input string then we should also reach final state as 'a' is also satify the property of DFA
  4. After 'a' if any number of 'a' comes then we do not have any problem, that is why a self-loop on state B
  5. On state B if b comes then it should be accepted as B is final state so we will create one more state C to get the 'b'
  6. On state C if any number of 'b' comes we do not have issues but if 'a' comes then we have to accept it so we will direct input to state B
  7. The same mechanism will be for another flow staring from start state A on input 'b'.

Testing 1

  1. Lets take one input string aba (this will describe for strings which starts with a and ends with same symbol a)
  2. Scan string from left to right
  1. First input is a, so from state A we will go to state B
  2. Second input is b, so from state B we will go to state C
  3. Third input is a, so from state C we will go to state B (final state)

After end of the string we are at final state so string is accepted.

Testing 2

  1. Lets take another input string bab(this will describe for strings which starts with b and ends with same symbol b)
  2. Scan string from left to right
  3. First input is b, so from state A we will go to state D
  4. Second input is a, so from state D we will go to state E
  5. Third input is b, so from state E we will go to state D (final state)

After end of the string we are at final state so string is accepted.

You may also try some examples of strings to run over this DFA, and you will understand more

Every 'a' should be followed by 'b'

Design a DFA in which every 'a' should be followed by 'b'

Given: Input alphabet, Σ={a, b}

Language L = {ε, ab, abab, bbbb, ...}

Clearly the language is infinite because there is infinite number of strings.

The idea behind this approach is very simple, follow the steps below and you will understand.

  1. Firstly for ε we will make the start sate as final state.
  1. Here C state is a dead state

Testing

  1. (^) Lets take one input string baa
  2. Scan string from left to right
  3. First input is b, so from state A we will go to state A itself
  4. Second input is a, so from state A we will go to state B
  5. Third input is a, so from state B we will go to state B itself (final state)

After end of the string we are at final state so string is accepted. You may also try some examples of strings to run over this DFA, and you will understand

more

Every 'a' should followed by 'bb'

Design a DFA in which every 'a' should followed by 'bb'

Given: Input alphabet, Σ={a, b}

Language L = {ε, abb, abbabb, abbabbabb, babb, ...}

Clearly the language is infinite because there is infinite number of strings.

The idea behind this approach is very simple, follow the steps below and you will understand.

  1. Firstly there is ε so make start state as final state
  1. And we do not care if string is only 'bbbbb...'(as this doesn't violate given property) so put self- loop on start state itself
  2. if a comes then we will move state B and we should have two b's after that so state C and D (final state)
  3. Now what if 'a' comes on state D so we will direct it to state B so that if two b's comes thereafter then string will be accepted
  4. On state D if b comes then that is not a problem so a self-loop is given there for 'b'
  5. What if 'a' comes on state B then it should be rejected as after 'a' only two b's are allowed
  6. That is why we have a dead state E(in red)
  7. On state C if 'a' comes then also property is violated so we will direct flow to state D on 'a'
  8. On state E we do not care about either 'a' or 'b' as the stirng is already failed the property

Testing

  1. Lets take one input string babb
  2. Scan string from left to right
  3. First input is b, so from state A we will go to state A itself
  4. Second input is a, so from state A we will go to state B
  5. Third input is b, so from state B we will go to state C
  6. Fourth input is b, so from state C we will go ti state D (final state)

After end of the string we are at final state so string is accepted. You may also try some examples of strings to run over this DFA, and you will understand more

Every 'a' should never followed by

'bb'

Design a DFA in which every 'a' should never followed by 'bb'

Given: Input alphabet, Σ={a, b}

Language L = {ε, aa, bb, ab, aaa, bbbb, ...}