# When is a grammar ambiguous or When is a grammar not ambiguous?

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?

That grammar as presented (with the addition of the production $$A\to a$$) is certainly ambiguous, regardless of what the site you copied it from says. Your work demonstrates that, and it can easily be verified using a parser generator or CFG analyzer. (See below for what they probably meant.)
I think you did not correctly guess the typo in that webpage. It's not that one production for $$A$$ is missing. Rather, the second line of the grammar should have read: $$A\to a S \mid b A A \mid a$$ instead of $$S\to…$$. You might also want to try using that version of the grammar.