Question d’entretien chez Meta

Write a method to generate the Fibonacci series

Réponses aux questions d'entretien

Utilisateur anonyme

16 avr. 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

Utilisateur anonyme

20 nov. 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.

Utilisateur anonyme

14 oct. 2010

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

Utilisateur anonyme

3 avr. 2010

Write a method to generate the Fibonacci series

Utilisateur anonyme

24 sept. 2010

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