GATE Overflow - Recent questions tagged regular-expressions
https://gateoverflow.in/tag/regular-expressions
Powered by Question2AnswerMichael Sipser Edition 3 Exercise 4 Question 22 (Page No. 212)
https://gateoverflow.in/323803/michael-sipser-edition-3-exercise-4-question-22-page-no-212
Let $PREFIX-FREE_{REX} = \{\langle R \rangle \mid \text{R is a regular expression and L(R) is prefix-free}\}$. Show that $PREFIX FREE_{REX}$ is decidable. Why does a similar approach fail to show that $PREFIX-FREE_{CFG}$ is decidable?Theory of Computationhttps://gateoverflow.in/323803/michael-sipser-edition-3-exercise-4-question-22-page-no-212Thu, 17 Oct 2019 13:13:22 +0000Michael Sipser Edition 3 Exercise 4 Question 2 (Page No. 211)
https://gateoverflow.in/323652/michael-sipser-edition-3-exercise-4-question-2-page-no-211
Consider the problem of determining whether a DFA and a regular expression are equivalent. Express this problem as a language and show that it is decidable.Theory of Computationhttps://gateoverflow.in/323652/michael-sipser-edition-3-exercise-4-question-2-page-no-211Tue, 15 Oct 2019 18:35:44 +0000CMI2019-B-1
https://gateoverflow.in/320522/cmi2019-b-1
<p>Consider an alphabet $\Sigma=\{a,b\}.$</p>
<p>Let $L_{1}$ be the language given by the regular expression $(a+b)^{\ast}bb(a+b)^{\ast}$ and let $L_{2}$ be the language $baa^{\ast}b.$</p>
<p>Define $L:=\{u\in\Sigma^{\ast}\mid \exists w\in L_{2}\: s.t.\: uw\in L_{1}\}.$</p>
<ol start="1" style="list-style-type:upper-alpha">
<li>Give an example of a word in $L.$</li>
<li>Give an example of a word not in $L.$</li>
<li>Construct an NFA for $L.$</li>
</ol>Theory of Computationhttps://gateoverflow.in/320522/cmi2019-b-1Fri, 13 Sep 2019 14:36:06 +0000CMI2018-A-1
https://gateoverflow.in/320492/cmi2018-a-1
<p>Which of the words below matches the regular expression $a(a+b)^{\ast}b+b(a+b)^{\ast}a$?</p>
<ol start="1" style="list-style-type:upper-alpha">
<li>$aba$</li>
<li>$bab$</li>
<li>$abba$</li>
<li>$aabb$</li>
</ol>Theory of Computationhttps://gateoverflow.in/320492/cmi2018-a-1Fri, 13 Sep 2019 14:34:33 +0000Ullman (Compiler Design) Edition 2 Exercise 5.2 Question 6 (Page No. 317)
https://gateoverflow.in/319938/ullman-compiler-design-edition-exercise-question-page-317
Implement Algorithm $3.23$, which converts a regular expression into a nondeterministic finite automaton, by an L-attributed SDD on a top-down parsable grammar. Assume that there is a token char representing any character, and that char.$lexval$ is the character it represents. You may also assume the existence of a function $new()$ that returns a new state, that is, a state never before returned by this function. Use any convenient notation to specify the transitions of the $NFA$.Compiler Designhttps://gateoverflow.in/319938/ullman-compiler-design-edition-exercise-question-page-317Fri, 06 Sep 2019 17:39:17 +0000Ullman (Compiler Design) Edition 2 Exercise 4.3 Question 2 (Page No. 216 - 217)
https://gateoverflow.in/318949/ullman-compiler-design-edition-exercise-question-page-216
<p>Repeat Exercise 4.3.1 on the following grammars:</p>
<ol start="1" style="list-style-type:lower-alpha">
<li>$S\rightarrow SS+\mid SS\: \ast\mid a$</li>
<li>$S\rightarrow 0S1\mid 01$</li>
<li>$S\rightarrow S ( S ) S\mid \epsilon$</li>
<li>$S\rightarrow (L)\mid a$ and $L\rightarrow L,S\mid S$</li>
<li>The following grammar for boolean expressions</li>
</ol>
<ul>
<li>$bexpr\rightarrow bexpr\:or\:bterm\mid bterm$</li>
<li>$bterm\rightarrow bterm\:and\:bfactor\mid bfactor$</li>
<li>$bfactor\rightarrow not\: bfactor\mid ( bexpr )\mid true \mid false $</li>
</ul>Compiler Designhttps://gateoverflow.in/318949/ullman-compiler-design-edition-exercise-question-page-216Tue, 20 Aug 2019 07:59:55 +0000Ullman (Compiler Design) Edition 2 Exercise 4.3 Question 1 (Page No. 216)
https://gateoverflow.in/318948/ullman-compiler-design-edition-exercise-question-page-216
<p>The following is a grammar for regular expressions over symbols $a$ and $b$ only, using $+$ in place of $\mid$ for union, to avoid conflict with the use of vertical bar as a metasymbol in grammars:</p>
<ul>
<li>$rexpr\rightarrow rexpr+rterm\mid rterm$ </li>
<li>$rterm\rightarrow rterm\:rfactor\mid rfactor$</li>
<li>$rfactor\rightarrow rfactor \:\ast\mid rprimary$</li>
<li>$rprimary\rightarrow a\mid b$</li>
</ul>
<ol start="1" style="list-style-type:lower-alpha">
<li>Left factor this grammar.</li>
<li>Does left factoring make the grammar suitable for top-down parsing?</li>
<li>In addition to left factoring, eliminate left recursion from the original grammar.</li>
<li>Is the resulting grammar suitable for top-down parsing? </li>
</ol>Compiler Designhttps://gateoverflow.in/318948/ullman-compiler-design-edition-exercise-question-page-216Tue, 20 Aug 2019 07:45:23 +0000Ullman (Compiler Design) Edition 2 Exercise 3.3 Question 12 (Page No. 128)
https://gateoverflow.in/318193/ullman-compiler-design-edition-exercise-question-page-128
SQL allows a rudimentary form of patterns in which two characters have special meaning: underscore (_) stands for any one character and percent-sign (%) stands for any string of $0$ or more characters. In addition, the programmer may define any character, say e, to be the escape character, so e preceding an e preceding -, %, or another e gives the character that follows its literal meaning. Show how to express any SQL pattern as a regular expression, given that we know which character is the escape character.Compiler Designhttps://gateoverflow.in/318193/ullman-compiler-design-edition-exercise-question-page-128Mon, 05 Aug 2019 18:18:29 +0000Ullman (Compiler Design) Edition 2 Exercise 3.3 Question 11 (Page No. 127 - 128)
https://gateoverflow.in/318192/ullman-compiler-design-edition-exercise-question-page-127
<p> The UNIX shell command sh uses the operators in Fig. $3.9$ in filename expressions to describe sets of file names. For example, the filename expression *.o matches all filenames ending in. o; sort 1. ? matches all filenames of the form sort. c, where c is any character. Show how sh filename expressions can be replaced by equivalent regular expressions using only the basic union, concatenation, and closure operators.</p>
<p><img alt="" src="https://gateoverflow.in/?qa=blob&qa_blobid=11988557617889816406"></p>Compiler Designhttps://gateoverflow.in/318192/ullman-compiler-design-edition-exercise-question-page-127Mon, 05 Aug 2019 18:14:42 +0000Ullman (Compiler Design) Edition 2 Exercise 3.3 Question 10 (Page No. 127)
https://gateoverflow.in/318190/ullman-compiler-design-edition-exercise-question-page-127
<p>The operator ^ matches the left end of a line, and \$ matches the right end of a line. The operator ^ is also used to introduce complemented character classes, but the context always makes it clear which meaning is intended. For example, ^ [^aeiou]* \$ matches any complete line that does not contain a lowercase vowel.</p>
<ol start="1" style="list-style-type:lower-alpha">
<li>How do you tell which meaning of ^ is intended?</li>
<li>Can you always replace a regular expression using the ^ and $ operators by an equivalent expression that does not use either of these operators?</li>
</ol>Compiler Designhttps://gateoverflow.in/318190/ullman-compiler-design-edition-exercise-question-page-127Mon, 05 Aug 2019 18:03:34 +0000Ullman (Compiler Design) Edition 2 Exercise 3.3 Question 9 (Page No. 127)
https://gateoverflow.in/318189/ullman-compiler-design-edition-exercise-question-page-127
The regular expression $r\{m, n\}$ matches from $m$ to $n$ occurrences of the pattern $r$. For example, $a [1, 5]$ matches a string of one to five a's. Show that for every regular expression containing repetition operators of this form, there is an equivalent regular expression without repetition operators.Compiler Designhttps://gateoverflow.in/318189/ullman-compiler-design-edition-exercise-question-page-127Mon, 05 Aug 2019 17:56:46 +0000Ullman (Compiler Design) Edition 2 Exercise 3.3 Question 8 (Page No. 126 - 127)
https://gateoverflow.in/318188/ullman-compiler-design-edition-exercise-question-page-126
<p>In Lex, a complemented character class represents any character except the ones listed in the character class. We denote a complemented class by using ^ as the first character; this symbol (caret) is not itself part of the class being complemented, unless it is listed within the class itself. Thus, [^ A-Za-z] matches any character that is not an uppercase or lowercase letter, and [^\^] represents any character but the caret (or newline, since newline cannot be in any character class). Show that for every regular expression with complemented character classes, there is an equivalent regular expression without complemented character classes.</p>
<p><img alt="" src="https://gateoverflow.in/?qa=blob&qa_blobid=15381427324172446382"></p>Compiler Designhttps://gateoverflow.in/318188/ullman-compiler-design-edition-exercise-question-page-126Mon, 05 Aug 2019 17:52:17 +0000Ullman (Compiler Design) Edition 2 Exercise 3.3 Question 7 (Page No. 126)
https://gateoverflow.in/318187/ullman-compiler-design-edition-exercise-question-page-126
Note that these regular expressions give all of the following<br />
symbols (operator characters) a special meaning:<br />
\ " . ^ $ [] * + ? {} | /<br />
Their special meaning must be turned off if they are needed to represent themselves in a character string. We can do so by quoting the character within a string of length one or more; e.g., the regular expression "**" matches the string **. We can also get the literal meaning of an operator character by preceding it by a backslash. Thus, the regular expression \*\* also matches the string **. Write a regular expression that matches the string "\.Compiler Designhttps://gateoverflow.in/318187/ullman-compiler-design-edition-exercise-question-page-126Mon, 05 Aug 2019 17:41:16 +0000Ullman (Compiler Design) Edition 2 Exercise 3.3 Question 6 (Page No. 126)
https://gateoverflow.in/318186/ullman-compiler-design-edition-exercise-question-page-126
<p>Write character classes for the following sets of characters:</p>
<ol start="1" style="list-style-type:lower-alpha">
<li>The first ten letters (up to "j" ) in either upper or lower case.</li>
<li>The lowercase consonants.</li>
<li>The "digits" in a hexadecimal number (choose either upper or lower case for the "digits" above 9).</li>
<li>The characters that can appear at the end of a legitimate English sentence (e.g., exclamation point).</li>
</ol>
<p>The following exercises, up to and including Exercise $3.3.10$, discuss the extended regular-expression notation from Lex (the lexical-analyzer generator that we shall discuss extensively in Section $3.5)$. The extended notation is listed in Fig.$3.8$.</p>
<p><img alt="" src="https://gateoverflow.in/?qa=blob&qa_blobid=9618220040403765369"></p>Compiler Designhttps://gateoverflow.in/318186/ullman-compiler-design-edition-exercise-question-page-126Mon, 05 Aug 2019 17:30:38 +0000Ullman (Compiler Design) Edition 2 Exercise 3.3 Question 4 (Page No. 125)
https://gateoverflow.in/318183/ullman-compiler-design-edition-exercise-question-page-125
Most languages are case sensitive, so keywords can be written only one way, and the regular expressions describing their lexeme is very simple. However, some languages, like SQL, are case insensitive, so a keyword can be written either in lowercase or in uppercase, or in any mixture of cases. Thus, the SQL keyword SELECT can also be written select, Select, or sElEcT, for instance. Show how to write a regular expression for a keyword in a case-insensitive language. Illustrate the idea by writing the expression for "select" in SQL.Compiler Designhttps://gateoverflow.in/318183/ullman-compiler-design-edition-exercise-question-page-125Mon, 05 Aug 2019 17:10:34 +0000Ullman (Compiler Design) Edition 2 Exercise 3.3 Question 2 (Page No. 125)
https://gateoverflow.in/318181/ullman-compiler-design-edition-exercise-question-page-125
<p> Describe the languages denoted by the following regular expressions:</p>
<ol start="1" style="list-style-type:lower-alpha">
<li>$a(a\mid b)^{\ast}a.$</li>
<li>$((\epsilon\mid a)b^{\ast})^{\ast}.$</li>
<li>$(a\mid b)^{\ast}a(a\mid b)(a\mid b).$</li>
<li>$a^{\ast}ba^{\ast}ba^{\ast}ba^{\ast}.$</li>
<li>$(aa\mid bb)^{\ast}((ab\mid ba)(aa\mid bb)^{\ast}(ab\mid ba)(aa\mid bb)^{\ast})^{\ast}.$</li>
</ol>Compiler Designhttps://gateoverflow.in/318181/ullman-compiler-design-edition-exercise-question-page-125Mon, 05 Aug 2019 17:00:51 +0000Michael Sipser Edition 3 Exercise 1 Question 22 (Page No. 87)
https://gateoverflow.in/310468/michael-sipser-edition-3-exercise-1-question-22-page-no-87
In certain programming languages, comments appear between delimiters such as $\text{/#}$ and $\text{#/}.$ Let $C$ be the language of all valid delimited comment strings. A member of $C$ must begin with $\text{/#}$ and end with $\text{#/}$ but have no intervening $\text{#/}.$ For simplicity, assume that the alphabet for $C$ is $\text{Σ = \{a, b, /, # \}.}$<br />
a. Give a $DFA$ that recognizes $C.$<br />
b. Give a regular expression that generates $C.$Theory of Computationhttps://gateoverflow.in/310468/michael-sipser-edition-3-exercise-1-question-22-page-no-87Sun, 21 Apr 2019 18:52:02 +0000Michael Sipser Edition 3 Exercise 1 Question 21 (Page No. 86)
https://gateoverflow.in/310467/michael-sipser-edition-3-exercise-1-question-21-page-no-86
<p>Use the procedure described in $\text{Lemma 1.60}$ to convert the following finite automata to regular expressions.</p>
<p><img alt="" src="https://gateoverflow.in/?qa=blob&qa_blobid=11381374725748877602"></p>Theory of Computationhttps://gateoverflow.in/310467/michael-sipser-edition-3-exercise-1-question-21-page-no-86Sun, 21 Apr 2019 18:47:39 +0000Michael Sipser Edition 3 Exercise 1 Question 20 (Page No. 86)
https://gateoverflow.in/310466/michael-sipser-edition-3-exercise-1-question-20-page-no-86
<p>For each of the following languages, give two strings that are members and two strings that are not members—a total of four strings for each part. Assume the alphabet $Σ = \{a,b\}$ in all parts.</p>
<ol start="1" style="list-style-type:lower-alpha">
<li>$a^{*}b^{*}$</li>
<li>$a(ba)^{*}b$</li>
<li>$a^{*}\cup b^{*}$</li>
<li>$(aaa)^{*}$</li>
<li>$\sum^{*}a\sum^{*}b\sum^{*}a\sum^{*}$</li>
<li>$aba\cup bab$</li>
<li>$(\epsilon\cup a)b$</li>
<li>$(a\cup ba\cup bb)\sum^{*}$</li>
</ol>Theory of Computationhttps://gateoverflow.in/310466/michael-sipser-edition-3-exercise-1-question-20-page-no-86Sun, 21 Apr 2019 18:42:40 +0000Michael Sipser Edition 3 Exercise 1 Question 19 (Page No. 86)
https://gateoverflow.in/310465/michael-sipser-edition-3-exercise-1-question-19-page-no-86
<p>Use the procedure described in $\text{Lemma 1.55}$ to convert the following regular expressions to non-deterministic finite automata.</p>
<ol start="1" style="list-style-type:lower-alpha">
<li>$(0\cup 1)^{*}000(0\cup 1)^{*}$</li>
<li>$(((00)^{*}(11))\cup 01)^{*}$</li>
<li>$\phi^{*}$</li>
</ol>Theory of Computationhttps://gateoverflow.in/310465/michael-sipser-edition-3-exercise-1-question-19-page-no-86Sun, 21 Apr 2019 18:31:50 +0000Michael Sipser Edition 3 Exercise 1 Question 18 (Page No. 86)
https://gateoverflow.in/310464/michael-sipser-edition-3-exercise-1-question-18-page-no-86
<p>Give regular expressions generating the languages of the alphabet is $\{0,1\}.$</p>
<ol start="1" style="list-style-type:lower-alpha">
<li>$\text{\{w| w begins with a 1 and ends with a 0\}}$</li>
<li>$\text{\{w| w contains at least three 1s\}}$</li>
<li>$\text{\{w| w contains the substring 0101 (i.e., w = x0101y for some x and y)\}}$</li>
<li>$\text{\{w| w has length at least 3 and its third symbol is a 0\}}$</li>
<li>$\text{\{w| w starts with 0 and has odd length, or starts with 1 and has even length\}}$</li>
<li>$\text{\{w| w doesn’t contain the substring 110\}}$</li>
<li>$\text{\{w| the length of w is at most 5\}}$</li>
<li>$\text{\{w| w is any string except 11 and 111\}}$</li>
<li>$\text{\{w| every odd position of w is a 1\}}$</li>
<li>$\text{\{w| w contains at least two 0's and at most one 1\}}$</li>
<li>$\{\epsilon, 0\}$</li>
<li>$\text{\{w| w contains an even number of 0's, or contains exactly two 1's\}}$</li>
<li>$\text{The empty set}$</li>
<li>$\text{All strings except the empty string}$ </li>
</ol>Theory of Computationhttps://gateoverflow.in/310464/michael-sipser-edition-3-exercise-1-question-18-page-no-86Sun, 21 Apr 2019 18:23:10 +0000Peter Linz Edition 4 Exercise 5.2 Question 10 (Page No. 145)
https://gateoverflow.in/309998/peter-linz-edition-4-exercise-5-2-question-10-page-no-145
Give an unambiguous grammar that generates the set of all regular expressions on $Σ =$ {$a,b$}.Theory of Computationhttps://gateoverflow.in/309998/peter-linz-edition-4-exercise-5-2-question-10-page-no-145Sun, 14 Apr 2019 17:26:04 +0000Ullman (TOC) Edition 3 Exercise 5.1 Question 5 (Page No. 182)
https://gateoverflow.in/309110/ullman-toc-edition-3-exercise-5-1-question-5-page-no-182
Let $T=\{0,1(,),+,*,\phi,e\}.$ We may think of $T$ as the set of symbols used by regular expressions over alphabet $\{0,1\};$ the only difference is that we use $e$ for symbol $\in,$ to avoid potential confusion in what follows. Your task is to design a CFG with set of terminals $T$ that generates exactly the regular expressions with alphabet $\{0,1\}.$Theory of Computationhttps://gateoverflow.in/309110/ullman-toc-edition-3-exercise-5-1-question-5-page-no-182Sat, 06 Apr 2019 11:11:36 +0000Ullman (TOC) Edition 3 Exercise 5.1 Question 2 (Page No. 182)
https://gateoverflow.in/309107/ullman-toc-edition-3-exercise-5-1-question-2-page-no-182
<p>The following grammar generates the language of regular expression $0^{*}1(0+1)^{*}:$</p>
<p>$S\rightarrow A1B$
<br>
$A\rightarrow 0A|\in$
<br>
$B\rightarrow B|1B|\in$</p>
<p>Give leftmost and rightmost derivations of the following strings$:$</p>
<ol start="1" style="list-style-type:lower-alpha">
<li>$00101$ </li>
<li>$1001$ </li>
<li>$00011$</li>
</ol>Theory of Computationhttps://gateoverflow.in/309107/ullman-toc-edition-3-exercise-5-1-question-2-page-no-182Sat, 06 Apr 2019 10:58:44 +0000Ullman (TOC) Edition 3 Exercise 4.2 Question 14 (Page No. 149 - 150)
https://gateoverflow.in/309092/ullman-toc-edition-3-exercise-4-2-question-14-page-no-149-150
<p>We described the $"$product construction$"$ that took two DFA's and constructed one DFA whose language is intersection of the languages of the first two.</p>
<ol start="1" style="list-style-type:lower-alpha">
<li>Show how to perform the product construction on NFA's (without $\in$ transitions).</li>
<li>Show how to perform the product construction on $\in-$NFA's</li>
<li>Show how to modify the product construction so the resulting DFA accepts the difference of the languages of the two given DFA's.</li>
<li>Show how to modify the product construction so the resulting DFA accepts the union of the languages of the two given DFA's.</li>
</ol>Theory of Computationhttps://gateoverflow.in/309092/ullman-toc-edition-3-exercise-4-2-question-14-page-no-149-150Sat, 06 Apr 2019 09:03:19 +0000Ullman (TOC) Edition 3 Exercise 4.2 Question 13 (Page No. 149)
https://gateoverflow.in/309091/ullman-toc-edition-3-exercise-4-2-question-13-page-no-149
<p>We can use closure properties to help prove certain languages are not regular. Start with the fact that the language $L_{0n1n}=\{0^{n}1^{n}|n\geq 0\}$ is not a regular set. Prove the following languages not to be regular by transforming them using operations known to preserve regularity,to $L_{0n1n}:$</p>
<ol start="1" style="list-style-type:lower-alpha">
<li> $\{0^{i}1^{j}|i\neq j\}$</li>
<li> $\{0^{n}1^{m}2^{n-m}|n\geq m\geq 0\}$</li>
</ol>Theory of Computationhttps://gateoverflow.in/309091/ullman-toc-edition-3-exercise-4-2-question-13-page-no-149Sat, 06 Apr 2019 08:54:51 +0000Ullman (TOC) Edition 3 Exercise 4.2 Question 12 (Page No. 149)
https://gateoverflow.in/309090/ullman-toc-edition-3-exercise-4-2-question-12-page-no-149
Let $w_{1}=a_{0}a_{0}a_{1},$ and $w_{i}=w_{i-1}w_{i-1}a_{i}$ for all $i>1.$For instance,$w_{3}=a_{0}a_{0}a_{1}a_{0}a_{0}a_{1}a_{2}a_{0}a_{0}a_{1}a_{0}a_{0}a_{1}a_{2}a_{3}.$ The shortest regular expression for the language $L_{n}=\{w_{n}\},$ i.e., the language consisting of the one string $w_{n}$ is the string $w_{n}$ itself and the length of this expression is $2^{n+1}-1.$ However if we allow the intersection operator we, can write an expression for $L_{n}$ whose length is $O(n^{2}).$ Find such an expression. Hint $:$ Find $n$ languages, each with regular expressions of length $O(n).$ Whose intersection is $L.$Theory of Computationhttps://gateoverflow.in/309090/ullman-toc-edition-3-exercise-4-2-question-12-page-no-149Sat, 06 Apr 2019 08:45:53 +0000Ullman (TOC) Edition 3 Exercise 4.2 Question 11 (Page No. 149)
https://gateoverflow.in/309065/ullman-toc-edition-3-exercise-4-2-question-11-page-no-149
Show that the regular languages are closed under the following operation$:$ $\text{cycle(L)={we can write w as w = xy,such that yx is in L}}.$ For example if $L=\{01,011\},$then $cycle(L)=\{01,10,011,110,101\}.$ Hint$:$ Start with a DFA for $L$ and construct an $\in-NFA$ for $cycle(L).$Theory of Computationhttps://gateoverflow.in/309065/ullman-toc-edition-3-exercise-4-2-question-11-page-no-149Sat, 06 Apr 2019 06:58:41 +0000Ullman (TOC) Edition 3 Exercise 4.2 Question 10 (Page No. 149)
https://gateoverflow.in/309051/ullman-toc-edition-3-exercise-4-2-question-10-page-no-149
Suppose that $L$ is any language not necessarily regular whose alphabet is $\{0\};$i.e. the strings of $L$ consist of $0's$ only. Prove that $L^{*}$ is regular. Hint$:$ At first this theorem sounds preposterous. However, an example will help you see why it is true. Consider the language $\text{L=\{0^{i}| i is prime \},}$ which we know is not regular.Strings $00$ and $000$ are in $L,$ since $2$ and $3$ are both primes. Thus if $j\geq 2,$ we can show $0^{j}$ is in $L^{*}.$If $j$ is even ,use $j/2$ copies of $00,$ and if $j$ is odd ,use copy of $000$ and $(j-3)/2$ copies of $00.$ Thus ,$L^{*}=$ $\in + 000^{*}.$Theory of Computationhttps://gateoverflow.in/309051/ullman-toc-edition-3-exercise-4-2-question-10-page-no-149Sat, 06 Apr 2019 06:33:58 +0000Ullman (TOC) Edition 3 Exercise 4.2 Question 9 (Page No. 148 - 149)
https://gateoverflow.in/309046/ullman-toc-edition-3-exercise-4-2-question-9-page-no-148-149
<p>We can generalize question $8$ to a number of functions that determine how much of the string we take.If $f$ is a function of integers, define $f(L)$ to be $\text{\{w| for some $x,$ with $|x|=f(|w|)$,we have $wx$ in L.\}}$ For instance,the operation $\text{half}$ corresponds to $f$ being the identity function $f(n)=n,$ since $\text{half(L)}$ is define by having $|x|=|w|.$Show that if $L$ is a regular language,then so is $f(L),$ if $f$ is one of the following function$:$</p>
<ol start="1" style="list-style-type:lower-alpha">
<li>$f(n)=2n(i.e.,$ take the first thirds of strings$).$</li>
<li>$f(n)=n^{2}(i.e.,$ the amount we take has length equal to the square root of what we do not take.</li>
<li>$f(n)=2^{n}(i.e,$ what we take has length equal to the logarithm of what we leave$).$</li>
</ol>Theory of Computationhttps://gateoverflow.in/309046/ullman-toc-edition-3-exercise-4-2-question-9-page-no-148-149Sat, 06 Apr 2019 06:11:51 +0000Ullman (TOC) Edition 3 Exercise 4.2 Question 8 (Page No. 148)
https://gateoverflow.in/308801/ullman-toc-edition-3-exercise-4-2-question-8-page-no-148
Let $L$ be a language.Define $\text{half(L)}$ to be the set of first halves of strings in $L,$ that is,$\{w|\text{for some x such that |x|=|w|,we have wx in L}\}.$For example,if $L=\{\in,0010,011,010110\}$ then $\text{half(L)}=\{\in,0,010\}.$ Notice that odd-length strings do not contribute to $\text{half(L)}$Prove that if $L$ is a regular language,so is $\text{half(L)}.$Theory of Computationhttps://gateoverflow.in/308801/ullman-toc-edition-3-exercise-4-2-question-8-page-no-148Thu, 04 Apr 2019 16:59:29 +0000Ullman (TOC) Edition 3 Exercise 4.2 Question 7 (Page No. 148)
https://gateoverflow.in/308795/ullman-toc-edition-3-exercise-4-2-question-7-page-no-148
If $w=a_{1}a_{2}.....a_{n}$ and $x=b_{1}b_{2}....b_{n}$ are strings of the same length, define $alt(w,x)$ to be the string in which the symbols of $w$ and $x$ alternate starting with $w$ that is $a_{1}b_{1}a_{2}b_{2}........a_{n}b_{n}.$If $L$ and $M$ are languages,define $alt(L,M)$ to be the set of strings of the form $alt(w,x),$where $w$ is any string in $L$ and $x$ is any string in $M$ of the same length. Prove that if $L$ and $M$ are regular,so is $alt(L,M).$Theory of Computationhttps://gateoverflow.in/308795/ullman-toc-edition-3-exercise-4-2-question-7-page-no-148Thu, 04 Apr 2019 16:38:58 +0000Peter Linz Edition 4 Exercise 4.1 Question 4 (Page No. 109)
https://gateoverflow.in/308776/peter-linz-edition-4-exercise-4-1-question-4-page-no-109
<p><u><em><strong>Theorem 4.3</strong></em></u></p>
<p>“Let h be a homomorphism. If L is a regular language, then its homomorphic image h (L) is also regular. The family of regular languages is therefore closed under arbitrary homomorphisms.”</p>
<p>
<br>
<u><em><strong>Proof:</strong></em></u> Let L be a regular language denoted by some regular expression $r$. We find $h (r)$ by substituting $h (a)$ for each symbol $a ∈ Σ$ of $r$. It can be shown directly by an appeal to the definition of a regular expression that the result is a regular expression. It is equally easy to see that the resulting expression denotes $h (L)$. All we need to do is to show that for every $w ∈ L (r)$, the corresponding $h(w)$ is in $L (h (r))$ and conversely that every $υ$ in $L (h (r))$ there is a $w$ in $L$, such that $υ = h (w)$. we claim that $h (L)$ is regular.</p>
<hr>
<p>In the proof of <em><strong>Theorem 4.3</strong></em>, show that $h (r)$ is a regular expression. Then show that $h (r)$ denotes $h (L)$.</p>Theory of Computationhttps://gateoverflow.in/308776/peter-linz-edition-4-exercise-4-1-question-4-page-no-109Thu, 04 Apr 2019 15:25:44 +0000Ullman (TOC) Edition 3 Exercise 4.2 Question 6 (Page No. 148)
https://gateoverflow.in/308723/ullman-toc-edition-3-exercise-4-2-question-6-page-no-148
<p>Show that the regular languages are closed under the following operations$:$</p>
<ol start="1" style="list-style-type:lower-alpha">
<li>$ min(L)=\big\{\text{w|w is in L, but no proper prefix of w is in L}\big\}.$</li>
<li>$ min(L)=\big\{\text{w|w is in L, and for no x other than $\in$ is wx in L}\big\}.$</li>
<li>$ init(L)=\big\{\text{w| for some x, wx is in L}\big\}.$</li>
</ol>Theory of Computationhttps://gateoverflow.in/308723/ullman-toc-edition-3-exercise-4-2-question-6-page-no-148Thu, 04 Apr 2019 10:06:12 +0000Ullman (TOC) Edition 3 Exercise 4.2 Question 5 (Page No. 148)
https://gateoverflow.in/308722/ullman-toc-edition-3-exercise-4-2-question-5-page-no-148
<p>The operation of Problem $4.2.3$ is sometimes viewed as a $"$derivative and $a/L$ is written $\frac{dL}{da}.$ These derivatives apply to regular expressions in a manner similar to the way ordinary derivatives apply to arithmetic expressions. Thus if $R$ is a regular expression, we shall use $\frac{dR}{da}$ to mean the same as $\frac{dL}{da},$if $L=L(R).$</p>
<ol start="1" style="list-style-type:lower-alpha">
<li>Show that $\frac{d(R+S)}{da}=\frac{dR}{da}+\frac{dS}{da}$</li>
<li>Give the rule for the $"$derivative$"$ of $RS.$ Hint$:$ You need to consider two cases$:$ if $L(R)$ does or does not contain $\in.$ This rule is not quite the same as the $"$product rule$"$ for ordinary derivatives, but is similar.</li>
<li>Give the rule for the $"$derivative$"$ of a closure, i.e.,$\frac{d(R^{*})}{da}$</li>
<li>Use the rules from $(a)-(c)$ to find the $"$derivatives of regular expression $(0+1)^{*}011$ with respect to $$0 and $1.$</li>
<li>Characterize those languages $L$ for which $\frac{dL}{d0}=\phi$</li>
<li>Characterize those languages $L$ for which $\frac{dL}{d0}=L$</li>
</ol>Theory of Computationhttps://gateoverflow.in/308722/ullman-toc-edition-3-exercise-4-2-question-5-page-no-148Thu, 04 Apr 2019 10:00:50 +0000Peter Linz Edition 4 Exercise 3.2 Question 17 (Page No. 89)
https://gateoverflow.in/308580/peter-linz-edition-4-exercise-3-2-question-17-page-no-89
<p>Analogous to the <a rel="nofollow" href="https://gateoverflow.in/308579/peter-linz-edition-4-exercise-3-2-question-16-page-no-89">previous exercise</a>, consider all words that can be formed from $L$ by dropping
<br>
a single symbol of the string. Formally define this operation drop for languages. Construct an nfa
<br>
for $drop (L)$, given an nfa for $L$.</p>Theory of Computationhttps://gateoverflow.in/308580/peter-linz-edition-4-exercise-3-2-question-17-page-no-89Wed, 03 Apr 2019 13:20:46 +0000Peter Linz Edition 4 Exercise 3.2 Question 16 (Page No. 89)
https://gateoverflow.in/308579/peter-linz-edition-4-exercise-3-2-question-16-page-no-89
In some applications, such as programs that check spelling, we may not need an exact match of<br />
the pattern, only an approximate one. Once the notion of an approximate match has been made<br />
precise, automata theory can be applied to construct approximate pattern matchers. As an<br />
illustration of this, consider patterns derived from the original ones by insertion of one symbol.<br />
Let L be a regular language on $Σ$ and define<br />
$insert (L) =$ {$uav : a ∈ Σ,uv ∈ L$}.<br />
In effect, $insert (L)$ contains all the words created from $L$ by inserting a spurious symbol<br />
anywhere in a word.<br />
(a) Given an nfa for $L$, show how one can construct an nfa for $insert (L)$.<br />
(b) Discuss how you might use this to write a pattern-recognition program for $insert (L)$, using as<br />
input a regular expression for $L$.Theory of Computationhttps://gateoverflow.in/308579/peter-linz-edition-4-exercise-3-2-question-16-page-no-89Wed, 03 Apr 2019 13:17:34 +0000Peter Linz Edition 4 Exercise 3.2 Question 15 (Page No. 89)
https://gateoverflow.in/308578/peter-linz-edition-4-exercise-3-2-question-15-page-no-89
Write a regular expression for the set of all $C$ real numbers.Theory of Computationhttps://gateoverflow.in/308578/peter-linz-edition-4-exercise-3-2-question-15-page-no-89Wed, 03 Apr 2019 13:14:31 +0000Peter Linz Edition 4 Exercise 3.2 Question 13 (Page No. 88)
https://gateoverflow.in/308577/peter-linz-edition-4-exercise-3-2-question-13-page-no-88
Find a regular expression for the following languages on {$a, b$}.<br />
(a) $L =$ {$w : n_a (w)$ and $n_b (w)$ are both even}.<br />
(b) $L =$ {$w :(n_a (w) - n_b (w))$ mod $3 = 1$}.<br />
(c) $L =$ {$w :(n_a (w) - n_b (w))$ mod $3 = 0$}.<br />
(d) $L =$ {$w :2n_a (w)+3n_b (w)$ is even}.Theory of Computationhttps://gateoverflow.in/308577/peter-linz-edition-4-exercise-3-2-question-13-page-no-88Wed, 03 Apr 2019 13:10:04 +0000Ullman (TOC) Edition 3 Exercise 3.4 Question 4 (Page No. 123)
https://gateoverflow.in/308574/ullman-toc-edition-3-exercise-3-4-question-4-page-no-123
Prove that $(L^{*}M^{*})^{*}=(L+M)^{*}.$Complete the proof by showing that strings in $(L^{*}M^{*})^{*}$ are also in $(L+M)^{*}.$Theory of Computationhttps://gateoverflow.in/308574/ullman-toc-edition-3-exercise-3-4-question-4-page-no-123Wed, 03 Apr 2019 13:03:09 +0000Ullman (TOC) Edition 3 Exercise 3.4 Question 3 (Page No. 122)
https://gateoverflow.in/308571/ullman-toc-edition-3-exercise-3-4-question-3-page-no-122
We developed the regular expression $(0+1)^{*}1(0+1)+(0+1)^{*}1(0+1)(0+1)$ Use the distributive laws to develop two different,simpler,equivalent expressions.Theory of Computationhttps://gateoverflow.in/308571/ullman-toc-edition-3-exercise-3-4-question-3-page-no-122Wed, 03 Apr 2019 12:56:44 +0000Ullman (TOC) Edition 3 Exercise 3.4 Question 2 (Page No. 122)
https://gateoverflow.in/308567/ullman-toc-edition-3-exercise-3-4-question-2-page-no-122
<p>Prove or disprove each of the following statements about regular expressions.</p>
<ol start="1" style="list-style-type:lower-alpha">
<li>$(R+S)^{*}=R^{*}+S^{*}$</li>
<li>$(RS+R)^{*}R=R(SR+R)^{*}$</li>
<li>$(RS+R)^{*}RS=(RR^{*}S)^{*}$</li>
<li>$(R+S)^{*}S=(R^{*}S)^{*}$</li>
<li>$S(RS+S)^{*}R=RR^{*}S(RR^{*}S)^{*}$</li>
</ol>Theory of Computationhttps://gateoverflow.in/308567/ullman-toc-edition-3-exercise-3-4-question-2-page-no-122Wed, 03 Apr 2019 12:50:51 +0000Ullman (TOC) Edition 3 Exercise 3.4 Question 1 (Page No. 121 - 122)
https://gateoverflow.in/308566/ullman-toc-edition-3-exercise-3-4-question-1-page-no-121-122
<p>Verify the following identities involving regular expressions.</p>
<ol start="1" style="list-style-type:lower-alpha">
<li>$R+S=S+R$</li>
<li>$(R+S)+T=R+(S+T)$</li>
<li>$(RS)T=R(ST)$</li>
<li>$R(S+T)=RS+RT$</li>
<li>$(R+S)T=RT+ST$</li>
<li>$(R^{*})^{*}=R^{*}$</li>
<li>$(\in+R)^{*}=R^{*}$</li>
<li>$(R^{*}S^{*})^{*}=(R+S)^{*}$</li>
</ol>Theory of Computationhttps://gateoverflow.in/308566/ullman-toc-edition-3-exercise-3-4-question-1-page-no-121-122Wed, 03 Apr 2019 12:44:46 +0000Ullman (TOC) Edition 3 Exercise 3.3 Question 2 (Page No. 114)
https://gateoverflow.in/308560/ullman-toc-edition-3-exercise-3-3-question-2-page-no-114
Give a regular expression to represent salaries as they might appear in employment advertising. Consider that salaries might be given on a per hour, week, month or year basis. They may or may not appear with a dollar sign or other unit such as $"K"$ following. There may be a word or words nearby that identify a salary. Suggestion$:$ look at classified ads in a newspaper, or on-line jobs listings to get an idea of what patterns might be useful.Theory of Computationhttps://gateoverflow.in/308560/ullman-toc-edition-3-exercise-3-3-question-2-page-no-114Wed, 03 Apr 2019 12:33:28 +0000Ullman (TOC) Edition 3 Exercise 3.3 Question 1 (Page No. 114)
https://gateoverflow.in/308559/ullman-toc-edition-3-exercise-3-3-question-1-page-no-114
Give a regular expression to describe phone numbers in all the various forms you can think of. Consider international numbers as well as the fact that different countries have different numbers of digits in area codes and in local phone numbers.Theory of Computationhttps://gateoverflow.in/308559/ullman-toc-edition-3-exercise-3-3-question-1-page-no-114Wed, 03 Apr 2019 12:33:03 +0000Ullman (TOC) Edition 3 Exercise 3.2 Question 5 (Page No. 108)
https://gateoverflow.in/308549/ullman-toc-edition-3-exercise-3-2-question-5-page-no-108
<p>Convert the following regular expressions to NFA's with $\in-$transactions.</p>
<ol start="1" style="list-style-type:lower-alpha">
<li> $01^{*}$</li>
<li>$(0+1)01$</li>
<li>$00(0+1)^{*}$</li>
</ol>
<p>Eliminate $\in-$transactions from your $\in-NFA’s$</p>Theory of Computationhttps://gateoverflow.in/308549/ullman-toc-edition-3-exercise-3-2-question-5-page-no-108Wed, 03 Apr 2019 11:35:18 +0000Ullman (TOC) Edition 3 Exercise 3.2 Question 4 (Page No. 108)
https://gateoverflow.in/308548/ullman-toc-edition-3-exercise-3-2-question-4-page-no-108
<p>Convert the following regular expressions to NFA's with $\in-$transactions.</p>
<ol start="1" style="list-style-type:lower-alpha">
<li>$01^{*}$</li>
<li>$(0+1)01$</li>
<li>$00(0+1)^{*}$</li>
</ol>Theory of Computationhttps://gateoverflow.in/308548/ullman-toc-edition-3-exercise-3-2-question-4-page-no-108Wed, 03 Apr 2019 11:33:44 +0000Ullman (TOC) Edition 3 Exercise 3.2 Question 3 (Page No. 107)
https://gateoverflow.in/308547/ullman-toc-edition-3-exercise-3-2-question-3-page-no-107
<p>Convert the following DFA to a regular expression using the state elimination techniques.</p>
<p><img alt="" height="219" src="https://gateoverflow.in/?qa=blob&qa_blobid=13637655300905302340" width="271"></p>Theory of Computationhttps://gateoverflow.in/308547/ullman-toc-edition-3-exercise-3-2-question-3-page-no-107Wed, 03 Apr 2019 11:25:57 +0000Ullman (TOC) Edition 3 Exercise 3.2 Question 2 (Page No. 107)
https://gateoverflow.in/308544/ullman-toc-edition-3-exercise-3-2-question-2-page-no-107
<p>Here is a transition table for a DFA$:$</p>
<p><img alt="" height="192" src="https://gateoverflow.in/?qa=blob&qa_blobid=436119006347968142" width="328"></p>
<ol start="1" style="list-style-type:lower-alpha">
<li>Give all the regular expressions $R_{ij}^{0}.$ Note$:$Think of state $q_{i}$ as if it were the state with integer number $i.$</li>
<li> Give all the regular expressions $R_{ij}^{1}.$ Try to simplify the expressions as much as possible.</li>
<li>Give all the regular expressions $R_{ij}^{2}.$ Try to simplify the expressions as much as possible.</li>
<li>Give a regular expression for the language of the automaton.</li>
<li>Construct the transition diagram for the DFA and give a regular expression for its language by eliminating state $q_{2}.$</li>
</ol>Theory of Computationhttps://gateoverflow.in/308544/ullman-toc-edition-3-exercise-3-2-question-2-page-no-107Wed, 03 Apr 2019 11:22:17 +0000Ullman (TOC) Edition 3 Exercise 3.2 Question 1 (Page No. 107)
https://gateoverflow.in/308543/ullman-toc-edition-3-exercise-3-2-question-1-page-no-107
<p>Here is a transition table for a DFA$:$</p>
<p><img alt="" height="163" src="https://gateoverflow.in/?qa=blob&qa_blobid=5081190679061429704" width="262"></p>
<p> </p>
<ol start="1" style="list-style-type:lower-alpha">
<li>Give all the regular expressions $R_{ij}^{0}.$ Note$:$Think of state $q_{i}$ as if it were the state with integer number $i.$</li>
<li> Give all the regular expressions $R_{ij}^{1}.$ Try to simplify the expressions as much as possible.</li>
<li>Give all the regular expressions $R_{ij}^{2}.$ Try to simplify the expressions as much as possible.</li>
<li>Give a regular expression for the language of the automaton.</li>
<li>Construct the transition diagram for the DFA and give a regular expression for its language by eliminating state $q_{2}.$</li>
</ol>Theory of Computationhttps://gateoverflow.in/308543/ullman-toc-edition-3-exercise-3-2-question-1-page-no-107Wed, 03 Apr 2019 11:20:38 +0000