Главная » Просмотр файлов » 1610906232-7ba7dbaea13262b50a6029d682cb7f1b

1610906232-7ba7dbaea13262b50a6029d682cb7f1b (824370), страница 31

Файл №824370 1610906232-7ba7dbaea13262b50a6029d682cb7f1b (Elements of Theory of Computation 2ed Lewis Papadimitriou) 31 страница1610906232-7ba7dbaea13262b50a6029d682cb7f1b (824370) страница 312021-01-17СтудИзба
Просмтор этого файла доступен только зарегистрированным пользователям. Но у нас супер быстрая регистрация: достаточно только электронной почты!

Текст из файла (страница 31)

Deterministic finite-state transducers were introduced in Problem 2.1.4.Show that if L is context-free and I is computed by a deterministic finitestate transducer, then(a) I[L] is context-free;(b)1 [L1is context-free.r3.5.12. Develop a version of the Pumping Theorem for context-free languages inwhich the length of the "pumped part" is as long as possible.3.5.13. Let M1 and M2 be pushdown automata. Show how to construct pushdown automata accepting L(M1 ) UL(M2 ), L(M1 )L(M2 ), and L(Md", thusproviding another proof of Theorem 3.5.1.3.5.14. Which of the following languages are context-free? Explain briefly in eachcase.(a) {ambnc p : m = nor n = p or m = p}(b) {ambncp : m ¥- nor n ¥- p or m ¥- p}Chapter 3: CONTEXT-FREE LANGUAGES150(c) {ambnc p : Tn = nand n = p and Tn = p}(d) {w E {a, b, c}': W does not contain equal numbers of occurrences ofa, b, and c}(e) {w E {a, b}' : W = WI W2 ...

Wm for some Tn ? 2 and WI, ... ,W m suchthat IWII = IW21 = ... = Iwml? 2}3.5.15. Suppose that L is context-free and R is regular. Is L- R necessarily contextfree? What about R - L? Justify your answers.3.6ALGORITHMS FOR CONTEXT-FREE GRAMMARSIn this section we consider the computational problems related to context-freelanguages, we develop algorithms for these problems, and we analyze their complexity.

All in all, we establish the following results.Theorem 3.6.1: (a) There is a polynomial algorithm which, given a context-freegrammar, constructs an equivalent pushdown automaton.(b) There is a polynomial algorithm which, given a pushdown automaton, constructs an equivalent context-free grammar.(c) There is a polynomial algorithm which, given a context-free grammar G anda string x, decides whether x E L( G).It is instructive to compare Theorem 3.6.1 with the corresponding statementsummarizing the algorithmic aspects of finite automata (Theorem 2.6.1). To besure, there are certain similarities: in both cases there are algorithms whichtransform acceptors to generators and vice versa -then finite automata to regular expressions and back, now pushdown automata to context-free grammarsand back. But the differences are perhaps more striking.

First, in Theorem 2.6.1there was no need for an analog of part (c) above, since regular languages are represented in terms of an efficient algorithm for deciding precisely the membershipquestion in (c): a deterministic finite automaton. In contrast, for context-freelanguages we have so far introduced only non-algorithmic, nondeterministic acceptors -pushdown automata.

In order to establish part (c), we show in thenext subsection that for any context-free language we can construct a deterministic acceptor; the construction is rather indirect and sophisticated, and theresulting algorithm, although polynomial, is no longer linear in the length of theinput.A second major difference between Theorem 2.6.1 and Theorem 3.6.1 isthat in the present case we do not mention any algorithms for testing whethertwo given context-free grammars (or two pushdown automata) are equivalent;neither do we claim that there are algorithms for minimizing the number of statesin a pushdown automaton.

We shall see in Chapter 5 that such questions about1513.6: Algorithms for Context-Free Grammarscontext-free grammars and pushdown automata are not amenable to solution byany algorithm -however inefficient!The Dynamic Programming AlgorithmWe turn now to proving part (c) of the Theorem (parts (a) and (b) are straightforward consequences of the constructions in the proofs of the Lemmata 3.4.1and 3.4.2). Our algorithm for deciding context-free languages is based on auseful way of "standardizing" context-free grammars.Definition 3.6.1: A context-free grammar G =Chomsky normal form if R ~ (V - ~) X V 2 .(V,~,R, S) is said to be inIn other words, the right-hand side of a rule in a context-free grammarin Chomsky normal form must have length two.

Notice that no grammar inChomsky normal form would be able to produce strings of length less than two,such as a, b, or e; therefore, context-free languages containing such strings cannotbe generated by grammars in Chomsky normal form. However, the next resultstates that this is the only loss of generality that comes with Chomsky normalform:Theorem 3.6.2: For any context-free grammar G there is a context-free grammar G' 'in Chomsky normal form such that L( G') = L( G) - (~ U {e }). Furthermore, the construction of G' can be carried out in time polynomial in the size ofG.In other words, G' generates exactly the strings that G does, with thepossible exception of strings of length less than two -since G' is in Chomskynormal form, we know that it cannot generate such strings.Proof: We shall show how to transform any given context-free grammar G =(V,~, R, S) into a context-free grammar in Chomsky normal form.

There arethree ways in which the right-hand side of a rule A --+ x may violate the constraints of Chomsky normal form: long rules (those whose right-hand side haslength three or more), e-rules (of the form A --+ e), and short rules (of the formA --+ a or A --+ B). We shall show how to remove these violations one by one.We first deal with the long rules of G. Let A --+ B 1 B 2 •.. Bn E R, whereB 1, ... ,Bn E V and n 2. 3. We replace this rule with n - 1 new rules, namely:152Chapter 3: CONTEXT-FREE LANGUAGESwhere AI, ...

,A n - 2 are new nonterminals, not used anywhere else in the grammar. Since the rule A --+ B 1 B 2 •.. Bn can be simulated by the newly insertedrules, and this is the only way in which the newly added rules can be used,it should be clear that the resulting context-free grammar is equivalent to theoriginal one. We repeat this for each long rule of the grammar. The resultinggrammar is equivalent to the original one, and has rules with right-hand sidesof length two or less.Example 3.6.1: Let us take the grammar generating the set of balanced parentheses, with rules S --+ SS,S --+ (S), S --+ e. There is only one long rule,S --+ (S).

It is replaced by the two rules S --+ (SI and SI --+ S).¢We must next take on the e-rules. To this end, we first determine the setof erasable nonterminalsE= {AE V - ~ : A::::}*e},that is, the set of all nonterminals that may derive the empty string. This isdone by a simple closure calculation:E:= 0while there is a rule A --+ a withA ~ E do add A to E.QE E* andOnce we have the set E, we delete from G all e-rules, and repeat the following: For each rule of the form A --+ Be or A --+ e B with BEE and e E V, weadd to the grammar the rule A --+ e.

Any derivation in the original grammarcan be simulated in the new, and vice versa -with one exception: e cannot bederived in the language any longer, since we may have omitted the rule S --+ eduring this step. Fortunately, the statement of the Theorem allows for thisexclusion.Example 3.6.1 (continued): Let us continue from the grammar with rulesS --+ SS,S --+ (SI,SI --+ S),S --+ e.We start by computing the set E of vanishing nonterminals: Initially E = 0;then E = is}, because of the rule S --+ e; and this is the final value of E. Weomit from the grammar the e-rules (of which there is only one, S --+ e), and addvariants of all rules with an occurrence of S, with that occurrence omitted. Thenew set of rules is3.6: Algorithms for Context-Free Grammars153The rule 5 --+ 5 was added because of the rule 5 --+ 55 with 5 E E; it is ofcourse useless and can be omitted.

