Question

In: Computer Science

Consider the following CFG with starting variable S and Σ = {1, 2, 3, 4, 5,...

Consider the following CFG with starting variable S and Σ = {1, 2, 3, 4, 5, 6, 7,

8, 9, 0}:

S → X Y Z

X → 1 | 2

Y → W | ε

Z → Z Z | W

W → 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 0

a. [20 marks] Create a derivation tree for your student number. - 84521004

b. [20 marks] Is this grammar ambiguous or unambiguous? Briefly explain (Remember the string is 84521004)

why.

Solutions

Expert Solution

a) In the given grammar, there is only one production rule involving S, the rule is S -> XYZ,

With this production rule when we expand X, we can only have 1 or 2 as the first digit.

So This grammar can only produce numbers that begin with either 1 or 2.

We cannot derive string  84521004 using this grammar, since, we cannot produce 8 as the first digit with this grammar.

So, there will be no derivation tree for 84521004.

b) Yes, this grammar is ambiguous.

A grammar is ambiguous if we can generate more than one derivation tree for any string.

Let us take a string 123

We can generate two derivation trees for the same string using this grammar.

Since we can generate more than one derivation tree using this grammar, this grammar is ambiguous.

------------------------------------------------

UPDATE:

for string 2180045

There are multiple derivation trees possible, one such derivation is below:

-----------------------------------------------

I hope this helps you,

Please rate this answer if it helped you,

Thanks for the opportunity


Related Solutions

2. Consider the following data: x= 1, 2, 3, 4, 5 y =3, 2, 4, 6,...
2. Consider the following data: x= 1, 2, 3, 4, 5 y =3, 2, 4, 6, 5 By hand, not using Matlab, and showing your work: (a) Compute the correlation coefficient. (b) Find the least-squares line. (c) Find the standard deviation around the least-squares line.
5. (a) Let σ = (1 2 3 4 5 6) in S6. Show that G...
5. (a) Let σ = (1 2 3 4 5 6) in S6. Show that G = {ε, σ, σ^2, σ^3, σ^4, σ^5} is a group using the operation of S6. Is G abelian? How many elements τ of G satisfy τ^2 = ε? τ^3 = ε? ε is the identity permutation. (b) Show that (1 2) is not a product of 3-cycles. Must be written as a proof! (c) If a^4 = 1 and ab = b(a^2) in a...
Consider the following set of numbers: {3, 5, 2, 5, 5, 15, 2, 2, 4, 4,...
Consider the following set of numbers: {3, 5, 2, 5, 5, 15, 2, 2, 4, 4, 20, 4998, 4} 14. The Q3 of this set is: a. 4 b. 5 c. 2 d. 10 15. The Q1 of this set is: a. 4 b. 5 c. 2 d. 2.5 e. 3
2. Consider functions f : {1, 2, 3, 4, 5, 6} → {1, 2, 3, 4,...
2. Consider functions f : {1, 2, 3, 4, 5, 6} → {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}. (a) How many of these functions are strictly increasing (i.e. f(1) < f(2) < f(3) < f(4) < f(5) < f(6))? Hint: How many different possibilities are there for the range of f? For each range of f, how many strictly increasing functions are there? (b) How many of these functions are non-decreasing (i.e. f(1) ≤ f(2) ≤...
Consider the following function ?(?) = ?^ 4+ 2? ^3 + 8?^ 2+ 5? With the...
Consider the following function ?(?) = ?^ 4+ 2? ^3 + 8?^ 2+ 5? With the initial guesses of ?1 = −2, ?2 = −1, and ?3 = 1, find the minimum of the given function using parabolic interpolation. Perform five iterations, reporting Ɛa based on the location of the minimum (i.e. xopt) and not the actual minimum value. (Round the final answer to four decimal places.)
a) Let σ = (1 2 3 4 5 6) ∈ S6, find the cycle decomposition...
a) Let σ = (1 2 3 4 5 6) ∈ S6, find the cycle decomposition of σ i for i = 1, 2, . . . , 6. (b) Let σ1, . . . , σm ∈ Sn be disjoint cycles. For 1 ≤ i ≤ m, let ki be the length of σi . Determine o(σ1σ2 · · · σm)
Consider the following data table: x 8 5 4 6 2 5 3 y 1 3...
Consider the following data table: x 8 5 4 6 2 5 3 y 1 3 6 3 7 2 5 (15 points) Create a scatterplot of the data either by hand or with a computer.  Does there appear to be a linear relationship between x and y?  If so, what is the strength and direction of the relationship? (20 points) Give the Simple Linear Regression Model, using x as the predictor variable and y as the response variable.  What is the meaning...
The following page-reference string: 1, 2, 4, 3, 2, 5, 4, 2, 4, 2, 1, 3,...
The following page-reference string: 1, 2, 4, 3, 2, 5, 4, 2, 4, 2, 1, 3, 2, 3, 1, 3, 6, 1, 6, 4. Main memory with 3 frames of 1 kilobyte available and they are all initially empty. Complete a figure, similar to Figure 8.14(in the slides or textbook), showing the frame allocation for each of the following page replacement policies: a. Optimal b. Least recently used c. First-in-first-out Then, find the relative performance of each policy with respect...
1) Consider the following requirements for a certain product. Period 1 2 3 4 5 6...
1) Consider the following requirements for a certain product. Period 1 2 3 4 5 6 7 8 Gross requirements 0 200 200 500 0 400 0 400 Beginning inventory = 300 units Setup cost = $300 per setup Lead time = 1 week Holding cost = $5 per unit per week (a) Develop the lot-for-lot MRP table - (complete table below). (b) Calculate the total relevant costs. Answer (Show all mathematical work): a) Period 1 2 3 4 5...
Consider the following pairs of observations.X 1 4 3 5 7 2 6 20
Consider the following pairs of observations. X 1 4 3 5 7 2 6 20 Y 3 12 10 12 19    7 17   60 A) Calculate the least squares line. B) Determine a 95% confidence interval for the mean value of Y using X = 6 C) Determine a 95% prediction interval for the Y value using X = 6
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT