Maximum-Subarray Problem, Matrix Multiplication and Strassen's Algorithm
Maximum-Subarray Problem, Matrix Multiplication and Strassen's Algorithm
pairs, so O(2 )
What is the base case? How to combine the sub problem solutions to the current solution?
A fact:
when divide array A[i, , j] into A[i, , mid] and A[mid+1, , j] A sub array must be in one of them
A[i, , mid] // the left array A[mid+1, , j] // the right array A[ , mid, mid+1.] // the array across the midpoint
The maximum subarray is the largest sub-array among maximum subarrays of those 3
Target array :
1 1
-4
1
-4 3 2 -4 3 2 -3 3 3 2 -1 5 0 2 2 1 2
-4 -4
Max! 1 -4 -4 1 -4
3 3 3
Target array :
1 1
-4
All the sub arrays: The problem can be then solved by: 1. Find the max in left sub arrays 2. Find the max in right sub arrays 3. Find the max in crossing sub arrays
1
-4 3 2 -4 3 2 -3 3 3 2 -1 5 0 2 2 1 2
We then have 3 types of subarrays: The ones belong to the left array The ones belong to the right array
-4 -4
-4 -4
3 3 3
-4
FindMaxSub (
-4
) FindMaxSub ( 1 -4 )
-4
2 once
-4
1 -4
3 3
+ (n)
Matrix multiplication
How to multiply two matrices?
9 = 1 2 3 2 1
11 12 11 12 11 = 21 21 22 21 22 11 = 11 11 + 12 21 12 = 11 12 + 12 22 21 = 21 11 + 22 21 22 = 21 12 + 22 22 Recurrence equation?
2
12 22
= 8
+ (2 )
+ (2 )
+ (2 )
= 7
+ (2 )
+ (2 )= (27 )