ATCD TutorialQs
ATCD TutorialQs
Tutorial Questions
ATCD
UNIT-1
1. Why do we need to study automata theory and formal languages?
2. What is DFA? Find the DFA for the following languages over {0, 1}*
i) The set of all strings such that number of 0’s is odd
ii) The set of all strings that contain exactly three 1’s
iii) The set of all strings that do not contain 1101
3. Design DFA which accepts language L={0,000,00000…….} over {0}
4. Design a DFA L(M) = {w | w ε {0, 1}*} and W is a string that does not contain
three consecutive 1's.Process the string 0011001 on machine.
5. Design DFA to accept strings with ‘c’ and‘d’ such that number of d’s are divisible by
4.Show the moves of DFA for the string cdcddcd
6. Design a DFA to accept the language
L = {w |w has both an even number of 0’s and an even number of 1’s}.
Represent obtained DFA by transition table. Show the transitions of DFA for the
string 110101.
7. What is DFA? Find the DFA’s accepting for the following languages over the
alphabet {a,b,c}:
i) The set of all strings with abc as a substring
ii) The set of all strings ending in bac
iii) The set of all strings starting with cab
8. Draw a deterministic and non-deterministic finite automata for ∑= {A-Z} which
accept a string containing “CSE” at the end of a strings of {A-Z}.
9. Design DFA for the following over {a,b}.
i) All string containing not more than three a’s.
ii) All strings that has at least two occurrences of b between any two occurrences of a.
iii) All strings ending with aa
10. What is DFA? Construct a DFA accepting the language
{ W {a,b}*| W has neither aa nor bb as substring}
11. Draw the DFA for the following
i) To accept decimal strings divisible by 3 over the alphabet ∑ = {0,1,2,3,4,5,6,7,8,9}
ii) To accept odd number of a’s and even number of b’s over alphabet ∑ = {a,b}
12. Design a DFA that reads strings made up of letters in the word ‘CHARIOT’ and
recognizes these strings that contain the word ‘CAT’ as a substring.
13. Define Deterministic and Non-deterministic finite automaton.
14. Differentiate between NFA and DFA?
15. Design an NFA with Σ = {0, 1} accepts all string in which the third symbol from the
right end is always 0.
16. Construct an NFA that accepts the set of all strings over {0,1} that start with 0 or 1
and end with 10 or 01.
17. Design a NFA for the following language L={0101n where n>0}
18. Describe the procedure of converting NFA to DFA with a suitable example.
Prepared By: MD SHAKEEL AHMED, Associate Professor, Dept. Of IT, VVIT, Guntur Page 1
III IT-I SEM Regulation: R20 ATCD: Tutorial Questions
25. Explain the procedure for constructing minimum state DFA with an example.
(OR) What is minimal DFA? Write the minimization Algorithm for DFA?
26. Let ∑= {a, b}, Give DFA that accepts any string with aababb as a substring.
Minimize the DFA obtained.
27. Reduce the following DFA where q1 is the start state and q6 is the final state.
Prepared By: MD SHAKEEL AHMED, Associate Professor, Dept. Of IT, VVIT, Guntur Page 2
III IT-I SEM Regulation: R20 ATCD: Tutorial Questions
Prepared By: MD SHAKEEL AHMED, Associate Professor, Dept. Of IT, VVIT, Guntur Page 3
III IT-I SEM Regulation: R20 ATCD: Tutorial Questions
33. Bring out the differences between Moore and Mealy machines?
34. Design a Moore machine with the input alphabet {0, 1} and output alphabet {Y, N}
which produces Y as output if input sequence contains 1010 as a substring otherwise,
it produces N as output .
35. Design a mealy machine to print out 1’s complement of an input bit string?
36. Design a Moore machine for 2’s complement of binary number.
37. Construct the Moore machine to compute residue modulo 5 and finds to its equivalent
Mealy machine.
38. Draw a Moore machine for calculating mod 3 of a given binary number. Find its
equivalent mealy machine.
39. Construct a Moore machine that determines whether an input string contains an even
or odd number of 1's. The machine should give 1 as output if an even number of 1’s is
in the string and 0 otherwise.
40. Design a Moore and Mealy machines for a binary input sequence such that if it has a
substring 101, the machine outputs A, if the input has substring 110, it outputs B
otherwise it outputs C.
41. Design a Moore and Mealy machine that scans sequence of input of 0 and 1 and
generates output 'A' if the input string terminates in 00, output 'B' if the string
terminates in 11, and output 'C' otherwise.
42. Design Moore and Mealy Machine to increment binary number by 1
43. Give Mealy and Moore machine for the following: For input from ∑*, where ∑=
{0,1,2}, print the residue modulo 5 of the input treated as a ternary (base 3, with digits
0, 1 and 2) number.
44. Design a Moore Machine that will read sequences made up of letters a, e, i, o, u and
will give as output, same characters except when an ‘i’ is followed by ‘e’, it will be
changed to ‘u’.
45. Design a Mealy machine to add two binary numbers of the form x1x2…xk, y1y2…yk?
46. Convert the following Mealy machine to an equivalent Moore machine
Prepared By: MD SHAKEEL AHMED, Associate Professor, Dept. Of IT, VVIT, Guntur Page 4
III IT-I SEM Regulation: R20 ATCD: Tutorial Questions
47. Convert the following Mealy machine into equivalent Moore machine.
UNIT-2
1. Define regular expression. Give regular expression for the following languages.
(i) Strings over the alphabet {a, b} ending with ab
(ii) Strings over the alphabet {0,1} that contain substring 10
(iii) Strings over the alphabet {0,1} that contain 1 in the 3 rd position from right end
2. What is regular expression? Write the regular expression for the following languages
over {0, 1}*
i) The set of all strings such that number of 0’s is odd
ii) The set of all strings that contain exactly three 1’s
iii) The set of all strings that do not contain 1101
3. Write regular expressions for the following language over the alphabet ∑= {0, 1}
i) Strings with three consecutive 1’s
ii) Strings with three 1’s
4. Write the regular expression for the language L over Σ = {0, 1} such that all the
strings
i) do not contain the substring 01.
ii) should have at least one 0 and at least one 1.
5. Explain pumping lemma for regular languages with the applications of pumping
lemma.
6. Prove that the language L = {(10)p 1q | p, q ∈ N, p ≥ q} is not regular.
7. Describe the closure properties of Regular sets.
(or) Summarize the closure properties of regular language.
8. Explain about the identity rules of Regular Expressions?
(or) List any ten algebraic laws for regular expressions and explain
(or) Explain about the Properties of Regular Expressions?
9. Construct a DFA for the Regular expression (0+1)* (00+11) (0+1)* ?
10. Design a NFA for the given regular expression 1 (1* 01* 01*)*.
11. Write the steps to construct regular expression from given DFA?
12. Construct a NFA equivalent to the regular expression 10(0+11)0*1?
13. Construct an NFA for r = (a+bb) *ba*
14. What is relationship between finite automata and regular expression? Explain the
process of converting DFA to regular expression.
15. Construct an NFA for the regular expression (a+b)* (aa+bb) (a+b)*
16. Convert the regular expression (((00)*(11)) + 01)* into an NFA.
17. Convert the following DFA to a regular expression.
Prepared By: MD SHAKEEL AHMED, Associate Professor, Dept. Of IT, VVIT, Guntur Page 5
III IT-I SEM Regulation: R20 ATCD: Tutorial Questions
20. Construct a regular expression corresponding to the DFA represented by the below
transition table. q1 is both the initial state and final state.
Prepared By: MD SHAKEEL AHMED, Associate Professor, Dept. Of IT, VVIT, Guntur Page 6
III IT-I SEM Regulation: R20 ATCD: Tutorial Questions
Prepared By: MD SHAKEEL AHMED, Associate Professor, Dept. Of IT, VVIT, Guntur Page 7
III IT-I SEM Regulation: R20 ATCD: Tutorial Questions
45. Construct a derivation tree for the string abcd from the grammar
SaAB, AbC, Bd, Ccd
46. Show that L= {ap /p is prime} is Context free?
47. Construct CNF for the Grammar SABC, A0B,BCD/0,C1
48. Write the general procedure to transform a grammar to Greibach Normal Form?
49. Remove Null production from the following grammar
S ASA | aB | b
AB
B b | ∈
50. Define Context Free Grammar. State and explain the closure properties of CFG.
51. Consider the CFG with {S,A,B} as the non-terminal alphabet, {a,b, } as the
terminal alphabet, S as the start symbol and the following set of production rules
SASA | aB
AB|S
Bb|
Convert the given grammar into CNF
52. Consider the CFG with {S,A,B} as the non-terminal alphabet, {0,1} as the terminal
alphabet, S as the start symbol and the following set of production rules
S A1B
A 0A / ∈
B 0B / 1B / ∈
For the string w = 00101, find the Leftmost derivation, Rightmost derivation, and
Parse Tree.
53. Show that language L={an bncn |n≥0} is not a Context Free.
54. Consider the CFG with {S,A,B} as the non-terminal alphabet, {a,b} as the
terminal alphabet, S as the start symbol and the following set of production rules
S aB|bA
S aS|bAA| a
B bS| aBB| b
Is this grammar ambiguous or unambiguous? Give justification to your answer.
55. Consider the CFG with {S,X,Y} as the non-terminal alphabet, {m,n,o} as the
terminal alphabet, S as the start symbol and the following set of production rules
S XY | Xn | p
X mX | m
Y Xn | o
Convert the given CFG into Greibach Normal Form
56. Generate left most and right most derivation and parse tree for given grammars
G1: S0B|1A, A0|0S|1AA, B1|1S|0BB for the string 00110101
G2: SAb|bA, Aa|aS|bAA, Bb|bS|aBB for the string aaabbabbba
Prepared By: MD SHAKEEL AHMED, Associate Professor, Dept. Of IT, VVIT, Guntur Page 8
III IT-I SEM Regulation: R20 ATCD: Tutorial Questions
UNIT-3
1. Construct a PDA for L={anbn /n ≥1}.Draw transition diagram.Using the instantaneous
description notation process the string aaabbb
2. Define PDA and instantaneous description of PDA. Obtain a PDA to accept the
language L={ wcwR : w {a,b}*}.Draw transition diagram of PDA. Show the moves
by this PDA for string abbcbba
3. Explain the various ways of determining the acceptability of Pushdown Automata.
4. Construct a PDA that accepts L = {0n1n | n ≥0}
5. Design a PDA to accept the language of balanced parenthesis.
6. Design PDA for the following languages by Empty Stack?
i) L = { an bn cm /n, m>=1}
ii) L = { an bm cn /n, m>=1}
iii) L = { am bn cn /n, m>=1}
7. Design PDA for the following languages by Empty Stack?
i) L = { am bn cm+n /n, m>=1}
ii) L = { am bm+n cn /n, m>=1}
iii) L = { am+n bm cn /n, m>=1}
8. Design PDA for the following languages by Empty Stack?
i) L = { anbmcm dn /n, m>=1}
ii) L = { anbncm dm /n, m>=1}
9. Design PDA for the following languages by final state?
i) L = { anbcn /n>=1}
ii) L = { abncn /n>=1}
iii) L = { anbnc /n>=1}
10. Design PDA for the following languages by final state?
i) L = { anb3cn /n>=1}
ii) L = { a3bncn /n>=1}
iii) L = { anbnc3 /n>=1}
11. Design PDA for the following languages by final state?
i) L = { anbc2n /n>=1}
ii) L = { abnc2n /n>=1}
iii) L = { anb2nc /n>=1}
12. Design PDA for the following languages by final state?
i) L = { anbn+1 /n>=1}
ii) L = { anb2n+1 /n>=1}
iii) L = { a2n b3n/n>=1}
iv) L = { a3n b2n/n>=1}
13. Design PDA for the following languages by final state?
i) L = { ambn /n, m>0,m n}
ii) L = { ambn /n, m>0,m>n}
iii) L = { ambn /n, m>0,m<n}
14. Design PDA for the language
Prepared By: MD SHAKEEL AHMED, Associate Professor, Dept. Of IT, VVIT, Guntur Page 9
III IT-I SEM Regulation: R20 ATCD: Tutorial Questions
Prepared By: MD SHAKEEL AHMED, Associate Professor, Dept. Of IT, VVIT, Guntur Page 10
III IT-I SEM Regulation: R20 ATCD: Tutorial Questions
Prepared By: MD SHAKEEL AHMED, Associate Professor, Dept. Of IT, VVIT, Guntur Page 11
III IT-I SEM Regulation: R20 ATCD: Tutorial Questions
UNIT-4
1. Define compiler. Describe the logical phases of a compiler with a neat sketch, show the
output of each phase, using the example of the following statement
position := initial + rate * 60
2. Explain the chief functions of lexical analysis phase.
3. What is the role of transition diagrams in the construction of lexical analyzer?
4. How a finite automaton is used to represent tokens and perform lexical analysis with
examples.
5. Differentiate between token, lexeme and pattern with examples.
6. Explain the recognition of keywords and identifiers with a suitable transition
diagram.
7. Design a non-recursive predictive parser for the following grammar:
S -> AaAb | BbBb
A -> e
B -> e where a, b, e are terminals.
8. Construct LALR parsing table for the following grammar:
S -> CC
C -> cC | d
9. Write an algorithm to find LR(0) items and give an example.
10. Define LR(k) parser. Draw and explain the model of LR parser.
11. State and explain the rules used to construct the LR(1) items.
12. Differentiate Top Down parsing and Bottom Up Parsing.
13. Consider the grammar:
E→ E+E
E→ E*E
E→ id
Perform shift reduce parsing of the input string “id1+id2+id3”.
14. Construct SLR parsing table for the following grammar:
SAS/b
A SA/a
15. Define FIRST and FOLLOW functions. Write the rules for computing FIRST(X) and
Follow(X) where X is grammar symbol. Compute FIRST and Follow, for all the non-
terminals in the following grammar:
S iEtSS’/a
S’ eS/
E b
16. Construct CLR parsing table for the following grammar:
S Aa/bAc/bBa
A d
B d
17. Define LL(1) grammar. Show that the following grammar is LL(1).
S aABd
A b/
B c/
18. Construct LL(1) parsing table for the following grammar. Find the moves made by the LL(1)
parser on the input string: id+id*id
E E+T/T
T T*F/F
F (E)/id
Prepared By: MD SHAKEEL AHMED, Associate Professor, Dept. Of IT, VVIT, Guntur Page 12
III IT-I SEM Regulation: R20 ATCD: Tutorial Questions
UNIT-5
1. What is role of intermediate Code generator in compilation process? Explain Various Forms
Of Intermediate Codes Used By Compiler.
2. Explain various methods of implementing three address statements with suitable examples.
(or) Explain about quadruples, triples and indirect triples of three-address statements of
intermediate code
3. Write quadruples, triples and indirect triples for the expression:
-(a*b)+(c+d)-(a+b+c+d)
(or) For the given expression generate different kinds of three-address
codes -(a*b)+(c+d)-(a+b+c+d)
4. Write the short note on: (i) Abstract syntax tree (ii) Polish notation
(iii) Three address code
5. Construct abstract syntax tree & DAG for the assignment statement
x:=a*b+c-a*b+d
6. Write the quadruple, triple, indirect triples for the statement
a:= b * -c + b * -c
7. Translate the assignment A:= -B*(C+D) into following
i) Quadruple ii) Triples iii) Indirect triples
8. Translate the expression -(a+b)*(c+d)+(a+b+c) into the following
i) Quadruples ii) Triples iii) Indirect triples
Prepared By: MD SHAKEEL AHMED, Associate Professor, Dept. Of IT, VVIT, Guntur Page 13
III IT-I SEM Regulation: R20 ATCD: Tutorial Questions
9. Convert the following arithmetic expressions into Abstract syntax tree, DAG, postfix
notation and three-address code:
i) b*-(a+b)
ii) a+b*(a+b)+c+d
10. What is code optimization? Compare machine dependent and independent code optimization
techniques.
11. What is code optimization? Explain about various levels and types of optimizations
(or) Explain different principle sources of optimization techniques with suitable examples
12. Discuss about principal sources of optimization.
13. Write short note on
a. Constant Folding
b. Dead Code Elimination
c. Code Motion
d. Induction Variable Elimination
14. Discuss briefly various loop optimization techniques.
15. Define flow graph. Explain the optimization of Basic Blocks.
16. Write about all issues in code generation. Describe it.
(or) Explain the different issues in the design of a code generator
17. Explain the peephole optimization Techniques?
(or) Discuss the transformations that are characteristic of peephole optimizations.
(or) What kinds of peephole techniques can be used to perform machine-dependent
optimizations?+
18. What is a basic block and flow graph? Explain how flow graph can be constructed for a given
program.
19. What is peephole optimization? How can it be performed? Give its role in code generation.
20. Discuss about register allocation and assignment in target code generation.
Prepared By: MD SHAKEEL AHMED, Associate Professor, Dept. Of IT, VVIT, Guntur Page 14