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.

Solution Stats

69.44% Correct | 30.56% Incorrect
Last Solution submitted on Jul 20, 2025

Problem Comments

Solution Comments

Show comments

Problem 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!