سوال ۵۳ کنکور ارشد مهندسی کامپیوتر ۱۴۰۱
زبان را درنظر بگیرید.
برای تولید زبان بالا گرامر زیر پیشنهاد شده است. ( متغیر شروع و تنها حرف الفبا است.)
کدام گزینه درخصوص نوع گرامر بالا و عبارتی که بایستی به جای ؟ قرار گیرد، درست است؟
پاسخ صحیح: گزینهٔ C — نوع صفر (بدون محدودیت) ...
The language contains the strings of length Since is not context-free, must use context (left- and right-hand context symbols), and the answer hinges on two independent decisions.
1. What goes in place of
The symbols and are end-markers; sweeps right doubling each (), turns around at the right end (), and sweeps left () back to the start marker, where launches another doubling pass. Each full round trip doubles the number of 's, giving exactly .
To stop, the sweeping head becomes a terminating marker: . This must now travel all the way left to the start marker and disappear. The only rule that consumes is the final , so has to reach . The rule must therefore move one cell to the left, i.e. turn into . That forces No other choice lets migrate to the start marker, so . This eliminates options 1 (), 2 () and 4 ().
2. The Chomsky type of
A grammar is context-sensitive (Type 1) only if it is non-contracting: every production satisfies (the lone exception is allowed when never appears on a right-hand side). Check the productions:
| Production | non-contracting? | |
|---|---|---|
| yes | ||
| yes | ||
| yes | ||
| yes | ||
| yes | ||
| yes | ||
| NO |
The clean-up rule erases a length-2 left side, so it is contracting. Because this is not an production, violates the Type-1 length condition. Hence is Type 0 (unrestricted), not context-sensitive. This rules out options 2 and 4 (which claim Type 1).
Conclusion
Type 0 (unrestricted) and — option 3.
Pitfall: is a context-sensitive language (a non-contracting grammar exists), but the grammar as written contains the erasing rule , so this particular grammar is Type 0. The question asks about the type of this grammar, not the inherent class of the language.