
Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
A problem in compiler theory, natural language processing, and theoretical computer science: determining if a string belongs to a context-free grammar. An example of a context-free grammar in chomsky normal form and explains how to generate strings from it. The main focus is on designing an algorithm to check if a given string is in the grammar, with a time complexity of o(n^3), where n is the number of characters in the string.
Typology: Exercises
1 / 1
This page cannot be seen from the preview
Don't miss anything!

COS 423 Theory of Algorithms Spring 2005
terminals a, b nonterminals S, T, A, B, X start S
Rules S โ S โ AB S โ AX X โ T B T โ AB T โ AX A โ a B โ b
For example, aabb is a string in the above context free grammar. To see why, we can apply the following sequence of transformations S โ AX โ AT B โ AABB โ aABB โ aaBB โ aabB โ aabb. In fact, the grammar generates precisely those strings with k aโs followed by k bโs. Given a context-free grammar in Chomsky Normal Form, design an algorithm to determine whether a string is in the grammar. Your algorithm should run in O(n^3 ) time where n is the number of characters in the string. You may assume the number of production rules is a small constant.