An Optimal Algorithm for MAXDENSITY SEGMENT Problem - PowerPoint PPT Presentation

1 / 29
About This Presentation
Title:

An Optimal Algorithm for MAXDENSITY SEGMENT Problem

Description:

... through all O(n2) feasible segments and output one segment with maximum density. ... based upon geometric interpretation, but the analysis of time complexity ... – PowerPoint PPT presentation

Number of Views:27
Avg rating:3.0/5.0
Slides: 30
Provided by: NTU57
Category:

less

Transcript and Presenter's Notes

Title: An Optimal Algorithm for MAXDENSITY SEGMENT Problem


1
An Optimal Algorithm for MAX-DENSITY SEGMENT
Problem
  • Kai-Min Chung Hsueh-I LU
  • NTU CSIE / Academia Sinica

2
Outline
  • The MAX-DENSITY SEGMENT problem
  • Previous works and our results
  • Our algorithm efficient implementation
  • On-line processing

3
The MAX-DENSITY SEGMENT problem
  • Input
  • a sequence S of n pairs of numbers (ai,wi)
  • ai the weight of i-th element
  • wi the width of i-th element (wigt0)
  • two width bounds L and U.

4
Notation
  • For a segment S(i,j)
  • width w(i,j) wi wj
  • density d(i,j) (ai aj) / w(i,j)
  • feasible if L ? w(i,j) ? U

S(1,4) width 7 density 1/7
5
The MAX-DENSITY SEGMENT problem
  • Output
  • a feasible segment S(i, j) with maximum density
    over all feasible segments of S
  • L 1 U 10
  • L 3 U 10
  • L 3 U 7

S(1,1) width 1 density 3
S(6,6) width 7 density 9/7
S(6,8) width 10 density 1.3
6
Simple Observations
  • There are only O(n2) segments S(i, j) in S.
  • Both indices i and j run over 1 to n
  • The density of each segment S(i, j) can be
    computed in O(1) time.
  • by O(n) pre-calculating accumulative sum
  • Ai a1 ai
  • Wi w1 wi
  • d(i, j) (Aj - Ai-1) / (Wj - Wi-1)

7
As a result
  • The problem has a naïve O(n2)-time algorithm
  • Go through all O(n2) feasible segments and output
    one segment with maximum density.

8
Privious works
  • First formulated by Inman 66 from biologic
    interesting
  • For the case without U, Lin 02 gave an
    O(nlogL) algorithm by right-skew decomposition
  • Goldwasser 02 gave an O(nlog(U-L1)) algorithm
    for general U, and improved the uniform case to
    O(n)

9
Privious works and our results
  • Kim 03 claims an O(n) algorithm based upon
    geometric interpretation, but the analysis of
    time complexity has some flaws.
  • We propose an O(n) algorithm for general case.
    Our approach can process the input sequence in an
    online manner.
  • We show how to exploit the sparsity of the input
    sequence

10
Our algorithm
11
Notation
  • j0 the smallest index with w(1,j0) ? L
  • For each j ? j0
  • lj the smallest index s.t. S(lj ,j) feasible
  • rj the largest index s.t. S(rj ,j) feasible
  • lj ,rj-1 is the removable region of j
  • ij the largest index with d(ij,j) max d(i,j)
    where i ? lj ,rj
  • The max-density segment must be S(it,t) for some
    t

L 4 U 8
removable region
rj
ij
lj
j
j0
12
Our strategy
  • For each j ? j0,n, we find a good candidate
    ij, and look for the max-density segment over all
    S(ij,j)
  • The correctness comes from it it

13
Key observation
  • For any three indices x ? y lt z, the order of
    d(x,y), d(y1,z), and d(x,z) can only be
  • d(x,y) ? d(x,z) ? d(y1,z)
  • d(x,y) ? d(x,z) ? d(y1,z)
  • x y z
  • Motivation by removing a lower density prefix
    of a segment, we can get a segment with higher
    density

14
Finding good ij
  • f(x,y) the largest index k ? x,y with d(x,k)
    min d(x,k), where k ? x,y
  • S(x,f(x,y)) is the valueless prefix of S(x,y)
  • Simple idea for a feasible segment S(i,j), we
    try to remove the valueless prefix of its
    removable region to get higher density

