0
$\begingroup$

How to find a regular expression $t$ over the alphabet $\{0,1\}$ such that the language defined by $t$ is :

a) All words that begin with $0$ or end with $1$

b) All words that contain at least one $0$ and at least one $1$

c) All words that have length at least $2$ and whose last but one symbol is $0$

I just wrote down some expressions following the text:

a) $t= (0|1)1^*$ we have that the word will begin with $0$ or $1$ and will finish with $1$s

b) $t= 010^*$ we have a word that contain at least one $0$ and at least one $1$, but I don't know if it is correct because it asks for all the words

c) $t= 11^*0$ so we have atleast two symbols that end with $0$.

I was thinking that for the all of the above expressions there are a lot of ways to write them down for example I could have written:

b) $01010$

c) $000110$

Am I right?

  • 0
    For your solution to (a), note that $0$ matches your $t$, but does not end with $1$. Moreover, $1$ matches your $t$, but doesn't begin with $0$. The other solutions you propose also have problems.2017-02-04
  • 0
    @FabioSomenzi and if I set solution a as: t= 0(0|1)1* now it starts with 0 and finishes always with 12017-02-04
  • 0
    That's clorser, but not yet a solution, because $00$ matches your $t$. What you want is $0(0|1)^*1$. Part (b) is a bit more complicated, but Part (c) is easy: the next to last letter must be $0$ and the last one is either $0$ or $1$. Before that, anything goes.2017-02-04
  • 0
    @FabioSomenzi is there a method that I can use to find the correct answers?2017-02-04
  • 0
    @FabioSomenzi: (a) asks for words that begin with 0 **or** end with 1, not for words that do both. So it is fine that `00` matches -- it's supposed to. But `000` matches neither of the expressions suggested so far, and that is not good.2017-02-04
  • 0
    There's always a bit of trial and error. Take the second case. You may reason as follows: the empty word certainly does not contain both a $0$ and a $1$. So all words in my $t$ must have a first letter. Suppose it's $0$; then all is left to check is that a $1$ appears somewhere. Likewise, if the first letter is a $1$, all is left to check is that a $0$ appears in the rest of the word. How do I write the RE that matches any word that contains a $0$ somewhere? OK. I solved my two half-problems. Since it's either one or the other...2017-02-04
  • 0
    @HenningMakholm I need new glasses... Thanks!2017-02-04
  • 0
    @JJAb: The method is to understand how regular expressions work and which words are in the languages you're targeting. Once you possess that _understanding_, writing down expressions with the right result should be close to trivial.2017-02-04
  • 0
    You seem to be quite off course with your suggestions -- when you suggest writing $01010$ you seem to be satisfied with writing an expression that matches _some_ of the described words (this one matches only `01010` itself!), but the exercise calls for an expression that match _all_ words with at least one 1 and at least one 0, and no others.2017-02-04
  • 0
    @HenningMakholm Ok, I will try to work out2017-02-04
  • 0
    In some cases you can combine parts to get an answer. For example, for c), words that end in $0$ can be given by $(0|1)^*0$. Words of length two or more can be written as $(0|1)(0|1)(0|1)^*$ (or other variations). Now combine.2017-02-04
  • 0
    I have no idea of what you are saying. I understood that they have to match. Can the answer for point a t= 01 be, it start with 0 and finishes with one2017-02-05

0 Answers 0