I was looking at an example of grammar from the website: grammer example
which is as follows:
S → aB / bA
S → aS / bAA / a
B → bS / aBB / b
I believe they forgot to write: A -> a
Next, we are going to derive the string: aaabbabbba
I did it by myself and found the following:
Left derivation:
S -> aB
-> aaBB
-> aaaBBB
-> aaabBB
-> aaabbB
-> aaabbaBB
-> aaabbabB
-> aaabbabbS
-> aaabbabbbA
-> aaabbabbba
Right Most Derivation:
S -> aB
-> aaBB
-> aaBbS
-> aaBbbA
-> aaBbba
-> aaaBBbba
-> aaaBbbba
-> aaabSbbba
-> aaabbAbbba
-> aaabbabbba
And the left most derivation tree:
Right most derivation tree:
Now, if the website says the grammer is "unambiguous" then shouldn't the parse trees of left most derivation and right most derivation be the same? am i correct or is the website correct?
Also, when is a grammer ambiguous? I feel it is when:
(1) It has more than 1 left most derivation tree for the same string
(2) It has more than 1 right most derivation tree for the same string
(3) It has different left most and right most derivation tree for the same string
In the above rules i mean the shape of the parse / derivation tree, not the actual substitution
Am i correct?