Hello I need help doing the following Recursion. Solve by using the spanning tre
ID: 3717501 • Letter: H
Question
Hello I need help doing the following Recursion. Solve by using the spanning tree method. Take a screenshot, or picture or submit the Word document with the traced out spanning tree solution and the written solution on the paper. Make sure the spanning tree is legible and the answers are visible and not blurry.
1. What is returned by recurs(4)?
public int recurs(int n)
{
int result = 0;
if(n<=3)
result = 2;
else
result = recurs(n - 2) + (n - 2);
return result;
}
2. What is returned by try(1) ?
3. What is returned by try(6) ?
public int try(int n)
if(n==1 || n==2)
return 2*n;
return try(n - 1) + try(n - 2);
4. What is returned by wow(2) ?
5. What is returned by wow(-5) ?
public static int wow(int x)
{
if(x<10)
return x + wow(x+2);
else
return 1;
}
6.What is returned by roses(5)?
7. What is returned by roses(0)?
public static int roses(int x)
{
if ( x == 0)
return 1;
if( x % 2 != 0)
return roses(x – 1) + x;
return roses(x – 2) + x;
}
8. What is returned by the method call rec(“abcdef”)? _____
9. What is returned by the method call rec(“”)? ______
public static String rec(String s)
if(s == null || s.length() ==0)
return “”;
}
10. 9! =
11. 0! =
12. What is the 8th number in Fibonacci’s sequence?
Explanation / Answer
Please find my answer.
public int recurs(int n)
{
int result = 0;
if(n<=3)
result = 2;
else
result = recurs(n - 2) + (n - 2);
return result;
}
What is returned by recurs(4)? ANS) 4
public int try(int n)
{
if(n==1 || n==2)
return 2*n;
else
return try(n - 1) + try(n - 2);
}
What is returned by try(1) ? ANS) 2
What is returned by try(6) ? ANS) 26
public static int wow(int x)
{
if(x<10)
return x + wow(x+2);
else
return 1;
}
What is returned by wow(2) ? ANS) 21
What is returned by wow(-5) ? ANS) 17
public static int roses(int x)
{
if ( x == 0)
return 1;
if( x % 2 != 0)
return roses(x – 1) + x;
return roses(x – 2) + x;
}
What is returned by roses(5)? ANS)12
What is returned by roses(0)?ANS) 1
9! = 362880
0! =0
What is the 8th number in Fibonacci’s sequence? ANS) 21
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.