Documentation for ITU AI Teacher Assistant Context
View the Project on GitHub frederico-alves/ITU-AI-Teacher-Assistant-Context
This quiz is about Recursion — a method of solving computational problems where the solution depends on smaller instances of the same problem.
Please note:
Use only your assigned resources:
❌ Do not use any other sources (books, blogs, videos, slides). 🧩 Focus on reasoning, not syntax correctness.
Please indicate which experimental group you have been assigned to:
We are master’s students from IT University of Copenhagen conducting research for our thesis.
By participating, you confirm:
I hereby consent to my data being collected and used for research:
What is your gender?
The following code implements a recursive function that calculates powers of two for a number n (i.e. 2ⁿ).
What is the sequence of function calls (including the value of the argument) if we call:
twoPow(3)?
int twoPow(int n) {
if (n == 0) return 1;
return 2 * twoPow(n - 1);
}
The following code implements a recursive function that calculates powers of two of a number n (i.e. 2ⁿ).
What is the sequence of return values from all function calls, if we call twoPow(3)?
int twoPow(int n) {
if (n == 0) return 1;
return 2 * twoPow(n - 1);
}
The following code implements a recursive function that calculates powers of two of a number n (i.e. 2ⁿ).
Modify this code so that it recursively calculates sums of two by adding 2 together n times.
You must use recursion.
Example table of expected results:
| n | Expression | Result |
|---|---|---|
| 0 | 0 | = 0 |
| 1 | 2 | = 2 |
| 2 | 2 + 2 | = 4 |
| 3 | 2 + 2 + 2 | = 6 |
int twoSum(int n) {
if (n == ...) return ...;
return ... (n - 1);
}
You need to implement a recursive function that calculates powers of two of a number n (i.e. 2ⁿ).
You need to use recursion.
int twoPow(int n) {
...
}
| n | Expression | Result |
|---|---|---|
| 0 | 2⁰ | = 1 |
| 1 | 2¹ | = 2 |
| 2 | 2² | = 4 |
| 3 | 2³ | = 8 |
The following code implements a recursive function that counts the number of 'a' characters in a word.
Example: countA("ada") = 2
What is the sequence of function calls (including the value of the argument) if we call:
countA("ada")?
int countA(String word) {
if (word.length() == 0) return 0;
if (word.charAt(0) == 'a') {
return 1 + countA(word.substring(1));
} else {
return countA(word.substring(1));
}
}
The following code implements a recursive function that counts the number of 'a' characters in a word.
Example: countA("ada") = 2
What is the sequence of return values from all function calls if we call:
countA("ada")?
int countA(String word) {
if (word.length() == 0) return 0;
if (word.charAt(0) == 'a') {
return 1 + countA(word.substring(1));
} else {
return countA(word.substring(1));
}
}
Modify the recursive function so that it returns true if the word contains an 'a', and false otherwise.
You must use recursion.
boolean hasA(String word) {
if (word.length() == 0) return false;
if (word.charAt(0) == 'a') return true;
return hasA(word.substring(1));
}
| Input | Result |
|---|---|
"" |
false |
"bo" |
false |
"abe" |
true |
"abama" |
true |
Implement a recursive function that counts the number of 'a' characters in a word.
Example: countA("ada") = 2.
You must use recursion.
int countA(String word) {
...
}
| Input | Result |
|---|---|
"" |
0 |
"bo" |
0 |
"abe" |
1 |
"abama" |
3 |
Thank you for taking the time to complete this quiz. Your participation is anonymous and contributes to our master’s thesis research on how students interact with AI and TAs in learning environments.