0

I have to basically write a fuction that does the inmemoized recursion and count the number of times is called..which i did..

the second part is that i dont understand which is to create a global array of 100 and calculate the function using memoization...

can some one help..this is the first part

import java.util.Scanner;

public class Fib{
static int calls;
public static void main(String[] args){
int fib;
int n;
Scanner scan = new Scanner(System.in);
System.out.println("Input a number");
n = scan.nextInt();
System.out.println(" " + RecurFib(n) + " " + calls);

}
int count = 0;
public static int RecurFib (int n){
calls ++;
if (n<2){

int answer = n;
return answer;
}else{
int answer = RecurFib(n-1) + RecurFib(n-2);
return answer;
}
}

2
Contributors
7
Replies
8
Views
9 Years
Discussion Span
Last Post by alejalv
0

basically the second part has to do the same thing as the first one but now using memoization...

0

here is an example of the outputs "numbers" that it should have..but the program is in C++ i think, and I can't understand it too well.

0

where's the value of calls in the program? you wouldnt happen to be in randall's class at rutgers would u

0

yes i am..and you? did he collected the program.. i think we still have time..to send it right?

0

naw i guess we can send it wenever... i went to talk 2 him today about why my program wont compile and i still cant figure it out.... i noticed u copied the program some1 replied to me with and what i dont understand is that first static int calls is declared as a global variable up top and then it says int count = 0.... where is the value for calls? in the program? isnt it supposed to say calls = 0;

0

i guess is because the calls ++ is inside the recursive function therefore.. the count will keep adding.. if you trie to punt count ++ it wont work..

im having trouble figuring out the second part.. the memoization part.. ..have you been successful with it?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.