Assign 2 Shiksha
Assign 2 Shiksha
1 (CO2) Given an array A of n integers, find the maximum sum of a contiguous subarray
using the Divide and Conquer approach. Analyze the time complexity of your solution and
verify if the Master Theorem applies.
Approach: We use the Divide and Conquer approach to solve the problem. The algorithm
divides the array into two halves:
#include <stdio.h>
#include <limits.h>
return (a > b) ? a : b;
}
// Function to find the maximum crossing subarray sum
int sum = 0;
sum += arr[i];
left_sum = sum;
sum = 0;
sum += arr[i];
right_sum = sum;
if (low == high)
return arr[low];
int mid = (low + high) / 2;
int main() {
return 0;
Q.2 (CO2) Given two n×n times matrices A and B, multiply them using Strassen’s Divide
and Conquer algorithm. Analyze the recurrence relation and determine the time
complexity using the Master Theorem.
Approach: Strassen's algorithm for matrix multiplication is based on dividing the matrices
into four submatrices and performing recursive operations to calculate the product
efficiently.
#include <stdlib.h>
C[0][0] = M1 + M4 - M5 + M7;
C[0][1] = M3 + M5;
C[1][0] = M2 + M4;
C[1][1] = M1 - M2 + M3 + M6;
int main() {
strassen(A, B, C);
printf("Product matrix:\n");
printf("\n");
return 0;
}