Question

In: Computer Science

Construct a dfa that accepts strings on {0, 1} if and only if the value of...

  1. Construct a dfa that accepts strings on {0, 1} if and only if the value of the string, interpreted as a binary representation of an integer, is zero modulo five. For example, 0101 and 1111, representing the integers 5 and 15, respectively, are to be accepted.

Solutions

Expert Solution

Here is procedure to build this dfa :

  • To build this DFA, you must realize what happens upon reading a new character in terms of multiplication.
  • If we are adding a 0 , it means we are multiplying our current number by 2 (this is a left shift operation). If we are adding a 1 , it means we are multiplying our current by 2 and adding 1.
  • To make sure it is divisible by 5, we have to operate mod 5 and we should accept s only when s mod 5 = 0 when it is interpreted as a binary number(and it begins with 1)
  • We also have to construct seperate states for start and 0 mod 5. This is why because if they are same states then we would go to trap state after reading a 0.
  • But if we already read part of string that started with 1 and which was equivalent to 0 mod 5 then our DFA would trap but it should not. Thus, two states should need to be made(S and 0 in the below diagram) to prevent this error from occuring.

DFA :

Like, if this helped :)


Related Solutions

Consider the number of strings on {0, 1} defined by the requirement below. For each construct...
Consider the number of strings on {0, 1} defined by the requirement below. For each construct a dfa. Every 00 is followed by a 1. For example, the strings 101, 0010, 0010011001 are in the language, but 0001 and 00100 are not. The leftmost symbol differs from the rightmost one.
Draw a DFA for the following ( ∑ = {0,1}):                                 Set of all strings with.
Draw a DFA for the following ( ∑ = {0,1}):                                 Set of all strings with at most one consecutive pair of 1’s.
Automata Question. Over the alphabet Σ = {a, b}: 1) Give a DFA, M1, that accepts...
Automata Question. Over the alphabet Σ = {a, b}: 1) Give a DFA, M1, that accepts a Language L1 = { w | w has exactly 2 a’s } 2) Give a DFA, M2, that accepts a Language L2 = { w | w has at least 2 b’s } 3) Give acceptor for L1 intersection L2 4) Give acceptor for L1 - L2
Write a progrm that accepts two strings as input, then indicates if the two strings are...
Write a progrm that accepts two strings as input, then indicates if the two strings are equal when the case of individual letters is ignored. Sample runs are shown below. Use C++ Enter two strings. String 1: PROgraM String 2: proGram PROgraM and proGram are equal. Enter two strings. String 1: litter String 2: LittLe litter and LittLe are not equal.
Q5 [15 pts] a) Convert the following NFA to a DFA: 0 1 ---------------------- -> a...
Q5 [15 pts] a) Convert the following NFA to a DFA: 0 1 ---------------------- -> a || {a} | {a,b} b || {c} | {c} c || {d} | {d} d || {e} | {e} * e || {} | {} b) Informally describe the language that it accepts.
Consider the ternary number system. What is the corresponding regular expression of a DFA that accepts...
Consider the ternary number system. What is the corresponding regular expression of a DFA that accepts ternary strings that are not divisible by nine?
Create a DFA for L = {wwR|w ∈ {0, 1}∗}. WR represents the reverse of the...
Create a DFA for L = {wwR|w ∈ {0, 1}∗}. WR represents the reverse of the string. Explain your answer.
Construct a finite-state machine, using combinational logic for an apple vending machine that only accepts nickels...
Construct a finite-state machine, using combinational logic for an apple vending machine that only accepts nickels (5 cents). When 15 cents is deposited the user can push a button to receive an apple and the machine resets. If the user inserts more than 15 cents no money will be returned. What are the machine states? What are the inputs? What are the outputs? Draw state table Draw state diagram Write the combinational logic for next state and output Explain if...
Construct a finite-state machine, using combinational logic for an apple vending machine that only accepts nickels...
Construct a finite-state machine, using combinational logic for an apple vending machine that only accepts nickels (5 cents). When 15 cents is deposited the user can push a button to receive an apple and the machine resets. If the user inserts more than 15 cents no money will be returned. What are the machine states? What are the inputs? What are the outputs? Draw state table Draw state diagram Write the combinational logic for next state and output Explain if...
construct a DFA to check if a string containing a,b and no.of a's is divisible by...
construct a DFA to check if a string containing a,b and no.of a's is divisible by 5 and no.of b's is divisible by 7
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT