1. 程式人生 > >ADA演算法知識(七)Divide and conquer algorithm(分治法解決最大子陣列和問題)

ADA演算法知識(七)Divide and conquer algorithm(分治法解決最大子陣列和問題)

[Maximum Subarry Sum] The maximum subarry sum problem takes as input an array of (positive or negative) integers a[1..n] and returns the largest sum of any subsequence of the form a[j]+a[j+1]+...+a[j+k], where 0<=k<=n-1 and k+j<=n-1. You need to design a divide and conquer algorithm for this problem that runs in time O(nlogn).

(a) Describe your algorithm below.

 

(b)Analyze the complexity of your algorithm and show that your algorithm runs in O(nlogn) using the master theorem.

T(n)=2T(n/2)+cn