Professional Documents
Culture Documents
RegEx and FSM Questions
RegEx and FSM Questions
RegEx and FSM Questions
______________
Question Set 1: From Finite State Machines to Regular Expressions – write the Regular Expression
FSM to Regex Questions:
1. FSM Description: Accepts binary strings ending in "01".
Answer:
2. FSM Description: Accepts strings containing exactly one "a" followed by any number of "b"s.
Answer:
3. FSM Description: Accepts strings of "a"s and "b"s where "a" must not be followed directly by "b".
Answer:
4. FSM Description: Accepts strings that start with an "a" followed by zero or more "b"s, and ends with "c".
Answer:
5. FSM Description: Accepts strings where "a" occurs at least once, and after every "a" there is at least one "b".
Answer:
Question Set 2: From Regular Expressions to Finite State Machines – draw or describe the FSM
Regex to FSM Questions:
EXAMPLE
Regular Expression: 1*0
Answer: An FSM with an initial state that loops on "1", a transition on "0", and then reaches a final state.
1
Question Set 3: Describe the Accepted Language – describe the language accepted by the regular expression.
Regular Expression Descriptions:
Example
Regular Expression: (a|b)*
Description: Accepts any sequence of "a"s and "b"s, including the empty string.
Question Set 4: String Acceptance by Regular Expressions – state the strings which would be accepted by the
regular expression.
Regular Expression String Acceptance Questions:
1. Regular Expression: a*b*
Strings: "aaaa", "bbbb", "abab", "aaabb", ""
Accepted Strings:
2. Regular Expression: (0|1)*01
Strings: "0101", "1100", "001", "1001", "1111"
Accepted Strings:
3. Regular Expression: (a|b)+
Strings: "a", "b", "ab", "ba", "aaa", "bb", "abc"
Accepted Strings:
4. Regular Expression: ab?a
Strings: "aba", "aa", "abba", "ab", "a"
Accepted Strings:
5. Regular Expression: 1*0+1?
Strings: "1110", "0001", "01", "0", "111001"
Accepted Strings: