HiveBrain v1.2.0
Get Started
← Back to all entries
patternModerate

String of minimum length in $\{a, b\}^*$ not in a regular expression

Submitted by: @import:stackexchange-cs··
0
Viewed 0 times
expressionlengthregularminimumnotstring

Problem

I'm doing an exercise in my book, the question is to find a string of minimum length in $\{a, b\}^*$ not in the language corresponding to the given regular expression.

a. $b^(ab)^a^*$

My answer: $aab$

b. $(a^ + b^)(a^ + b^)(a^ + b^)$

My answer: $abab$

c. $a^(baa^)^b^$

My answer: $bba$

d. $b^(a + ba)^b^*$

My answer: $abba$

I came up with my answers by trial and error. I don't know for sure if these are the shortest possible strings. Is the best method trial and error, or would there be some better algorithmic way?

Solution

First, the string of minimum length might not be defined properly since it might not be unique.

Here is a way to find a string of minimum length:

  • Convert the regular expression to a nondeterministic finite automaton.



  • Convert the nondeterministic automaton into a deterministic one.



  • Use a breadth first search until you encounter the first nonfinal state (if there is one at all).

Context

StackExchange Computer Science Q#10064, answer score: 11

Revisions (0)

No revisions yet.