Determine if the string is in L(G)

  • MHB
  • Thread starter mathmari
  • Start date
  • Tags
    String
In summary, the conversation is about writing an $O(n^3)$ algorithm to determine if a given string is in a specific context-free grammar. The person asking for help is wondering how to use dynamic programming in this case, and the other person explains that it involves finding the set of symbols that can derive a specific substring of the given string. This is described in detail in multiple sources, including [1], [2], and [3].
  • #1
mathmari
Gold Member
MHB
5,049
7
Hey! :eek:

I have to write an $O(n^3)$ algorithm to determine whether a given string $w=a_1 a_2 \dots a_n$ is in $L(G)$, where $G=(N,\Sigma ,P, S)$ is a context-free grammar in Chomsky normal form.

Could you give me some hints how to do that?? (Wondering)
 
Technology news on Phys.org
  • #2
Could you explain me how we could use the dynamic programming in this case?? (Wondering)
 
  • #3
This is described in Section 3.6 in [1], Theorem 7.16 in [2] and Section 7.4.4 in [3]. Briefly, the idea is the following. Given a word $x_1\dots x_n$, for each $i$ and $s$ such that $1\le i\le i+s\le n$ find the set $N[i,i+s]$ of all symbols that can derive $x_i\dots x_{i+s}$. This computation occurs in a loop where $s$ changes from 1 to $n-1$.

[1] Lewis, Papadimitriou. Elements of the Theory of Computation. 2nd edition.

[2] Sipser. Introduction to the Theory of Computation. 2nd edition.

[3] Hopcroft, Motwani, Ullman. Introduction to Automata Theory, Languages, and Computation. 2nd edition.
 

Related to Determine if the string is in L(G)

What is the definition of L(G)?

L(G) refers to the language generated by the grammar G, which is a set of rules that describe the structure and formation of strings in a given language.

What does it mean for a string to be in L(G)?

A string is said to be in L(G) if it can be generated by the grammar G, meaning it follows the rules and structure set by the grammar.

How can I determine if a string is in L(G)?

To determine if a string is in L(G), you can use an algorithm called the "parsing algorithm" which checks if the string can be generated by the grammar G. Alternatively, you can manually check if the string follows the rules and structure set by the grammar.

What happens if a string is not in L(G)?

If a string is not in L(G), it means that it cannot be generated by the grammar G, and therefore does not follow the rules and structure set by the grammar.

Can a string be in L(G) for multiple grammars?

Yes, a string can be in L(G) for multiple grammars. This is because different grammars can have overlapping rules and structures, allowing for the same string to be generated by multiple grammars.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
10
Views
1K
  • Programming and Computer Science
Replies
1
Views
1K
  • Linear and Abstract Algebra
Replies
10
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
3
Views
1K
Replies
6
Views
740
  • Programming and Computer Science
Replies
1
Views
1K
  • Computing and Technology
Replies
2
Views
132
Replies
12
Views
2K
  • Programming and Computer Science
Replies
1
Views
1K
  • Programming and Computer Science
Replies
1
Views
1K
Back
Top