Question: 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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!