Compilers Questions and Answers – Transformation from NFA to DFA – 2

This set of Compilers Multiple Choice Questions & Answers (MCQs) focuses on “Transformation from NFA to DFA – 2”.

1. A deterministic finite automation (DFA)D with alphabet ∑ = {a,b} is given below. Which of the following is a valid minimal DFA which accepts the same language as D?
Find the finite automation from the given diagram
a) Find the same language from the given diagram
b) Find the minimal DFA from the given diagram
c) Find the alphabet ∑ = {a,b} from the given diagram
d)Find accept ‘b’of string from the given diagram
View Answer

Answer: a
Explanation: Two options are invalid because they both accept ‘b’ as a string which is not accepted by give DFA. D is invalid because it accepts bb+a which are not accepted by given DFA.

2. The lexical analysis for a modern language such as Java needs the power of which one of the following machine models in a necessary and sufficient sense?
a) Finite state automata
b) Deterministic pushdown automata
c) Non-deterministic pushdown automata
d) Turing machine
View Answer

Answer: a
Explanation: Initially in lexical analysis the program is divided into tokens. Tokens can be expressed as regular expressions: [a-zA-Z] [a-zA-Z0-9]*
the keyword if is given by if.
Integers are given by [+-]? [0-9]+.

3. Is empty string a valid input in Ndfa.
a) True
b) False
View Answer

Answer: a
Explanation: Empty strings can be inputted n a NDFA.
advertisement
advertisement

4. What is the complement of the language accepted by the NFA shown below? Assume ∑ = {a} and ε is the empty string.
Find the  complement of the language from the given diagram
a) Φ
b) ε
c) a
d) {a, ε}
View Answer

Answer: b
Explanation: The given alphabet ∑ contains only one symbol {a} and the given NFA accepts all strings with any number of occurrences of ‘a’. Hence the complement is an empty string.

5. Given the language L = {ab, aa, baa}, whih of the following strings are in L*?

i) abaabaaabaa
ii) aaaabaaaa
iii) baaaaabaaaab
iv) baaaaabaa
Sanfoundry Certification Contest of the Month is Live. 100+ Subjects. Participate Now!

a) i, ii and iii
b) ii, iii and iv
c) i, ii and iv
d) i, iii and iv
View Answer

Answer: c
Explanation: Any combination of strings in set {ab, aa, baa} will be in L*.
i) “abaabaaabaa” can be partitioned as a combination of strings in set {ab, aa, baa}. The partitions are “ab aa baa ab aa”
ii) “aaaabaaaa” can be partitioned as a combination of strings in set {ab, aa, baa}. The partitions are “aa ab aa aa”
iii) “baaaaabaaaab” cannot be partitioned as a combination of strings in set {ab, aa, baa}
iv) “baaaaabaa” can be partitioned as a combination of strings in set {ab, aa, baa}. The partitions are “baa aa ab aa”.

6. Consider the set of strings on {0,1} in which, every substring of 3 symbols has at most two zeros. Complete the partially completed DFA that accepts this language is shown below.
Find the set of strings from the given diagram
The missing arcs in the DFA are
a) Find the substring of 3 symbols from the given diagram
b) Find the most two zeros from the given diagram
c) Find the completed DFA from the given diagram
d) Find the accepting states from the given diagram
View Answer

Answer: d
Explanation: State ‘q’ is trap state. All other states are accepting states. In state 00, DFA must move to ‘q’ for input symbol 0. All (non-trap) states indicate names indicate the characters seen before reaching that particular state.
advertisement

7. Which of the following problems occur?

i) Does a given program ever produce an output?
ii) If L is a CFL, then is L’ is also context-free?
iii) L’ is regular only if L is regular?
iv) If L is a recursive language, then, L’ is also recursive?

a) i, ii, iii, iv
b) i, ii
c) ii, iii, iv
d) iii, iv
View Answer

Answer: d
Explanation: i) Is a variation of Turing Machine Halting problem and it is undecidable.
….ii) Context Free Languages are not closed under intersection and complement.
….iii) Complement of Regular languages is also regular.
….iv) Recursive Languages is closed under complement.
advertisement

8. The definition of a language L with alphabet {a} is given as following. L = { ank | k > 0, and n is a positive integer constant} What is the minimum number of states needed in a DFA to recognize L?
a) k+1
b) n+1
c) 2n+1
d) 2k+1
View Answer

Answer: b
Explanation: Note that n is a constant and k is any positive integer. For example, let n=3, then the DFA must be able to accept aaa, aaaaaa, aaaaaaaaa, , .. build such a DFA, 4 states are required.
Find the definition of a language L from the given diagram

Sanfoundry Global Education & Learning Series – Compilers.

To practice all areas of Compilers, here is complete set of 1000+ Multiple Choice Questions and Answers.

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.