CISC/CMPE 223 - Assignment 2 Mahir Khandokar February 9, 2023 1. Here is the hierarchical structure of the regular expression (01* + 10)*1*, where · is concatenation, + is union, and * is closure: * * 1 + 1 . 0 * 1 0 1 Working from the bottom of the tree at the leaf nodes up to the root, we are able to construct the state diagram of the regex by combining the state diagrams of the nodes. To construct the state diagram, we start from left to right from the leaf nodes: State diagram for 0: 0 State diagram for 1: 1 State diagram for 1 *: 1
Mahir Khandokar CISC 223 - Assignment 2 State diagram for 01 *: State diagram for 10: State diagram for 01* + 10: State diagram for (01* + 10) *: Page 2 1 3 - 3 + 1 0 3 E 1 0 1 0 E 3 1 0
Mahir Khandokar CISC 223 - Assignment 2 Page 3 1 3 0 3 0 3 3 1 State diagram for the original regex (01* + 10)*1 *: 1 3 0 3 0 3 3 1 3 3 1 2. For the state diagram in Figure 1, no pre-processing for the state elimination algorithm is required because the start and accept states are distinct. From there, a state that is neither the accept state nor the start state must be selected. Since the start state is 1 and the accept state is 3, the only remaining state that is neither is state 2, so state 2 must be eliminated. Any transitions that go through state 2, whether incoming or outgoing, must be accounted for, so the transitions between the remaining states must be modified, or new ones are to be added. - The modified transition from state 1 to state 1 comes from transitioning through c to get to state 2, then using a to get back to state 2 any number of times, followed by that is a transition from state 2 to state 1 through d.