Problem 60964. Evaluate Deterministic Finite Automata on String
Given a Deterministic Finite Automata (DFA) and a string, determine whether or not the DFA will accept when ran on the string. Assume the first state is always the starting state.
Transitions will be given as an mx3 array of ints (where m is the number of state transitions), where each row will represent a state transition. The first element of the row will be the state we're transitioning from, the second will be the state we're transitioning to, and the third will be the ascii value of the character we're transitioning over. Assume the automata you are given are deterministic (e.g. there will either be one transition you can take, in which case you should take it, or there will be none, in which case you should return false).
Since the alphabet is arbitrary integers the DFA will not be exhaustive. If there is no transition over the current character for a given state, return false.
Ex: If we're given the following DFA
transitions=double([1 2 'a'; 2 3 'a'; 2 3 'b']), finals=[3]
when s='ab' or s='aa' we should return true, otherwise we should return false. For more complex examples, see the tests.
For information about DFAs see https://en.wikipedia.org/wiki/Deterministic_finite_automaton
Solution Stats
Problem Comments
Solution Comments
Show commentsProblem Recent Solvers9
Suggested Problems
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!