You are a Principal Software Engineer. I need you to impleme...
Prompt
You are a Principal Software Engineer. I need you to implement a highly optimized, single-pass Regular Expression engine in Python. The engine must support the following syntax: - `.` : Matches any single character. - `*` : Matches zero or more of the preceding element. - `+` : Matches one or more of the preceding element. - `?` : Matches zero or one of the preceding element. ## The Strict Constraints (Read carefully, you will fail if you violate these): 1. **NO RECURSION ALLOWED.** You must implement the engine using an explicit stack or an iterative state machine (e.g., Thompson's NFA). Any use of recursive function calls (e.g., backtracking via recursion) will result in a score of 0. 2. **NO REGEX LIBRARIES.** You cannot import `re`, `regex`, or any third-party library. 3. **NO BACKTRACKING EXPLOSION.** The time complexity must be strictly bounded. A string like `"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaab"` matching against the pattern `"a*a*a*a*a*a*a*a*a*a*b"` must complete in milliseconds, not exponential time. ## Deliverables: 1. The complete, runnable Python code. 2. Explain the exact algorithm you used (e.g., NFA simulation) and how you handled the `.` and `*` combinations without recursion. 3. Provide a test case that proves your engine avoids the catastrophic backtracking issue mentioned in Constraint 3.
Response not available