The rule 51 --+) was added because of therule 51 --+ 5) with 5 E E.For example, the derivation in the original grammar5::::} 55 => 5(5) => 50 => ()can now simulated by-omitting the 5 => 55 part, since the first 5 would be eventually erased- andfinally-using the 51 =» rule to anticipate the erasing of the 5 in the rule 51 => 5).¢Our grammar now has only rules whose right-hand sides have length oneand two. We must next get rid of the short rules, those with right-hand sideswith length one. We accomplish this as follows: For each A E V we compute,again by a simple closure algorithm, the set D(A) of symbols that can be derivedfrom A in the grammar, D(A) = {B E v: A =>* B}, as follows:D(A):={A}while there is a rule B -+ G with B E D(A) andG ~ D(A) do add G to D(A).Notice that for all symbols A, A E D(A); and if a is a terminal, thenD(a)= {a}.In our third and final step of the transformation of our grammar to one inChomsky normal form, we omit all short rules from the grammar, and we replaceeach rule of the form A --+ BG with all possible rules of the form A --+ B'G'where B' E D(B) and G' E D( G).

Such a rule simulates the effect of the originalrule A --+ BG, with the sequence of short rules that produce B' from B and G'from G. Finally, we add the rules 5 --+ BG for each rule A --+ BG such thatA E D(5) - {5}.Again, the resulting grammar is equivalent to the one before the omissionof the short rules, since the effect of a short rule is simulated by "anticipating"its use when the left-hand side first appears in the derivation (if the left-handside is 5, and thus it starts the derivation, the rules 5 --+ BG added in the lastpart of the construction suffice to guarantee equivalence).

