0
0
DSA Cprogramming~10 mins

Divide and Conquer Strategy and Recurrence Relations 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 correctly divide the problem size by 2 in the recursive call.

DSA C
int divideAndConquer(int n) {
    if (n <= 1) return n;
    return divideAndConquer(n [1] 2) + n;
}
Drag options to blanks, or click blank then click option'
A-
B+
C/
D*
Attempts:
3 left
💡 Hint
Common Mistakes
Using addition or subtraction instead of division to reduce problem size.
Multiplying n instead of dividing.
2fill in blank
medium

Complete the recurrence relation formula for the time complexity T(n) = 2 * T(n {{BLANK_1}} 2) + n.

DSA C
T(n) = 2 * T(n [1] 2) + n
Drag options to blanks, or click blank then click option'
A/
B+
C*
D-
Attempts:
3 left
💡 Hint
Common Mistakes
Using subtraction instead of division in the recurrence relation.
Using addition which increases problem size.
3fill in blank
hard

Fix the error in the recursive function call to correctly implement divide and conquer.

DSA C
int solve(int n) {
    if (n <= 1) return 1;
    return 2 * solve([1]) + n;
}
Drag options to blanks, or click blank then click option'
An * 2
Bn / 2
Cn + 2
Dn - 1
Attempts:
3 left
💡 Hint
Common Mistakes
Multiplying or adding to n instead of dividing.
Using n - 1 which reduces size by 1, not half.
4fill in blank
hard

Fill both blanks to complete the recurrence relation and base case for a divide and conquer algorithm.

DSA C
if (n [1] 1) return 1;
T(n) = 3 * T(n [2] 3) + n;
Drag options to blanks, or click blank then click option'
A<=
B>
C/
D-
Attempts:
3 left
💡 Hint
Common Mistakes
Using greater than in base case condition.
Using subtraction instead of division in recurrence.
5fill in blank
hard

Fill all three blanks to complete the recursive function and recurrence relation for a divide and conquer algorithm.

DSA C
int dcFunc(int n) {
    if (n [1] 1) return 1;
    return 4 * dcFunc(n [2] 2) + n * n;
}

T(n) = 4 * T(n [3] 2) + n * n;
Drag options to blanks, or click blank then click option'
A<=
B-
C/
D*
Attempts:
3 left
💡 Hint
Common Mistakes
Using multiplication or subtraction instead of division.
Incorrect base case condition.