The Problem of K Maximum Sums and its VLSI
Implementation
Sung Eun Bae, Tadao Takaoka
University of Canterbury
Christchurch New Zealand
Problem of Maximum Sum
Originated by Bentley To find a portion of maximum sum in an array
1-dimension : Maximum subsequence problem 2-dimension: Maximum subarray problem
-7531
-194-3
6-8-24
7-2-53
-7531
-194-3
6-8-24
7-2-53-958-937-65
S=14
-958-937-65
S=21
For one dimensional array of size n
How fast can we compute?
x1 x2 x3 x4 x5 x6 x7 x8 x9 x10
x1 x2 x3 x4 x5 x6 x7 x8 x9 x10
Size n
1
x10x9x8x7x6x5x4x3x2
x9x8x7x6x5x4x3x2x1n-1
Size 2
x10x9x8x7x6x5x4x3x2x1n
Size 1 …
Total Number=n+(n-1)+(n-2)+…+2+1=n(n+1)/2 Is it O(n2)? No!!!
x10x9x8x7x6x5
x9x8x7x6x5x4
x8x7x6x5x4x3
Size 3
x3x2 x4x1 x3x2
n-2
x2 x3 x4 x5 x6 x7 x8 x9 x10x1 x2 x3 x4 x5 x6 x7 x8 x9
Size n-1
2
/*maximum subsequence a[x1..x2] of a[1..n]*/(x1,x2):=(0,0); s:=-∞; t:=0; i:=1;for j:=1 to n begin
t:=t+a[j];if t>s then begin (x1,x2):=(i,j); s:=t endif t<0 then begin t:=0; i:=j+1; end //reset accumulation
end
t=-1
s=5
t=0
s=5
Maximum Subsequence ProblemKadane’s algorithm: O(n)
-958-937-65 -958-937-65t=5
s=5
t=7
s=7
t=10
s=10
t=1
s=10
t=9
s=10
t=14
s=14
t=5
s=14
t=0
s=-∞
Maximum Subarray Problem
Two dimensional array:
Based on Kadane’s algorithm: O(n3) (iterative)
Best result by Tamaki, Tokuyama: O(n3(loglogn/logn)1/2) (divide-and-conquer)
The Problem of K Maximum Sums
What about 2nd ,3rd …Kth maximum sum? We expect,
O(K*n) : K maximum subsequences O(K*n3): K maximum subarrays
Key idea Prefix sum: sum of preceding cells Eg. K=3
Maximum sum=max(a[x]+a[x+1]+…+a[y]) =max(sum[y]-sum[x-1])
-26-15-1 7934-1a sum
Kadane’s framework is not capable…
[ ] [ 1] ... [ ] [ ] [ ] [ 1]y
i x
a x a x a y a i sum y sum x
Eg. a[2]+a[3]=sum[3]-sum[1]=4
K Maximum Subsequences Algorithm
Sums of all subsequences ending at a[i] obtained by
sum[i]-sum[0…i-1]
Eg. i=4,
sum[4]-sum[0,1,2,3]=9-{0,-1,4,3}={9,10,5,6}
Sums of K maximum subsequences ending at a[i] obtained by sum[i]-min[K](sum[0…i-1]) Eg. i=4 K=3
sum[4]-min[3](sum[0,1,2,3])=9-min(0,-1,4,3)=9-{-1,0,3}={10,9,6}
-26-15-1 7934-1a sum
-15-1 6 -15 6 -1 6 6
K Maximum Subsequences Algorithm
min_prefixi[1..K] are K minimum prefix sums (select from sum[0,…,i-1]) sum[i]-min[K](sum[0…i-1])1= sum[i]- min_prefixi[1..K]
Possible K-candidates (K=3) by sum[i]-min_prefixi[1..K]
i=1: -1-{0, ∞, ∞}={-1,-∞, -∞}
i=2: 4-{-1,0, ∞}={5,4, -∞}
i=3: 3-{-1,0,4}={4,3,-1}
i=4: 9-{-1,0,3}={10,9,6}
i=5: 7-{-1,0,3}={8,7,4}
-26-15-1 7934-1a sum
{∞,∞,∞}min_prefixi
0sum(i)
{-1,0,3}
7
5
{-1,0,3}
9
4
{-1,0,4}
3
3
{-1,0, ∞}
4
2
{0,∞, ∞}
-1
1i
-1
5 5-1
-15 -15-1 -1
-15 6 -15 6-1 6
6-1 -25 -15 6-1 -2 -26
K=3
K Maximum Subsequences Algorithm
Final K Maximum Sums
-26-15-1 7934-1a sum
6-15
6-15-1
-26-15
O(K*n)
{∞,∞,∞}min_prefixi
0sum(i)
{-1,0,3}
7
5
{-1,0,3}
9
4
{-1,0,4}
3
3
{-1,0, ∞}
4
2
{0,∞, ∞}
-1
1i
Take K best candidates
=10
-1
5 5-1
-15 -15-1 -1
-15 6 -15 6-1 6
6-1 -25 -15 6-1 -2 -26
=9
=8
-1
5 4
4 3 -1
10 9 6
8 7 4
K Maximum Subarrays Problem
Based on K maximum subsequences algorithm
10
-26
8-64
13-2
13-2
8-64
10-26
8-64
13-2
10-26
8-64
10-26
8-64
13-2
8-12
20210
21-2
6-24
1446
2238
n=3
m=3
3
2
1
m+(m-1)+..+1=m(m+1)/2=O(m2)
∴O(m2) K maximum
subsequences
Prefix sums
K Maximum Subarrays Problem
K maximum subarrays problem
K maximum subsequences problem
m(m+1)/2 *
Analysis Each K maximum subsequences algorithm takes O(K*n) time O(m2) such problems to solve O(K*m2*n) time
O(K*m2*n)≒O(K*n3)
Parallel Algorithm for Maximum Subarray Problem
PRAM and Interconnect hypercube: T=O(logn) time P=O(n3/logn) processors (P*T=O(n3) and is optimal)
Mesh1. T=O(n) time2. P=O(n2) processors3. (P*T=O(n3) and optimal)
Mesh model
Motivation The size of job for each node
is very small and identically distributed
Mesh-type parallel algorithm can be easily programmed in a single VLSI chip
Cost-effective parallelisation Practical
VLSI Algorithm Design of Circuit
n
m
m*n nodes
Data transmission is made vertically & horizontally
Control signal is propagated downwards triggering horizontal transmission.
Registor1,2,…
control
Control signal
VLSI Algorithm for K Maximum Subarrays Problem
s: prefix sum
(r1,c1)|(r2,c2): coordinates of Mx
M1..MK
The K maximum subarrays
m1…mK
the K minimum prefix sums
r: row-wise sum
v:value of the cell
cell(i,j)
The number of parallel steps based on data transmission
VLSI Algorithm for K Maximum Subarrays Problem
s: prefix sum
(r1,c1)|(r2,c2): coordinates of Mx
M1..MK
The K maximum subarrays
m1…mK
the K minimum prefix sums
r: row-wise sum
v:value of the cell
cell(i,j)
VLSI Algorithm for K Maximum Subarrays Problem
s: prefix sum
(r1,c1)|(r2,c2): coordinates of Mx
M1..MK
The K maximum subarrays
m1…mK
the K minimum prefix sums
r: row-wise sum
v:value of the cell
cell(i,j)
VLSI Algorithm for K Maximum Subarrays Problem
s: prefix sum
(r1,c1)|(r2,c2): coordinates of Mx
M1..MK
The K maximum subarrays
m1…mK
the K minimum prefix sums
r: row-wise sum
v:value of the cell
cell(i,j)
VLSI Algorithm for K Maximum Subarrays Problem
s: prefix sum
(r1,c1)|(r2,c2): coordinates of Mx
M1..MK
The K maximum subarrays
m1…mK
the K minimum prefix sums
r: row-wise sum
v:value of the cell
cell(i,j)
VLSI Algorithm for K Maximum Subarrays Problem
s: prefix sum
(r1,c1)|(r2,c2): coordinates of Mx
M1..MK
The K maximum subarrays
m1…mK
the K minimum prefix sums
r: row-wise sum
v:value of the cell
cell(i,j)
VLSI Algorithm for K Maximum Subarrays Problem
s: prefix sum
(r1,c1)|(r2,c2): coordinates of Mx
M1..MK
The K maximum subarrays
m1…mK
the K minimum prefix sums
r: row-wise sum
v:value of the cell
cell(i,j)
VLSI Algorithm for K Maximum Subarrays Problem
s: prefix sum
(r1,c1)|(r2,c2): coordinates of Mx
M1..MK
The K maximum subarrays
m1…mK
the K minimum prefix sums
r: row-wise sum
v:value of the cell
cell(i,j)
•T=O(K*n)•P=m*n=O(n2)•Total cost T*P=O(K*n3)
Top Related