Docsity

12 Questions on Thompson's Construction Algorithm | CMSC 430, Exams of Computer Science

Toggle sidebar
bg1
CMSC 430, Practice Problems 1
For these practice problems, when creating NFAs from REs, use Thompson’s
construction algorithm, but with a modified algorithm for computing closure. Instead of
adding an epsilon edge from the final state back to the start state of the original NFA, add
the epsilon edge from the final state back to the start state of the new NFA instead. The
resulting NFA should appear as follows:
→
→→
→
1. Describe the languages denoted by the following regular expressions:
a. 0(0|1)∗0
b. ((ε |0)1∗)∗
c. (0|1)∗0(0|1)(0|1)
2. Regular expressions
a. Give a regular expression for all binary numbers including the substring “101”.
b. Give a regular expression for all binary numbers with an even number of 1’s.
c. Give a regular expression for all binary numbers that don’t include “000”.
3. Finite automata
a. Give a NFA that only accepts binary numbers including the substring “101”.
b. Give a NFA that only accepts binary numbers that include either “00” or “11”.
c. Give a NFA that only accepts binary numbers that include both “00” and “11”.
d. Compute the ε-closure of the start state for each of the NFA above.
e. Give a DFA that only accepts binary number with an odd number of 1’s.
f. Give a DFA that only accepts binary numbers that include “000”.
g. Give a DFA that only accepts binary numbers that don’t include “000”.
4. Reducing REs to DFAs
For each regular expression: 1*, (0|01)*0
a. Reduce the RE to an NFA using the modified Thompson’s algorithm above.
b. Reduce the resulting NFA to an DFA using the subset algorithm.
c. Show whether the DFA accepts / rejects the strings “1”, “11”, “101”
d. Minimize the resulting DFA using Hopcroft reduction
pf3
Discount

On special offer

Partial preview of the text

Download 12 Questions on Thompson's Construction Algorithm | CMSC 430 and more Exams Computer Science in PDF only on Docsity!

CMSC 430, Practice Problems 1

For these practice problems, when creating NFAs from REs, use Thompson’s construction algorithm, but with a modified algorithm for computing closure. Instead of adding an epsilon edge from the final state back to the start state of the original NFA, add the epsilon edge from the final state back to the start state of the new NFA instead. The resulting NFA should appear as follows:

  1. Describe the languages denoted by the following regular expressions: a. 0(0|1)∗ 0 b. ((ε |0)1∗)∗ c. (0|1)∗0(0|1)(0|1)
  2. Regular expressions a. Give a regular expression for all binary numbers including the substring “101”. b. Give a regular expression for all binary numbers with an even number of 1’s. c. Give a regular expression for all binary numbers that don’t include “000”.
  3. Finite automata a. Give a NFA that only accepts binary numbers including the substring “101”. b. Give a NFA that only accepts binary numbers that include either “00” or “11”. c. Give a NFA that only accepts binary numbers that include both “00” and “11”. d. Compute the ε-closure of the start state for each of the NFA above. e. Give a DFA that only accepts binary number with an odd number of 1’s. f. Give a DFA that only accepts binary numbers that include “000”. g. Give a DFA that only accepts binary numbers that don’t include “000”.
  4. Reducing REs to DFAs For each regular expression: 1, (0|01) a. Reduce the RE to an NFA using the modified Thompson’s algorithm above. b. Reduce the resulting NFA to an DFA using the subset algorithm. c. Show whether the DFA accepts / rejects the strings “1”, “11”, “101” d. Minimize the resulting DFA using Hopcroft reduction
  1. Describing grammars a. Describe the language accepted by the following grammar: S → abS | a b. Describe the language accepted by the following grammar: S → aSb | ε c. Describe the language accepted by the following grammar: S → bSb | A A → aA | ε d. Describe the language accepted by the following grammar: S → AS | B A → aAc | Aa | ε B→ bBb | ε e. Describe the language accepted by the following grammar: S → S and S | S or S | (S) | true | false f. Which of the previous grammars are left recursive? g. Which of the previous grammars are right recursive? h. Which of the previous grammars are ambiguous? Provide proof.
  2. Creating grammars a. Write a grammar for axby, where x = y b. Write a grammar for axby, where x > y c. Write a grammar for axby, where x = 2y d. Write a grammar for all strings of a and b that are palindromes. e. Write a grammar for all strings of a and b that include the substring baa. f. Write a grammar for all strings of a and b with an odd number of a ’s and b ’s.
  3. Derivations and parse trees For the following grammar: S → S and S | true a. List 4 possible derivations for the string “true and true and true”. b. Label each derivation as left-most, right-most, or neither. c. List the parse tree for each derivation
  4. Consider the following grammar S → aSbS | bSaS | ε a. Prove grammar is ambiguous by finding 2 left-most derivations for ”abab” b. Prove grammar is ambiguous by finding 2 right-most derivations for ”abab”
  5. Consider the following grammar: S → S and S | S or S | (S) | true | false a. Compute First sets for each production and nonterminal b. Explain why the grammar cannot be parsed by a LL(1) parser
  6. Consider the following grammar: S → abS | acS | c a. Compute First sets for each production and nonterminal b. Show why the grammar cannot be parsed by a LL(1) parser. c. Rewrite the grammar so it can be parsed by a LL(1) parser. d. Write a recursive descent parser for the rewritten grammar.