0
0
DSA Cprogramming~10 mins

Memoization Top Down DP 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 declare the memo array for storing computed Fibonacci values.

DSA C
int memo[[1]];
Drag options to blanks, or click blank then click option'
A10
B0
C1000
D-1
Attempts:
3 left
💡 Hint
Common Mistakes
Using zero or negative size for the array.
Using too small size causing out of bounds.
2fill in blank
medium

Complete the code to initialize the memo array with -1 to indicate uncomputed values.

DSA C
for (int i = 0; i < n; i++) {
    memo[i] = [1];
}
Drag options to blanks, or click blank then click option'
A-1
B0
C1
Dn
Attempts:
3 left
💡 Hint
Common Mistakes
Initializing with 0 which is a valid Fibonacci number.
Using positive numbers that can confuse computed and uncomputed states.
3fill in blank
hard

Fix the error in the memoization check to return the stored value if already computed.

DSA C
if (memo[n] != [1]) {
    return memo[n];
}
Drag options to blanks, or click blank then click option'
A-1
B1
Cn
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Checking for 0 which is a valid Fibonacci number.
Checking for 1 which is also a valid Fibonacci number.
4fill in blank
hard

Fill both blanks to complete the recursive Fibonacci function with memoization.

DSA C
int fib(int n) {
    if (n <= 1) return n;
    if (memo[n] != -1) return memo[n];
    memo[n] = fib(n [1] 1) + fib(n [2] 2);
    return memo[n];
}
Drag options to blanks, or click blank then click option'
A-
B+
C*
D/
Attempts:
3 left
💡 Hint
Common Mistakes
Using addition or multiplication instead of subtraction for indices.
Using wrong operators causing wrong recursion.
5fill in blank
hard

Fill all three blanks to complete the memoization initialization and function call.

DSA C
for (int i = 0; i < [1]; i++) {
    memo[i] = [2];
}
int result = fib([3]);
Drag options to blanks, or click blank then click option'
An
B-1
C10
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Initializing with 0 instead of -1.
Calling fib with 0 which returns trivial result.