Questions: Regular Language Recognition Algorithms

5 questions to test your understanding

Score: 0 / 5
Question 1 Multiple Choice

A DFA has 500,000 states and is used to recognize a regular language. How does its size affect the time complexity of testing whether an input string of length n is in the language?

AIt increases the time complexity to O(n × 500,000)
BIt has no effect — DFA membership testing is O(n) regardless of the number of states
CIt causes exponential slowdown because more states mean more possible paths
DIt reduces the time complexity because larger DFAs can skip ahead in the input
Question 2 Multiple Choice

A compiler lexer needs to tokenize millions of lines of source code using patterns for keywords, identifiers, and literals. Why does it precompile those patterns from NFAs to DFAs rather than using on-the-fly NFA simulation?

ABecause NFAs cannot recognize the same languages as DFAs
BBecause the DFA is built once at compiler construction time and then processes all subsequent input in O(n) per token, while NFA simulation pays overhead proportional to active states on every input
CBecause NFAs require exponential time even for short inputs
DBecause DFAs can recognize languages that NFAs cannot, enabling more expressive token patterns
Question 3 True / False

DFA membership testing runs in O(n) time where n is the input length, regardless of how many states the DFA has.

TTrue
FFalse
Question 4 True / False

On-the-fly NFA simulation is generally slower than DFA simulation for any input, because tracking sets of active states takes more work per symbol than following a single transition.

TTrue
FFalse
Question 5 Short Answer

Why do compiler lexers typically precompile regex patterns to DFAs, while many general-purpose regex engines (like Python's or JavaScript's) use NFA-based simulation? What practical feature drives the tradeoff?

Think about your answer, then reveal below.