Why we are more optimistic about ourselves and our peers and pessimistic about others? I watched a ted talk which is about optimism bias by Tali Sharot. It stated that we are more optimistic about ourselves and our peers and we are more passimistic about others.But, I can't find an apt explanation for it.I observed this behaviour in all humans at some extent.

What makes the difference? Is there any scientific explanation?
I'm going to take the evolutionary standpoint. Many of these reasons and explanations Tali Sharot already gave in her talk. You could also check out her books. I'm going to try to make the point I see in it clear.
First the basics of evolutionary advantages - traits in a species are favored by evolution if they make it likelier for us to survive and procreate. (those with unfavorable characteristics are less likely to survive in order to procreate!)
The genes we have are more likely to be passed on if we reach a mature age, find a partner and successfully rear our offspring. 
This is the basic idea behind an evolutionary explanation. 
As she says, optimism makes it more likely for us to reach for higher goals - and also for achieving them. 
Hope and our happiness leads to better health, reduces stress and a longer life span and thus, it's more likely that we're going to pass on our genes.
Why not for others? We know that bad things happen and that the world is dangerous, but if we can convince ourselves that it happens to others, rather than us, we'll be happier.
Well, that's very basic evolutionary explanation. 
Here's an article that goes into this:
https://www.brainpickings.org/2012/12/12/science-of-optimism-sharot/
Her full-length book: https://www.amazon.de/Optimism-Bias-wired-bright-English-ebook/dp/B005RZB6VU/ref=asap_bc?ie=UTF8