Meta Interview Question

Write a method to generate the Fibonacci series

Interview Answers

Anonymous

Apr 16, 2010

void print_fib(int length) { int prev_prev = 0, prev = 1, current = 1; while (length--) { printf(" %d", prev_prev); prev_prev = prev; prev = current; current = prev_prev + prev; } printf("\n"); }

2

Anonymous

Nov 20, 2011

tail recursion is far from enough to make recursion fast enough, you'll need to use memoization, and even if you do that, the code will still be slower and especially much more memory consuming than the one in the post of April 15, 2010 Recursion without memoization will take exponential time.

Anonymous

Oct 14, 2010

The recursive Sep 24 answer is too inefficient; you can still use recursion if you want, but think of a tail recursive method...

Anonymous

Apr 3, 2010

Write a method to generate the Fibonacci series

Anonymous

Sep 24, 2010

int fib(int n) { if (n < 2) return n; return fib(n - 1) + fib(n - 2); }