سوال ۴۶ کنکور ارشد مهندسی کامپیوتر ۱۴۰۵
زبان و ماشین پشتهای (PDA) زیر را در نظر بگیرید. برای آنکه این PDA به درستی پذیرندهٔ زبان باشد، کدامیک از شرایط زیر لازم و کافی است؟
نمودار PDA. سه حالت: (حالت شروع)، و (حالت نهایی، با دایرهٔ دوتایی). برچسب گذار بهصورت یعنی: با خواندن نماد ورودی ، نماد از بالای پشته برداشته و بهجای آن گذاشته شود ( رشتهٔ تهی است). گذارها:
- حلقهٔ روی :
- گذار :
- حلقههای روی : و
- گذار :
- حلقهٔ روی :
پاسخ صحیح: گزینهٔ A — حداقل یکی از مسیرهای محاسبه در این ماشین پس از خواندن تمام ورودی به حالت نهایی و پشته خالی برسد.
What the machine does. In it pushes one a for every input a (loop ); an -move sends it to . In each input b either pops an a () or pushes a b (); an -move sends it to . In each input c pops a b (). Because only reads a, only reads b, and only reads c, every fully-read string has the form .
Nondeterminism kills option 3. A PDA is nondeterministic, so a string is in its language iff there exists an accepting path (), never “all paths” () — most branches get stuck. “All computation paths reach the final state” is the wrong quantifier. Eliminate option 3.
The empty stack is trivial at the start, so option 4 fails. The stack begins empty, so “at least one path reaches a state with an empty stack” is satisfied by every input (already in , before reading anything), and it never even requires the whole input to be consumed. It characterizes nothing useful. Eliminate option 4.
Final state alone is too weak (option 2). Take the input b, i.e. . Path: stay in (no a) ; read b via , so the stack becomes b; ; no c. The whole input is read and the machine sits in the final state — but the stack still holds a stray b. Under “final state only” this string would be accepted, yet it is not in the intended (the balance fails: ). So accepting by final state alone over-accepts.
Final state and empty stack is exactly right (option 1). Forcing an empty stack after the entire input is read means every pushed symbol must be cancelled: the pushed as must be popped by bs in , and the remaining pushed bs must be popped by the cs in . A valid accepting computation exists iff and , i.e. iff
which is precisely the intended context-free language . The stray-b counterexample is now rejected (non-empty final stack). Hence “reach the final state with an empty stack” is both necessary and sufficient.
Answer: option 1.
Exam trick: PDA acceptance is existential ( a good path, not ), and for the “final state and empty stack” mode the empty-stack test must be applied after the whole input is consumed — not at the start, where every PDA trivially has an empty (or initial) stack.