Topic: Theory of Computation
Let M be a DFA with n states accepting language L. If L != ∅, what is the maximum length of the shortest string accepted by M?
- A. n
- B. 2n
- C. [n/2]
- D. n-1
Answer: D. n-1
Explanation: If a DFA with $n$ states accepts any strings at all (meaning the language is not empty), the shortest string it accepts must form a path from the start state to an accept state without visiting any state more than once. If a state was revisited, a loop would be formed, and skipping that loop would yield an even shorter accepted string. The longest possible path without repeating any of the $n$ states contains exactly $n$ states and thus exactly $n-1$ transitions. Therefore, the shortest accepted string has a maximum length of $n-1$.