CYK Membership Test for the String “baaba”
This lesson applies the CYK algorithm to the grammar
and the input string
The goal is to determine whether . CYK is a bottom-up parsing method that fills a triangular chart of substrings. It normally requires Chomsky Normal Form; this grammar already satisfies that requirement because every production is either binary or produces one terminal.
CYK records every nonterminal capable of deriving each contiguous substring. The final cell contains the answer: if it includes , the string is generated by the grammar.
Footnotes
-
CYK algorithm - Wikipedia - Describes CYK as a bottom-up dynamic-programming parser requiring CNF-style grammar rules. ↩
Grammar and input
Nonterminals: . Terminals: . Start symbol: . Input: , whose length is .
CYK chart notation
Let denote the set of nonterminals that derive the substring beginning at position and ending at position , using one-based indexing.
For example:
- describes the substring .
- describes the substring .
- describes the complete string .
For a substring of length greater than one, CYK tries every split point:
If a production exists, and
Footnotes
-
Parsing I: Context-Free Grammars and the CYK Algorithm - Explains chart cells, binary splits, and the CYK recurrence. ↩
CYK Recognition Procedure
- 1Step 1
Write the symbols as , , , , and .
- 2Step 2
For each terminal symbol, insert every nonterminal that directly produces it. Here, , , and .
- 3Step 3
For lengths , examine every substring and every possible split into two nonempty parts.
- 4Step 4
Use the binary rules , , , , and .
- 5Step 5
The string belongs to the language exactly when .
Step 1: Length-one substrings
The terminal productions are
The input positions are:
| Position | Symbol | Deriving nonterminals | Reason |
|---|---|---|---|
| 1 | |||
| 2 | |||
| 3 | |||
| 4 | |||
| 5 |
Thus,
Number of Deriving Nonterminals in Length-One Cells
Each input symbol may be derived by one or more grammar variables.
Step 2: Length-two substrings
For each length-two substring, there is only one split.
Substring
The split is
The left cell contains and the right cell contains . Therefore, the possible pairs are
The grammar contains , but no rule . Hence,
Indeed,
Substring
The possible pairs are
The only matching binary rule is
Therefore,
Substring
The left cell is and the right cell is . The possible pairs are
The rules and match . Thus,
Substring
This has the same symbol pattern as positions –:
The length-two results are therefore
Step 3: Length-three substrings
Substring
There are two splits.
Split 1:
The pair is
No production has right-hand side .
Split 2:
The pair combinations are
No production has right-hand side or .
Therefore,
Substring
Split 1:
The left cell is and the right cell is . The possible pairs include
The rule matches only if the left side contains and the right side contains . Hence,
Split 2:
The pair is
which matches no binary production.
Thus,
Substring
Split 1:
The pair combinations are
Neither matches a binary production.
Split 2:
Since and , the pair is possible, but no rule has right-hand side .
Therefore,
The length-three cells are
Step 4: Length-four substrings
Substring
Split 1:
The pair is
No rule matches .
Split 2:
The cells are
The possible pairs are and ; neither occurs on the right-hand side of a binary production.
Split 3:
Since , this split contributes nothing.
Therefore,
Substring
Split 1:
Since , this split contributes nothing.
Split 2:
The cells are
The pair is , which matches
Therefore,
Split 3:
The cells are and , giving and . Again, only matches, so this split also derives .
Thus,
The length-four cells are
Step 5: Length-five substring
The complete input is
There are four possible split points.
| Split | Left substring | Left cell | Right substring | Right cell | Matching pair | Result |
|---|---|---|---|---|---|---|
| 1 | gives | |||||
| 2 | none | none | ||||
| 3 | none | none | ||||
| 4 | none | none |
The first split derives :
and because
we obtain
No split produces :
- would require a split whose left cell contains and whose right cell contains .
- would require a split whose left cell contains and whose right cell contains .
Neither condition is satisfied.
Hence,
Complete CYK triangular table
The table is conventionally displayed with longer substrings above shorter substrings.
| Span length | Substring | CYK cell |
|---|---|---|
| 5 | ||
| 4 | ||
| 4 | ||
| 3 | ||
| 3 | ||
| 3 | ||
| 2 | ||
| 2 | ||
| 2 | ||
| 2 | ||
| 1 | ||
| 1 | ||
| 1 | ||
| 1 | ||
| 1 |
A positional triangular representation is:
| 1: b | 2: a | 3: a | 4: b | 5: a | |
|---|---|---|---|---|---|
| 1 | |||||
| 2 | |||||
| 3 | |||||
| 4 | |||||
| 5 |
The top-right cell is
Final membership test
The start symbol is not present in the top cell: . Therefore, the string is rejected by the grammar.
Conclusion
The CYK algorithm returns
Although the entire string can be derived from nonterminal ,
this does not establish membership in because the grammar’s designated start symbol is , not .
A valid derivation from the grammar must have the form
Since , no such derivation exists.
Common Questions and Verification Notes
CYK and This Grammar
Exam Strategy
Always distinguish between “some nonterminal derives the string” and “the start symbol derives the string.” For CYK membership, inspect only whether appears in the final top-right cell.
Knowledge Check
What is the initial CYK cell for the first symbol ?
Explore Related Topics
When Can a Language Be Accepted by a Turing Machine?
LangChain vs LangGraph: A Comprehensive Comparison
LangChain and LangGraph are complementary frameworks in the LangChain ecosystem: LangChain offers fast, linear pipeline composition via LCEL, while LangGraph provides a graph‑based runtime with persistent state, loops, branching, and human‑in‑the‑loop capabilities.
- LangChain’s modular components (models, prompts, memory, tools) are combined with the pipe operator
|to build simple to moderate linear workflows such as retrieve‑summarize‑answer. - LangGraph introduces three primitives—State, Nodes, and Edges—enabling cycles, conditional branches, multi‑agent coordination, and checkpoint‑driven fault tolerance.
- State management differs: LangChain relies on chain‑scoped Memory; LangGraph uses a global State object with checkpointers that support time‑travel debugging and rollback.
- Decision guidance: choose LangChain for straightforward RAG or Q&A bots; adopt LangGraph when you need loops, branching, persistent state, or production‑grade resilience.
Functional Dependencies and Candidate Keys in $R(A,B,C)$
In with functional dependencies and , neither single attribute determines all three attributes, so and are not keys; the minimal candidate keys are and .
- and , both missing → not superkeys.
- Adding yields , making and candidate keys.
- Mutual determination () does not imply key status without covering the whole schema.
- A common exam trap is assuming or are keys because they determine each other.
- Heuristic: any attribute not derivable from others (here ) must appear in every candidate key.