0
0
DSA Cprogramming~20 mins

Divide and Conquer Strategy and Recurrence Relations in DSA C - Practice Problems & Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Divide and Conquer Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of Recursive Merge Sort Call Count
Consider the following C code snippet that counts the number of recursive calls made by merge sort on an array of size n = 4. What is the printed output?
DSA C
int count = 0;

void merge_sort(int arr[], int left, int right) {
    count++;
    if (left < right) {
        int mid = (left + right) / 2;
        merge_sort(arr, left, mid);
        merge_sort(arr, mid + 1, right);
    }
}

int main() {
    int arr[4] = {4, 3, 2, 1};
    merge_sort(arr, 0, 3);
    printf("%d\n", count);
    return 0;
}
A7
B8
C6
D5
Attempts:
2 left
💡 Hint
Count how many times merge_sort is called including the initial call.
🧠 Conceptual
intermediate
2:00remaining
Master Theorem Case Identification
Given the recurrence relation T(n) = 3T(n/4) + n, which case of the Master Theorem applies to find the time complexity?
ANone of the above
BCase 2: f(n) = Θ(n^log_b(a) * log^k(n)), T(n) = Θ(n^log_b(a) * log^(k+1)(n))
CCase 1: f(n) = O(n^log_b(a) - ε), T(n) = Θ(n^log_b(a))
DCase 3: f(n) = Ω(n^log_b(a) + ε), T(n) = Θ(f(n))
Attempts:
2 left
💡 Hint
Calculate log base b of a and compare f(n) with n^log_b(a).
Predict Output
advanced
2:00remaining
Output of Recursive Function with Divide and Conquer
What is the output of the following C function when called with mystery(8)?
DSA C
int mystery(int n) {
    if (n <= 1) return 1;
    return mystery(n / 2) + mystery(n / 2);
}

int main() {
    printf("%d\n", mystery(8));
    return 0;
}
A8
B4
C16
D1
Attempts:
2 left
💡 Hint
Trace the calls and sum the return values.
🔧 Debug
advanced
2:00remaining
Identify the Error in Recurrence Relation Implementation
The following C code attempts to compute T(n) = 2T(n/2) + n using recursion and print the result for n=8. What error will occur when running this code?
DSA C
int T(int n) {
    if (n == 1) return 1;
    return 2 * T(n / 2) + n;
}

int main() {
    printf("%d\n", T(8));
    return 0;
}
ARuntime error due to infinite recursion
BNo error, output is 32
CCompilation error due to missing return type
DWrong output: 20 instead of 24
Attempts:
2 left
💡 Hint
Check base case and recursive calls carefully.
🧠 Conceptual
expert
2:00remaining
Time Complexity of Strassen's Matrix Multiplication
Strassen's algorithm multiplies two n x n matrices using 7 recursive multiplications of size n/2 plus some additions. Which recurrence relation best describes its time complexity?
AT(n) = 8T(n/2) + O(n^2)
BT(n) = 8T(n/2) + O(n^3)
CT(n) = 7T(n/2) + O(n^2)
DT(n) = 7T(n/2) + O(n^3)
Attempts:
2 left
💡 Hint
Strassen reduces multiplications from 8 to 7, additions cost O(n^2).