Характеристики

Тип файла
PDF-файл
Размер
11,07 Mb
Тип материала
Высшее учебное заведение

Список файлов решённой задачи

Свежие статьи
Популярно сейчас
Зачем заказывать выполнение своего задания, если оно уже было выполнено много много раз? Его можно просто купить или даже скачать бесплатно на СтудИзбе. Найдите нужный учебный материал у нас!
Ответы на популярные вопросы
Да! Наши авторы собирают и выкладывают те работы, которые сдаются в Вашем учебном заведении ежегодно и уже проверены преподавателями.
Да! У нас любой человек может выложить любую учебную работу и зарабатывать на её продажах! Но каждый учебный материал публикуется только после тщательной проверки администрацией.
Вернём деньги! А если быть более точными, то автору даётся немного времени на исправление, а если не исправит или выйдет время, то вернём деньги в полном объёме!
Да! На равне с готовыми студенческими работами у нас продаются услуги. Цены на услуги видны сразу, то есть Вам нужно только указать параметры и сразу можно оплачивать.
Отзывы студентов
Ставлю 10/10
Все нравится, очень удобный сайт, помогает в учебе. Кроме этого, можно заработать самому, выставляя готовые учебные материалы на продажу здесь. Рейтинги и отзывы на преподавателей очень помогают сориентироваться в начале нового семестра. Спасибо за такую функцию. Ставлю максимальную оценку.
Лучшая платформа для успешной сдачи сессии
Познакомился со СтудИзбой благодаря своему другу, очень нравится интерфейс, количество доступных файлов, цена, в общем, все прекрасно. Даже сам продаю какие-то свои работы.
Студизба ван лав ❤
Очень офигенный сайт для студентов. Много полезных учебных материалов. Пользуюсь студизбой с октября 2021 года. Серьёзных нареканий нет. Хотелось бы, что бы ввели подписочную модель и сделали материалы дешевле 300 рублей в рамках подписки бесплатными.
Отличный сайт
Лично меня всё устраивает - и покупка, и продажа; и цены, и возможность предпросмотра куска файла, и обилие бесплатных файлов (в подборках по авторам, читай, ВУЗам и факультетам). Есть определённые баги, но всё решаемо, да и администраторы реагируют в течение суток.
Маленький отзыв о большом помощнике!
Студизба спасает в те моменты, когда сроки горят, а работ накопилось достаточно. Довольно удобный сайт с простой навигацией и огромным количеством материалов.
Студ. Изба как крупнейший сборник работ для студентов
Тут дофига бывает всего полезного. Печально, что бывают предметы по которым даже одного бесплатного решения нет, но это скорее вопрос к студентам. В остальном всё здорово.
Спасательный островок
Если уже не успеваешь разобраться или застрял на каком-то задание поможет тебе быстро и недорого решить твою проблему.
Всё и так отлично
Всё очень удобно. Особенно круто, что есть система бонусов и можно выводить остатки денег. Очень много качественных бесплатных файлов.
Отзыв о системе "Студизба"
Отличная платформа для распространения работ, востребованных студентами. Хорошо налаженная и качественная работа сайта, огромная база заданий и аудитория.
Отличный помощник
Отличный сайт с кучей полезных файлов, позволяющий найти много методичек / учебников / отзывов о вузах и преподователях.
Отлично помогает студентам в любой момент для решения трудных и незамедлительных задач
Хотелось бы больше конкретной информации о преподавателях. А так в принципе хороший сайт, всегда им пользуюсь и ни разу не было желания прекратить. Хороший сайт для помощи студентам, удобный и приятный интерфейс. Из недостатков можно выделить только отсутствия небольшого количества файлов.
Спасибо за шикарный сайт
Великолепный сайт на котором студент за не большие деньги может найти помощь с дз, проектами курсовыми, лабораторными, а также узнать отзывы на преподавателей и бесплатно скачать пособия.
Популярные преподаватели
Добавляйте материалы
и зарабатывайте!
Продажи идут автоматически
6418
Авторов
на СтудИзбе
307
Средний доход
с одного платного файла
Обучение Подробнее