MESSAGE
DATE | 2015-02-18 |
FROM | Ruben Safir
|
SUBJECT | Subject: [NYLXS - HANGOUT] Recursive Allorithms
|
Has anyone ever looked closely and this classic algorithm for the fibonacci sequence
I was listening to this in class and thinking, no that is NOT going to give you the sequence desires.
It is a little snippet of a function that looks something like this
long fib(long in) { long ctch; // std::cout << "a => " << in << std::endl; if(in < 3){ std::cout << in << "| 1" << std::endl; return 1; } ctch = (fib(in - 1) + fib( in - 2) ); std::cout << in << " " << ctch << std::endl; return ctch; }
The problem is it has a double recursion so, amoung other problems it can't guarantee the order of outcomes. There might be a definitive presedence rule, but I'm not certain how it will end up on the stack.
One thing I am certain of is that it is not the same as the polynumerial sequence of
Fn = Fn-1 + Fn-2 where n > 2
That function gives a sequence of: 1 1 2 3 4 8 13 21 34 ...
It will calculate out the last value in the sequence for n. That is the problem it solves. It just bothers me that this is Computer Sciences and they can't be EXACT about the math.
It is just sloppy and then the students get lost.
|
|