CS 1MD3 - Winter 2006 - Assignment #4

Generated for Student ID: 0560247

Due Date: Friday, March 17th

(You are responsible for verifying that your student number is correct!)
NOTE: All submissions must be plain text format in ".py" files.

Here is your state transition table (in human-readable format) representing a finite state automaton:
abpqt
1 54  
221 45
3 1 25
44 522
51 3  

Interpretation of the table:
Question 1: Write a Python function which accepts a dictionary representation of a state transition table (like the one below) and an input string. The function returns True if string would be accepted by the finite state automaton represented by the state transition table, and False if it would be rejected.

Question 2: Write a Python function which accepts an input string and uses 'if' statements to determine whether the string would be accepted by the finite state automaton represented by your state transition table. Do not use a dictionary for this one.

Question 3: Write several test cases for each of your functions involving strings which are accepted and strings which are rejected. You may use PyUnit if you feel so inspired, or just a simple Python program. If your particular machine either accepts all strings or rejects all strings, please explain why (in lieu of writing impossible test cases). If you like, you can put all three questions in one Python program. Just please, Please, PLEASE submit only plain text files with a ".py" extension!

"Free Gift" (whatever that redundancy is supposed to mean)
Here is the Python code which creates a dictionary representing your state transition table:
transDict = {(2, 'q'): 4, (4, 't'): 2, (1, 'b'): 5, (3, 'b'): 1, (5, 'p'): 3, (2, 't'): 5, (4, 'p'): 5, (1, 'p'): 4, (3, 't'): 5, (2, 'a'): 2, (2, 'b'): 1, (5, 'a'): 1, (3, 'q'): 2, (4, 'q'): 2, (4, 'a'): 4}

Bonus Question:
Write a Python function which accepts a state transition table (as a dictionary), a start state, and a set of final states. The function should return True if the corresponding automaton accepts ANY input strings, and False otherwise. Be sure to provide test cases (i.e. values for the parameters which result in True, and values which result in False).