Mathematically
Code:
f(k) = 3 * f(k-1) + 2;  k > 0
f(0) = 0;
Edit: Just apply what tabstop said.