Formal Language Review Question
Formal Language Review Question
Formal Language Review Question
- a) \( a^m b^n \)
- b) \( \lambda \)
- c) \( a^n b^n \)
- d) \( a^m+1 b^m \)
- **Explanation**: The grammar produces strings with equal numbers of \( a \)'s and \( b \)'s.
The first rule \( S \rightarrow aSb \) ensures that for each \( a \) there is a corresponding \( b \)
following it. The second rule \( S \rightarrow A \) allows the transition to \( A \) which produces
a sequence of \( a \)'s followed by an empty string (since \( A \rightarrow \lambda \)).
- a) Unrestricted
- b) Context-sensitive grammar
- c) Context-free grammar
- d) Regular grammar
- **Explanation**: This grammar fits the definition of a context-free grammar (CFG) because
each production rule has a single non-terminal on the left-hand side.
- d) None of these
- **Explanation**: \( (a, b)^* \) denotes the Kleene star operation, which includes all possible
strings formed by \( a \) and \( b \), including the empty string (null).
4. **Which of the following grammar generates strings with any number of 1's?**
- **Explanation**: This grammar can generate strings with any number of 1's because \( S \
rightarrow 1S \) allows for the addition of any number of 1's, and \( S \rightarrow \epsilon \)
terminates the production.
5. **What is the highest type number to the grammar given by the following production rules \
( S \rightarrow Aa, A \rightarrow c|Ba, B \rightarrow abc \)?**
- a) Zero
- b) One
- c) Two
- d) Three
- **Answer: c) Two**
- **Explanation**: This is a context-free grammar, which is Type 2 in the Chomsky
hierarchy. The productions fit the context-free grammar definition where each production has a
single non-terminal on the left-hand side.
- a) Alphabet
- b) String
- c) Set
- d) None of these
- **Answer: b) String**
- **Answer: c) If control enters, there is no way to come out from the state**
- **Explanation**: A dead state is one where, once entered, there are no transitions leading
out that lead to an accepting state. Hence, any string that reaches a dead state will be rejected by
the automaton.
- (FA diagram shows states and transitions with specific labels, typically a small automaton)
- a) \( (ab)^* \)
- b) \( bb^*a \)
- c) \( b(ba)^*a \)
- d) Null
- **Explanation**: Based on the typical transitions of such a finite automaton (FA), the
language it accepts would involve alternating 'a' and 'b' in pairs, starting from the initial state and
returning to it after consuming each 'ab' pair.
These answers provide a detailed understanding of each question, explaining why each option is
correct or incorrect.
10. A string after full traversal is called not accepted by an NFA if it results in
o a) Some non-final states
o b) All non-final states
o c) A single non-final state
o d) Some final states
o Answer: b) All non-final states
Explanation: An NFA accepts a string if at least one of the possible
traversal paths ends in a final state. If the string ends in all non-final states,
then it is not accepted.
11. Consider the strings u=ababbau = ababbau=ababba, v=babv = babv=bab, and
w=aabbw = aabbw=aabb. Which of the following statement is true for the given
transitional system?
o a) The automaton accepts uuu and vvv but not www.
o b) The automaton accepts each of u,v,u, v,u,v, and www.
o c) The automaton rejects each of u,v,u, v,u,v, and www.
o d) The automaton accepts uuu but rejects vvv and www.
o Answer: d) The automaton accepts uuu but rejects vvv and www.
Explanation: The diagram needs to be analyzed to determine which
strings are accepted. u=ababbau = ababbau=ababba is accepted as it
follows the path through the states reaching a final state. vvv and www do
not reach the final state as per the given transitions.
12. Consider the following deterministic finite state automaton M. Let SSS denote the
set of seven-bit binary strings in which the first, fourth, and last bits are 1. The
number of strings in SSS that are accepted by MMM is
o a) 1
o b) 2
o c) 3
o d) none of the above
o Answer: a) 1
Explanation: Given the conditions, there is only one seven-bit binary
string where the first, fourth, and last bits are 1. It should be in the form of
1xxx1xx1xxx1xx1xxx1xx and should be validated against the DFA.
13. If the final state and non-final states in the following DFA are interchanged, then
which of the following languages over the alphabet {a,b}\{a, b\}{a,b} will be accepted
by the new DFA?
o a) Set of all strings that do not end with ababab
o b) Set of all strings that begin with either an aaa or a bbb
o c) Set of all strings that do not contain the substring ababab
o d) The set described by the regular expression
b∗aa∗(ba)∗b∗b^*aa^*(ba)^*b^*b∗aa∗(ba)∗b∗
o Answer: c) Set of all strings that do not contain the substring ababab
Explanation: Interchanging the final and non-final states will result in a
DFA that rejects any string containing ababab.
14. The language of all words with at least 2 aaa's can be described by the regular
expression
o a) (ab)∗a(ab)^*a(ab)∗a
o b) (a+b)∗ab∗a(a+b)∗(a + b)^*ab^*a(a + b)^*(a+b)∗ab∗a(a+b)∗
o c) b∗ab∗(a+b)∗b^*ab^*(a + b)^*b∗ab∗(a+b)∗
o d) All of the above
o Answer: d) All of the above
Explanation: All given regular expressions can generate strings with at
least two aaa's in various ways.
15. Which of the strings do not belong to the regular expression (ba+baa)∗aabba(ba +
baa)^*aabba(ba+baa)∗aabba
o a) baaaab
o b) babaabaaab
o c) babababa
o d) baaaaba
o Answer: c) babababa
Explanation: The regular expression specifies that strings are composed
of repetitions of "ba" or "baa" followed by "aabba". The string "babababa"
does not fit this pattern as it lacks the necessary structure and the "aabba"
ending.
Fill in blank
1. Regular expression is accepted by type 3 grammar.
o Explanation: Type 3 grammars are also known as regular grammars, which can
be used to describe regular languages. Regular expressions are equivalent to
regular grammars.
2. DFA is a finite automata where for all cases for a single input given to a single state, the
machine goes to a single state.
o Explanation: In a Deterministic Finite Automaton (DFA), each state has exactly
one transition for each input symbol.
3. In the tabular format representation of finite automata, by single circle a non-final state
is represented.
o Explanation: A single circle represents a non-final (non-accepting) state, while a
double circle represents a final (accepting) state.
4. The lexical analyzer is designed by regular expressions.
o Explanation: Lexical analyzers or lexers are typically designed using regular
expressions to match patterns in the input string.
5. If any finite automata contains any ɛ (null) move or transition, then that finite automata is
called NFA (Non-deterministic Finite Automaton) with ɛ moves.
o Explanation: An NFA with epsilon (ɛ) transitions allows for state transitions
without consuming any input symbols.
6. The set of all states that can be reached from that state to all the states with input ɛ is
called epsilon-closure.
o Explanation: Epsilon-closure of a state is the set of states that can be reached
from the given state by only ɛ transitions.
7. A CFG G is said to be ambiguous if there exists some W∈L(G)W \in L(G)W∈L(G) that
has at least two distinct parse trees.
o Explanation: A context-free grammar is ambiguous if there is at least one string
in the language generated by the grammar that has more than one distinct parse
tree or derivation.
8. Context-free languages are not closed under intersection and complementation.
o Explanation: Context-free languages are closed under union, concatenation, and
Kleene star, but not under intersection and complementation.