15
Finding good ij
  • subroutine FIND(x,j)
  • let i x
  • while i lt rj and d(i,f(i,rj-1)) ? d(i,j) do
  • let i f(i,rj-1)1
  • return i
  • lj x rj
    j
  • d(i,j) max d(k,j) for k ? x,rj
  • FIND(lj,j) ij

f(i,rj-1)
f(i,rj-1)
return i
f(i,rj-1)
removable region
16
Naïve algorithm
  • algorithm MAIN
  • for j j0 to n do
  • output ij FIND(lj, j)
  • ij ij for all j
  • hard to implement in O(n) time

17
Our algorithm
  • algorithm MAIN
  • for j j0 to n do
  • output ij FIND( , j)
  • Only it it (proved in the paper)

max(lj , ij-1)
18
Time complexity
  • algorithm MAIN
  • for j j0 to n do
  • output ij FIND( max(lj,ij-1), j)
  • subroutine FIND(x,j)
  • let i x
  • while i lt rj and d(i,f(i,rj-1)) ? d(i,j) do
  • let i f(i,rj-1)1
  • return i
  • require only linear steps since
  • both i and j are monotonically incresing
  • either i or j increases within O(1) steps

19
Efficent implementation
  • The challenge lies in supporting O(1)-time query
    for f(i,rj-1) in Step 2 of FIND
  • Things become easier when U is ineffective, e.g.,
    U w(1,n)

20
Case 1 U w(1,n)
  • In this case, lj 1 for all j
  • FIND( max(lj,ij-1), j) reduces to FIND(ij-1, j)
  • The value of i can only be
  • ij-1, f(ij-1,rj-1)1 , f(f(ij-1,rj-1)1,rj-1) ,
  • rj
    j
  • Lead us to maintain data structure Fj

f(ij-1,rj-1)1
f(f(ij-1,rj-1)1,rj-1)1
ij-1
removable region
21
Data structure Fj
  • Fj is an array with index over p,q s.t.
  • Fjp ij-1
  • Fjq rj
  • Fjt f(Fjt-1,rj-1)1 for t ? p1,q
  • rj
    j
  • Clearly, we can support O(1)-time query by Fj

Fjp
Fjp1
Fjq
removable region
22
Update Fj to Fj1
  • Iteratively increase rj to rj1
  • rj
    rj1 rj1 j j1
  • subroutine UPDATE(j)
  • for k rj1 to rj1 do
  • while p lt q and d(Fq-1 ,Fq -1) ? d(Fq-1
    , k-1) do
  • let q q-1
  • let q q1
  • let Fq k

23
Time complexity

  • rj rj1 rj1 j j1
  • Amotized linear time, since
  • each element is inserted to and removed from F at
    most once
  • either insertion or deletion occurs within O(1)
    steps

24
Case 2 U is effective(sketch)
  • The following situation will happen
  • ij-1 lj rj
    j
  • Fj may be
  • ij-1 lj rj
    j
  • hard to update Fj efficently in this case

25
Case 2 U is effective(sketch)
  • So we do not insist to update Fj correctly
  • ij-1 lj rj
    j
  • Sacrifice the segment with indices within
  • ij-1 lj rj
    j
  • Remedy this problem by finding max-density
    segment over what is sacrificed

26
Variant problem(sketch)
  • Finding a max-density segment with i ? x1,x2,
    j ? y1,y2, and width bound U
  • x1 x2 y1 y2
  • Our algorithm works well
  • for j y1 to y2 do
  • output ij FIND(max(lj ,i j-1), j))

27
Variant problem(sketch)
  • Again, the challenge is O(1)-time query f(i,rj-1)
  • Fortunately, in variant problem
  • L is ineffective, rj is always x2
  • We may pre-calculate f(,x2-1) in linear time
  • As a result, variant problem can be solved in
    time O(x2-x1y2-y1)

28
Time complexity
  • each sacrificed region is disjoint
  • ij-1 lj rj
    j
  • Our implementation runs in linear time

29
On-line processing
  • When j-th element comes
  • calculate accumulative sum Aj and Wj
  • update Fj-1 to Fj
  • calculate ij
  • if a variant problem occurs, pre-calculate
    f(,x2-1)
  • if a variant problem exists, calculate ij
Write a Comment
User Comments (0)
About PowerShow.com