Problem: Given a DFA $D$, find all possible lengths of strings accepted by the $D$.
It makes sense that these lengths can be represented as $a_i+kb_i$. What might be the algorithm to find all such pairs $(a_i, b_i)$?
Computer Science Stack Exchange is a question and answer site for students, researchers and practitioners of computer science. It only takes a minute to sign up.
Sign up to join this communityTake your DFA and change each of its input symbols into a single symbol, say $a$. Now of course your automaton no longer is deterministic, but lengths are preserved. Then make the automaton deterministic again. The form of the new DFA is that of a initial linear path leading to a loop. This is because of the single letter restriction.
The accepting states in the initial linear path are the finite component of the language, of lengths that do not repeat. The accepting states in the loop represent the $a_i$ for your construction. The length of the loop is the single $b$ in the $a_i+kb$ representation.
The set of possible lengths of strings accepted by a DFA is always a semilinear set. The semilinear sets form a Kleene algebra, and determining the possible lengths accepted by a DFA (or NFA) is a classic semiring graph problem which can be solved by applying Kleene's algorithm with the algebra of semilinear sets swapped out in place of the algebra of regular expressions.
Essentially, you pretend you are computing the regular expression accepted by the NFA, but for each $R_{ij}^k$, instead of storing an entire regular expression, you only store a representation of the semilinear set of possible lengths of the regular expression.
See Stephen Dolan's "Fun With Semirings" for other interesting things you can do by treating the edge labels of a graph as elements of a semiring.