fibMem[n - 1] = r; } return r; } This is much more efficient because if the value r has already been calculated for a certain n and stored in fibMem[n - 1], the function can just return the stored value rather than making more recursive function calls. This results in a pattern which can be visualized by this diagram: f(5) = f(4) + f(3) = 5 | | f(4) = f(3) + f(2) = 3 | | f(3) = f(2) + f(1) = 2 | | | f(1) = 1 | f(2) = 1 The difference may not seem too significant with an N of 5, but as its value increases, the complexity of the original fibonacci function increases exponentially, whereas the revised version increases more linearly. See also Dynamic programming References Dynamic programming