0
0
DSA Cprogramming~10 mins

Recursion Concept and Call Stack Visualization in DSA C - Interactive Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to make the function call itself recursively.

DSA C
void countdown(int n) {
    if (n == 0) {
        printf("Blastoff!\n");
        return;
    }
    printf("%d\n", n);
    countdown([1]);
}
Drag options to blanks, or click blank then click option'
An + 1
Bn
Cn - 1
D1
Attempts:
3 left
💡 Hint
Common Mistakes
Calling countdown with n + 1 causes infinite recursion.
Calling countdown with n does not reduce the problem size.
2fill in blank
medium

Complete the code to calculate factorial of n recursively.

DSA C
int factorial(int n) {
    if (n == 0) {
        return 1;
    }
    return n * factorial([1]);
}
Drag options to blanks, or click blank then click option'
An - 1
Bn + 1
C1
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Using n + 1 causes infinite recursion.
Using 1 or 0 directly does not compute factorial correctly.
3fill in blank
hard

Fix the error in the recursive Fibonacci function call.

DSA C
int fibonacci(int n) {
    if (n <= 1) {
        return n;
    }
    return fibonacci([1]) + fibonacci(n - 2);
}
Drag options to blanks, or click blank then click option'
An + 1
Bn - 1
Cn
D2
Attempts:
3 left
💡 Hint
Common Mistakes
Using n + 1 causes infinite recursion.
Using n or 2 as argument breaks the Fibonacci logic.
4fill in blank
hard

Fill both blanks to complete the recursive sum of array elements.

DSA C
int sumArray(int arr[], int size) {
    if (size == 0) {
        return 0;
    }
    return arr[[1]] + sumArray(arr, [2]);
}
Drag options to blanks, or click blank then click option'
Asize - 1
Bsize + 1
Dsize
Attempts:
3 left
💡 Hint
Common Mistakes
Using size or size + 1 causes out-of-bounds errors.
Not reducing size leads to infinite recursion.
5fill in blank
hard

Fill all three blanks to complete the recursive power function.

DSA C
int power(int base, int exp) {
    if (exp == 0) {
        return [1];
    }
    return base * power(base, [2]);
}

// Usage: int result = power([3], 3);
Drag options to blanks, or click blank then click option'
A1
Bexp - 1
C2
Dbase
Attempts:
3 left
💡 Hint
Common Mistakes
Returning base instead of 1 in base case.
Not reducing exponent causes infinite recursion.
Using wrong base value in usage example.