In: Computer Science
Q1:
Given the following code, what is returned by tq(4)?
int tq(int num){
if (num == 0) return 0;
else
if (num > 100) return -1;
else
return num + tq( num – 1 );
}
Group of answer choices:
0
4
-1
10
Q2:
Given that values is of type LLNode<Integer> and references a linked list (non-empty) of Integer objects, what does the following code do if invoked as mystery(values)?
int mystery(LLNode<Integer> list)
{
if (list.getLink() == null)
return list.getInfo();
else
return mystery(list.getLink());
}
Group of answer choices:
returns sum of the numbers on the values list
returns the last number on the values list
returns 0
returns how many numbers are on the values list
Q3:
Given that values is of type LLNode<Integer> and references a linked list (possibly empty) of Integer objects, what does the following code do if invoked as mystery(values)?
int mystery(LLNode<Integer> list)
{
if (list == null)
return 0;
else
return 1 + mystery(list.getLink());
}
Group of answer choices:
returns 0
returns sum of the numbers on the values list
returns the last number on the values list
returns how many numbers are on the values list