Google Interview Question: Write down different versions... | Glassdoor

Interview Question

Software Engineer Intern Interview New York, NY

Write down different versions for computing the fibonacci

  sequence.
Answer

Interview Answer

1 Answer

2

int fib[N];

void compute_recursive(int n){
     if (n==0) return 0;
     if (n==1) return 1;
     return compute_recursive(n-1) + compute_recursive(n-2);
}

void compute_seq(int n){
    fib[0] = 0;
    fib[1] = 1;
    int i;
    for (i=2;i<=n;i++)
        fib[i] = fib[i-1] + fib[i-2];
}

Anonymous on Oct 23, 2014

Add Answers or Comments

To comment on this, Sign In or Sign Up.