I have this recurrence : $$f(i) = \begin{cases} 0 &i=0\\ 1 &i=M\\ \frac{f(i-1) + f(i+1)} 2& 0 < i < M \end{cases}$$
I have guessed that $$f(i) = \frac i M$$ and proved it via induction.
What is the right way of solving it without guessing ?
Later Edit:
Thank you very much for your answers. I found them all very helpful. Thank you very much for your time !
This isn't really a recurrence relation.
Your "guess" is the right way to solve it. You can formalise your argument by reasoning that all internal points are the average of their neighbours - so only the straight line connecting the end-points can solve the relation. Note that this proves that your solution is correct, and unique.