In vipassana we are asked to be optimist. But buddha said expectation is the cause of all suffering. . Is there any difference between expectation and optimism?
To 'expect' is to imagine a particular state of the world and assume or assert that it will come to be. It is a counterfactual that can lead to discontentment and attachment (dukkha and tanhā) if it doesn't come to pass exactly as imagined.
To be 'optimistic' is to have trust in the workings of the world: faith that whatever outcome arises (expected or unexpected) will ultimately work out well. Optimism is an attitude more than a belief, and it's an attitude that tends to dissolve discontentment and attachment.
You asked about "expectation", but let's start with the word "expect". The word "expect" is used in translations of the suttas in terms of future certainty.
DN16:1.4.5: “As long as the Vajjis meet frequently and have many meetings, they can expect growth, not decline.
However, the word "optimist" is not used in the same translations, so we have to rely on Google:
involving an overestimate. "previous estimates may be wildly optimistic"
Although we can expect a future certain outcome, we should not fall into the optimistic trap of expecting it tomorrow. So some expectations are well founded and those are discussed throughout the suttas. However, there are also optimistic expectations which are delusional. In other words, the Vajjis may have to endure much hardship before growth happens. As we deepen our practice, we can expect skillful outcomes but should not be optimistic about instant success. It takes time for our practice to be fruitful, not forever, but not never:
Returning to "expectation", we have:
SN22.3:12.1: And how does one have expectations?
SN22.3:12.2: It’s when someone thinks:
SN22.3:12.3: ‘In the future, may I be of such form, such feeling, such perception, such choices, and such consciousness!’
Form, feeling, perception, choices and consciousness are the five grasping aggregates. As they grasp, we crave. And as we crave, we suffer.
In vipassana we are asked to be optimist.
One can't force themselves or pretend to be optimistic. Instead, optimism, or a positive attitude about life can only come as a result of diligent cultivation of the Path, after a certain degree of Samatha/tranquility and Vipassana/insight have been developed. See Ven. Brahm's excellent essay Joy At Last To Know There Is No Happiness In The World for more details.
"It’s so ironic that Buddhism is called pessimistic. Actually, it’s probably the most optimistic teaching there could be. Human beings have the ability to totally transcend suffering, that’s what the Buddha says. He not only says it, he also gives us a path to follow. He gives us the techniques and he also tells us, “You’ve got to develop these qualities of mind: an enjoyment in the path, persistence in the path, showing interest and sensitivity in what you’re doing, and using your own ingenuity. Make use of them.”"
~ Thanissaro Bhikkhu "The Power to Transcend Suffering" https://www.dhammatalks.org/Archive/Writings/CrossIndexed/Published/Meditations9/0203n1b1PowertoTranscendSuffering,The.pdf
There is no standardized "Vipassana" and very few people agree on what is vipassana & how to achieve it.
Buddha said "expectation is root"
Did he really?
"Monks, there are these three roots of what is unskillful. Which three? Greed is a root of what is unskillful, aversion is a root of what is unskillful, delusion is a root of what is unskillful.
"Now, there are these three roots of what is skillful. Which three? Lack of greed is a root of what is skillful, lack of aversion is a root of what is skillful, lack of delusion is a root of what is skillful.
There is another way of explaining what is root of all things when asked by people from other schools/sects. If they ask what is the root of all things one should answer
all things are rooted in desire
One can say that expectation creates suffering, but this doesn't have much to do with Buddhism in particular. Expectations are a cause for disappointment, if there are no expectations then there is no disappointment, in that sense it's suffering, this is obvious.
Expectations can be realistic or not-realistic. In the world it is held that unrealistic expectations in particular are a cause for suffering and the realistic one's a cause for equanimity.
In Buddha's teachings expectation itself comes under 'suffering' because it is impermanent.
Optimism is likewise good & necessary if it's tied to wisdom. As example, a person should believe that good behavior will have good expected value and that the doer of good will meet with good fortune when the results of the good deeds mature.
If he didn't believe that then it would be difficult to find motivation to keep up the good behavior especially if met with bad fortune whilst the good has yet to mature.