MESSAGE
DATE | 2015-02-18 |
FROM | Ruben Safir
|
SUBJECT | Subject: [LIU Comp Sci] Hwk4 Allorithms
|
From owner-learn-outgoing-at-mrbrklyn.com Wed Feb 18 05:38:54 2015 Return-Path: X-Original-To: archive-at-mrbrklyn.com Delivered-To: archive-at-mrbrklyn.com Received: by mrbrklyn.com (Postfix) id CE8581612FA; Wed, 18 Feb 2015 05:38:54 -0500 (EST) Delivered-To: learn-outgoing-at-mrbrklyn.com Received: by mrbrklyn.com (Postfix, from userid 28) id BF1B71612FC; Wed, 18 Feb 2015 05:38:54 -0500 (EST) Delivered-To: learn-at-nylxs.com Received: from mailbackend.panix.com (mailbackend.panix.com [166.84.1.89]) by mrbrklyn.com (Postfix) with ESMTP id 4C7DB1612FA for ; Wed, 18 Feb 2015 05:38:53 -0500 (EST) Received: from panix2.panix.com (panix2.panix.com [166.84.1.2]) by mailbackend.panix.com (Postfix) with ESMTP id 5A448123E3 for ; Wed, 18 Feb 2015 05:38:53 -0500 (EST) Received: by panix2.panix.com (Postfix, from userid 20529) id 4FF6433C90; Wed, 18 Feb 2015 05:38:53 -0500 (EST) Date: Wed, 18 Feb 2015 05:38:53 -0500 From: Ruben Safir To: learn-at-nylxs.com Subject: [LIU Comp Sci] Hwk4 Allorithms Message-ID: <20150218103853.GA19549-at-panix.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.23 (2014-03-12) Sender: owner-learn-at-mrbrklyn.com Precedence: bulk Reply-To: learn-at-mrbrklyn.com
This assignment is so small that I don't want to post my answer but I will say that 5 => 51, I think, if I understnad this correctly. I'm not sure exactly what he wants written here and he can be a PIA.
I ASUME that we are starting with n = 0
I hope that is right. Meanwhile, FWIW, here is a slight reworking of the examples in the notes.
http://www.nylxs.com/docs/grad_school/algorithms/Hwk4/recursions/
the main part looks like this
#include "recursion.h" #include
long recursion(long in) { long ctch; if (in < 2){ std::cout << in << std::endl; return 1; } ctch = ( in * recursion(in - 1)); //count down to zero std::cout << in << " " << ctch << std::endl; return ctch; }
long buffer[5000] = {0};
long fib(long in) { //long ctch; // std::cout << "a => " << in << std::endl;
if (buffer[in] != 0){ return buffer[in]; }
if(in < 3){ std::cout << in << "| 1" << std::endl; buffer[in] = 1; return 1; } //ctch = (fib(in - 1) + fib( in - 2) ); buffer[in] = (fib(in - 1) + fib( in - 2) ); std::cout << in << " " << buffer[in] << std::endl; return buffer[in]; }
If anyone has trouble, call me before 10 minutes before class or email the list 718-715-1771
Ruben
|
|