-3

I cannot solve this problem, if anyone can solve this problem.

my problem is L = {w ∈ {a, b}*, Na(w) mod 2 = 1}

  • Welcome to Stack Overflow. Please take the [tour] to learn how Stack Overflow works and read [ask] on how to improve the quality of your question. Then check the [help/on-topic] to see what questions you can ask. You might want to delete this question and ask it on https://cs.stackexchange.com/ instead, but check the help pages there first. – Progman May 30 '21 at 13:18
  • 1
    Start with `a(aa)*` and determine how to add `b` to it. – Welbog May 31 '21 at 21:54

1 Answers1

0

If you're stuck writing a regular expression but know how to make the DFA, do that first, then write some equations and solve for the regular expression. A DFA seems easy here:

     /---a---\
     |       |
     V       |
---->q0--a-->q1
    / ^     / ^
   /  |    /  |
   \--/    \--/
     b       b

Here, q1 is accepting. We get some equations from this:

(q0) = e + (q0)b + (q1)a
(q1) = (q0)a + (q1)b

We want to solve for (q1). Let's remove the self reference in the equation for (q0):

(q0) = e + (q0)b + (q1)a
     = (e + (q1)a) + (q0)b
     = (e + (q1)a)b*

Now we can substitute in the equation for (q1):

(q1) = (q0)a + (q1)b
     = [(e + (q1)a)b*]a + (q1)b

Distributing and rearranging:

(q1) = [(e + (q1)a)b*]a + (q1)b
     = (e + (q1)a)b*a + (q1)b
     = b*a + (q1)ab*a + (q1)b
     = b*a + (q1)(ab*a + b)

Now we can easily remove the self-reference from this equation:

(q1) = b*a + (q1)(ab*a + b)
     = b*a(ab*a + b)*

We can observe:

  1. the number of a's is always odd since one is always added, and any after the first are added in matched pairs
  2. the strings in this language may begin with any number of b's, end with any number of b's, and have any number of b's separating any otherwise adjacent pair of a's.
Patrick87
  • 27,682
  • 3
  • 38
  • 73