I started my data structures course at university and I came across with that equation, can someone explain me how I prove it please?
$$\sum_{i=0}^{\log_3{n}}3^i = \frac{3n - 1}{2}$$ $$3^0+3^1+ ...+3^{\log_3 (n)} = \frac{3n-1}{2}$$ $$2(3^0+3^1+ ...+3^{\log_3 (n)}) = 3n-1$$ $$2+2\cdot3+2\cdot3^2 + ...+2\cdot3^{\log_3 (n)} = 3n-1$$ $$3+2\cdot3+2\cdot3^2 + ...+2\cdot3^{\log_3 (n)} = 3n$$ $$\frac{3+2\cdot3+2\cdot3^2 + ...+2\cdot3^{\log_3 (n)}}{3} = n$$ $$\frac{3(1+2+2\cdot3 + ...+2\cdot3^{\log_3 (n) -1})}{3} = n$$ $$1+2+2\cdot3 + ...+2\cdot3^{\log_3 (n) -1} = n$$ $$3+2\cdot3 + ...+2\cdot3^{\log_3 (n) -1} = n$$
Can I continue from here?