Women in Technology

Hear us Roar

  Technologies to Watch: A Look at Four That May Challenge Java’s Development Dominance
Subject:   fibonacci
Date:   2005-10-21 11:58:56
From:   tcowan
The fibonacci example was a straw man.

public static int fib(int n) {
return (n<=1)?n:fib(--n)+fib(--n);

Full Threads Oldest First

Showing messages 1 through 1 of 1.

  • fibonacci
    2005-10-22 09:15:13  Nonymous [View]

    Apparently you are not found in recurrent successions, your algorithm is unusable. Try evaluating fib(40).

    The answer is fib(40) = 165,580,141 but your "pritty" algorith will require 1,402,817,465 method calls.

    The algorithm you mentioned as a "straw man" requires only 40 steps to evaluate fib(40).

    As a conclusion I think perhaps Java doesn't encourage to think about what you are writing.