Which of the following are context-free languages?
(A) {wⁱ xʲ yᵏ zˡ | i + k = j + l, where i, j, k, l ≥ 0}
(B) {wⁱ xʲ yᵏ zˡ | i = j, k = l, where i, j, k, l ≥ 0}
(C) {wⁱ xʲ yᵏ zˡ | i = j = k and k ≠ l, where i, j, k, l ≥ 0}
(D) {wⁱ xʲ yᵏ zˡ | i = j = k + l, where i, j, k, l ≥ 0}
(E) {wⁱ xʲ yᵏ zˡ | i = j = l and k ≠ l, where i, j, k, l ≥ 0}
Pick an option to check yourself, or open the answer below.
Show answer & explanation
Correct answer: A. (A) and (B) Only
Explanation
(B) is the concatenation of wⁱxⁱ and yᵏzᵏ, so it is CF. (A) needs one counter: add for w and y, subtract for x and z, and accept if the counter ends at 0. A PDA can track the sign with its bottom marker. (C), (D) and (E) each need two independent equalities (three-way comparisons), which no PDA can check.More Theory of Computation and Compilers questions
- Let L = {ab, aa, baa}. Which of the following strings is NOT in L*?
- Let A = {a, b} and L = A*. Let X = {aⁿbⁿ | n > 0}. The languages L ∪ X and X are respectively:
- Which of the following symbol-table implementations is best suited if access time is to be minimum?
- Consider the grammar E → E + n | E × n | n. For the sentence n + n × n, the handles in the right-sentential forms of the reduction are:
- One of the purposes of using intermediate code in compilers is to:
- The sum of the minimum and maximum number of final states for a DFA having P states is equal to: