=========================================================================== CSC 236 Sample Solutions for Week 13 Tutorial Fall 2007 =========================================================================== A. Construct a NFA equivalent to RE: (b+d)* (a(e + b(b+d)*))*. Q: First thing to do? A: Eliminate 'e' and '{}' from RE: (b+d)* (a + ab(b+d)*)*. Q: Next? A: Start with: (b+d)* (a + ab(b+d)*)* --> q_0 ----------------------->(q_1) Q: Next? A: Remove operators one by one. First, concatenation: (b+d)* (a + ab(b+d)*)* --> q_0 -------> q_2 ---------------->(q_1) Next, do (b+d)*: b+d (a + ab(b+d)*)* --> q_0 q_2 ---------------->(q_1) \_____________________________/| (a + ab(b+d)*)* b+d (a + ab(b+d)*)* --> q_0 ---------------->(q_1) (because q_2 has no more incoming transitions). Next, remove the next '*': it's not the only transition out of q_0 (because of loop), so: b+d a + ab(b+d)* -->(q_0)------------->(q_2) a + ab(b+d)* (q_1) Drop q_1 (no more incoming transitions), and replace each '+' with two transitions: a b,d ---------> a -->(q_0) (q_2) ab(b+d)* ---------> ab(b+d)* Break up concatenations: b,d a a (b+d)* -->(q_0)---->(q_2)<---- q_6 | /| \_ /| a| (b+d)*| a\_ b| \| | \| | q_3 ----> q_4 q_5 b Remove '*' from the transition q_4 -> q_2: b,d a a (b+d)* -->(q_0)---->(q_2)<---- q_6 | /| \_ /| a| a| a\_ b| \| | \| | q_3 ---->(q_4)----> q_5 b b,d a Remove '*' from the transition q_6 -> q_2: b,d a a a b,d -->(q_0)---->(q_2)<----(q_6) | /| \_ /|| a| a| a\_ b||a \| | \| ||/ q_3 ---->(q_4)----> q_5 b b,d a Done! Compare this with the equivalent DFA: a b,d ---> -->(q_0) (q_1) a <--- b Moral: Sometimes, a little thinking is better than a lot of mechanical computation! :) B. Review! Bring any question about the course material (mostly for the second half).