ITU AI Teacher Assistant Context

Documentation for ITU AI Teacher Assistant Context

View the Project on GitHub frederico-alves/ITU-AI-Teacher-Assistant-Context

Recursion Assessment DEMO

About This Assessment

This quiz is about Recursion — a method of solving computational problems where the solution depends on smaller instances of the same problem.

Please note:

You must use only the resources assigned to your group:


🧩 Group Assignment

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:


⚧ Gender

What is your gender?


🧩 Problem 1


Question 1.1

Following code implements a recursive function that computes the factorial value of n. Example: fac(3) = 6.

What is the sequence of recursive calls and their arguments, if we call fac(3)?

Code

int fac(int n) {
    if (n == 0) return 1;
    return n * fac(n - 1);
}

Possible answers


Question 1.2

Following code implements a recursive function that computes the factorial value of n. Example: fac(3) = 6.

What is the sequence of return values from all recursive calls, if we call fac(3)?

Code

int fac(int n) {
    if (n == 0) return 1;
    return n * fac(n - 1);
}

Possible answers


Question 2

The following code implements a recursive function that computes the factorial value of n (n!).

Rewrite the code so that it computes the accumulated sum of n instead of the factorial value. Use recursion.

Instruction

Example: sum(3) = 6, since 3 + 2 + 1 + 0 = 6.

Template

int sum(int n) {
    if (n == ...) return ...;
    return n ... sum(n - 1);
}

Reference Table

n Calculation Result
0 0 = 0
1 1 + 0 = 1
2 2 + 1 + 0 = 3
3 3 + 2 + 1 + 0 = 6

Question 3

You must implement a recursive function that computes the factorial value of n.

Example:

fact(3) = 6, since 3 * 2 * 1 = 6.

Template

int fac(int n) {
    // your code here
}

Reference Table

n Expression Result
0 1 = 1
1 1 = 1
2 2 * 1 = 2
3 3 * 2 * 1 = 6

🎓 Thank You!

Thank you for participating in this quiz. Your responses are anonymous and will be used solely for research in the IT University of Copenhagen master’s thesis.


Would you like me to also convert this quiz into an interactive Markdown form (e.g., for GitHub Pages or Jupyter Notebook use, with radio buttons and text inputs)?