Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1 ) What does the following code print when i = 1 ? public static void rec 1 ( int i ) { if (

1) What does the following code print when i =1?
public static void rec1(int i){
if (i==0)
System.out.print(i +"");
for (int j=0; j<2; j++){
rec1(i-1);
rec1(i-1);
}
}
2) What does the following code print when i =1?
public static void rec2(int i){
if (i==0){
System.out.print(i +"");
} else {
for (int j=0; j<2; j++){
rec2(i-1);
rec2(i-1);
}
}
}
3) What does rec return when list ={1,3,5,7,9}?
public int rec(int [] list){
return rec3(list,0);
}
public int rec3(int [] list, int start){
if (start == list.length -1){
return list[start];
} else {
return Math.max(list[start], rec3(list, start +1));
}
}
Use this definition for 4 & 5. In this recursive definition with two cases:
a list of names is
1: a name (no spaces, punctuation, or special characters)
or
2: a name followed by a semicolon and a space followed by a list of names
4) Which of the following match the definition of a list of names below?
Bob Alice
Bob; Alice;
Alice; Mary; Ted
Owen;
None of the above
5) Which of the following match the definition of a list of names below?
Bob Alice
Bob; Alice;
Alice Mary Ted
Owen;
None of the above
6)Given the following code snippet, how many times does the call tree include a base case?
System.out.println(combRec(4,2));
public long combRec(long n, long k){
if (n==k || k==0)
return 1;
else
return combRec(n-1,k-1)+ combRec(n-1,k);
}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions