This was a question for an exam that I received 0 points on, I'd like to get some input on what the correct answer should have been.
Imagine that you are asked to write an algorithm $P$ that takes a regular expression $R$ as input, and returns $1$ if and only if $L(R) = \{0,1\}^*$; otherwise, it should return $0$. What would your algorithm do? Please give a carefully explained description of your algorithm.
Note: your algorithm does not need to be "efficient". but it must halt in a finite number of steps(no matter what regular expression $R$ is given as input), and the answer it gives must be correct.
First I drew a DFA that would accept $L(R)$
Algorithm $P$
- Given a regular expression $R$ as input
- If $R = \{0,1\}^*$, then $R=R.1$ (concatenation of $R$ and $1$)
- Otherwise, $R = R.0$
My thoughts were that the concatenation of $1$ would cause the accept state to be $1$ if the input was in $\{0,1\}^*$, otherwise it would cause the accept state to be $0$. I'm not sure what my professor wanted as an answer, should my algorithm have been to build a DFA $D$ that accepts $\{0,1\}^*$, run input $R$ on $D$ and return a $1$ if the DFA accepted $R$?
The problem is asking you to determine whether or not a regex accepts every binary string. To do that, your algorithm should traverse the graph of the DFA you built, and if it finds any non-final reachable state, this means that the DFA does not describe $\{0,1\}^*$.