Fryguy8
09-22-2004, 08:41 PM
What is the optimal way to represent a Deterministic Finite Automaton? For those who don't know:
Set of states
an alphabet
Set of transition rules that map a state and an element from the alphabet to another state
a start state
a set of final states
Basically it's a structured digraph, with each state being a node, and each edge being a transition rule from one state pointing to another, labeled with an element from the alphabet.
For every state, every element of the alphabet must be mapped.
The automaton then accepts an input string and "parses" it using it's set of rules, and if it ends on a final state, it accepts, otherwise it rejects.
What is the optimal way to represent the 5 things that make up the DFA? The states should be a linked list in a sense. So the head of the list is the start state, and each node of the linked list contains a hash table mapping each element of the alphabet to another node on the list. Each node should also have a boolean property final. When the input has been parsed, check the property of the node you are on, and return true or false accordingly.
Note: I don't have to implement this, so worrying about whether the language supports lists like this isn't a concern.
Set of states
an alphabet
Set of transition rules that map a state and an element from the alphabet to another state
a start state
a set of final states
Basically it's a structured digraph, with each state being a node, and each edge being a transition rule from one state pointing to another, labeled with an element from the alphabet.
For every state, every element of the alphabet must be mapped.
The automaton then accepts an input string and "parses" it using it's set of rules, and if it ends on a final state, it accepts, otherwise it rejects.
What is the optimal way to represent the 5 things that make up the DFA? The states should be a linked list in a sense. So the head of the list is the start state, and each node of the linked list contains a hash table mapping each element of the alphabet to another node on the list. Each node should also have a boolean property final. When the input has been parsed, check the property of the node you are on, and return true or false accordingly.
Note: I don't have to implement this, so worrying about whether the language supports lists like this isn't a concern.