400 likes | 465 Views
Notation 2. Let A be a sequence of n ordered pairs of real numbers (a 1 , w 1 ), (a 2 , w 2 ), …, (a n , w n ), w i > 0 . A segment A(i, j) is a consecutive subsequence (a i , w i ), (a i+1 , w i+1 ), …, (a j , w j ).
E N D
Notation 2 • Let A be a sequence of n ordered pairs of real numbers (a1, w1), (a2, w2), …, (an, wn), wi > 0. • A segment A(i, j) is a consecutive subsequence (ai, wi), (ai+1, wi+1), …, (aj, wj). • The width w(i, j) of segment A(i, j) is wi+wi+1+ …+ wj. • The sum s(i, j) of segment A(i, j) is ai+ai+1+ …+ aj. • The density d(i, j) of segment A(i, j) is s(i, j) / w(i, j).
Notation 1 • A segment A(i,j) is feasible if its width satisfies ℓ ≦ w(i, j) ≦ u. • The rank of an element in a set P of the real numbers, r(x, P) = | {y | y P, y x} |
Density Selection Problem (DSP) 2 • Input: • a sequence A of n ordered pairs of real numbers (a1, w1), (a2, w2), …, (an, wn), wi > 0 • two nonnegative real numbers ℓ, u with ℓ u • a positive integer k. • Output: • The segment A(i*, j*) such that the rank of its density d(i*, j*) in the set of densities of all possible feasible segments is k. The total number of feasible segment is (u - ℓ) n = O(n2)
Density Selection Problem 1 An Example • Input: • A=3, -4, -2, 5, wi = 1 • ℓ= 2, u = 4 • k = 3 • Output: • Densities of all feasible segments: • The k smallest feasible segments: d(1, 2) = -1/2 d(2, 3) = -3, d(3, 4) = 3/2, d(1, 2) = -1/2, d(2, 4) = -1/3, d(1, 3) = -1, d(1, 4) = 1/2, d(i*, j*) = d(1, 2) = -1/2, d(2, 3) = -3, d(1, 3) = -1, d(3, 4) = 3/2,
Transforming DSP to Geometric Slope Selection Problem (GSSP) 5 • Define a set L = {l1, l2 …, ln} of n lines in R2, where li : y = xi x - yi = w(1, i) x – s(1, i) • li andli will intersect at point pij with abscissa xij = (yj -yi)/(xj - xi) = s(i+1, j)/w(i+1, j) = d(i+1, j) • An intersection point of two lines li, lj is feasible if ℓ ≦ xj - xi = w(i+1, j)≦u.
Transforming DSP to Geometric Slope Selection Problem 4 • Input: • a set L = {l1, l2 …, ln} of n lines in R2, where li : y = xi x - yi = w(1, i)x – s(1, i) • two nonnegative real numbers ℓ, u with ℓ u • a positive integer k. • Output: • The feasible intersection point such that the rank of its abscissa in the set of all possible feasible intersection points is k.
DSP Transform to GSSP 2An Example • Input: • A=3, -4, -2, 5 • ℓ= 2, u = 4, wi = 1 • k = 3 • Output: the 3rd feasible density d(1, 2) = -1/2 Transform DSP to GSSP • Input: • l0 ,l1 ,…, l5where li : y = w(1, i) x – s(1, i) = i x - s(1, i) • ℓ= 2, u = 4, wi = 1 • k = 3 • Output: the 3rd feasible intersection point p0,2 = -1/2
ℓ0 : y= 0 ℓ1: y = x-3 ℓ2: y = 2x+1 ℓ3: y = 3x+3 ℓ4: y = 4x-2 DSP Transform to GSSP 1 An Example 5 ℓi: y=w(1,i) x-s(1,i) ℓj: y=w(1,j) x-s(1,j) When ℓi intersects ℓj, we have x = s(i+1,j)/w(i+1,j) = d(i+1, j) p0,2 = -1/2 0 • ℓ = 2, u = 4, k = 3 An intersection point is feasible if ℓ ≦ xj - xi = w(i+1, j)≦ u. -5 Find the k-th abscissa over all feasible intersection points (solid blackpoints) -5 0 5 10
Main Ideas for Solving DSP: Prune-and-Search 4 • Using three techniques to do Prune-and-Search • Random Sampling: Randomly generate n intersection points such that their abscissae lie in a given interval [dl, dr] • Counting mode for Density Range Query Problem Count the total number of feasible intersection points in a given interval [dl, dr]. • Reporting mode for Density Range Query Problem Enumerate feasible intersection points in a given interval [dl, dr].
Main Ideas for Solving DSP: Prune-and-Search 3 • To find a subinterval [dl', dr'] • containing the k-th feasible point d* = d(i*, j*) • containing only a specific ratio of feasible points in [dl, dr] and a specific ratio of points in [dl, dr]. • To prune the set of points outside [dl', dr']. dl d* dr dl' dr'
Main Ideas for Solving DSP: Prune-and-Search 2 • to check whether [dl', dr'] containing k-th feasible pt d* • k2 = # of feasible points in [dl, dr'] • k1 = # of feasible points in [dl, dl'] • d* in [dl', dr'] k1 < k ≦ k2 • to check whether [dl', dr'] containing a specific ratio of feasible pts in [dl, dr] and a specific ratio of pts in [dl, dr]. dl d* dr dl' dr'
Main Ideas for Solving DSP: Prune-and-Search 1 • Repeat the algorithm in [dl', dr']until:[dl'', dr''] contains O(n) feasible intersection points and d* lies in [dl'', dr''] • Reporting mode for Density Range Query Problem • Enumerate all feasible intersection points in [dl'', dr''] by the Reporting subroutine of DRQP • Select from those feasible points the k-th smallest point d* by using any standard selection algorithm. dl'' dl d* dr dl' dr'' dr'
Density Range Query Problem: Reporting Mode 3 • Input: • a sequence A of n ordered pairs of real numbers (a1, w1), (a2, w2), …, (an, wn), wi > 0 • two nonnegative width bounds ℓ, u with ℓ u • two density bounds dl, dr with dl dr • Output: • Enumerate all feasible segments A(i, j) such that their densities d(i, j) satisfy dl d(i, j) dr.
Example:DRQP Reporting Mode 2 • Input: • A = 1, 3, 5, 7, 9, 11 , wi = 1 • ℓ = 2, u = 4 • dl = 4.5, dr = 7.5 • Output: s(2, 4), s(3, 5), s(2, 5) s(3, 4), 1 segment of width 6 2 segments of width 5 4 feasible segments of width 3 5 feasible segments of width 2 3 feasible segments of width 4 6 segments of width 1 0 1 2 3 4 5 6 7 8 9 10 11 12
Density Range Query Problem: Reporting Mode 1 • Lemma 1: The reporting version of the Density Range Query Problem can be solved in O(n) space and O(n log m + h) time, where m is min{(u-ℓ)/wmin, n} and h is the output size. • Proof: Reduce to n range queries of the form R= [u, w] x (-∞,v] using dynamic priority search tree.
Density Range Query Problem: Counting Mode 3 • Input: • a sequence A of n ordered pairs of real numbers (a1, w1), (a2, w2), …, (an, wn), wi > 0 • two nonnegative width bounds ℓ, u with ℓ u • two density bounds dl, dr with dl dr • Output: • Find the number of feasible segments A(i, j) such that their densities d(i, j) satisfy dl d(i, j) dr.
Example: DRQP Counting Mode 2 • Input: • A = 1, 3, 5, 7, 9, 11 • ℓ = 2, u = 4 • dl = 4.5, dr = 7.5 • Output: 4 0 1 2 3 4 5 6 7 8 9 10 11 12
Density Range Query Problem: Counting Version 1 • Lemma 2:The counting version of the Density Range Query Problem can be solved in O(n) space and O(n log m) time, where m is min{(u-ℓ)/wmin, n} • Proof: Reduce to n rank queries to order-statistics trees of size m.
Random Sampling 3 • Lemma 3: [Dillencourt et al. ‘92] • Given a set L = {l1, l2 …, ln} of n lines in R2 and an interval [dl, dr] We can randomly generate n intersection points in O(n log n) time to obtain a random sampling S such that the abscissae of all intersection points of S are in [dl, dr]. • Proof: By merge sort technique.
Monte Carlo Random Sampling 5 • Input: • a set L = {l1, l2 …, ln} of n lines in R2, where li : y = xix - yi = w(1, i) x – s(1, i). • two nonnegative real numbers ℓ, u with ℓ u • two density bounds dl, dr with dl dr • Output: • Randomly generate a set S of n intersection pts such that their abscissae lie in [dl, dr] and contain M to 3M feasible intersection points, where M = (n/2)(Nf/N), Nf = # feasible intersection pts in [dl, dr] N = # intersection pts in [dl, dr]
Monte Carlo Random Sampling 4 • We can show that in a random sampling of n intersection points the probability of the number F of feasible intersection points lying between M and 3M, is no less than ½, i.e., Proba.{M≦F≦3M} ≧½, where F is # feasible intersection pts in S.
Monte Carlo Random Sampling 3 An Example Randomly generate n = 6 pts such that their abscissaelie in [dl, dr]= [3.5, 8.5]. They may contain only 1 feasible pt < M = 1.7, where M = (n/2)(Nf/N), Nf=12, N= 21. • Input: • A = 1, 3, 5, 7, 9, 11 • ℓ = 2, u = 4 • dl = 3.5, dr = 8.5 • Output: s(3, 3), s(5, 5),s(3, 4),s(1, 5) , s(2, 6) , s(1, 6) 0 1 2 3 4 5 6 7 8 9 10 11 12
Monte Carlo Random Sampling 2 An Example Randomly generate n = 6 pts such that their abscissaelie in [dl, dr]= [3.5, 8.5]. They may contain 6 feasible pts > 3M = 5.1, where M = (n/2)(Nf/N), Nf=12, N= 21. • Input: • A = 1, 3, 5, 7, 9, 11 • ℓ = 2, u = 4 • dl = 3.5, dr = 8.5 • Output: s(2, 3), s(3, 4), s(4, 5), s(2, 4) , s(3, 5) , s(2, 5) 0 1 2 3 4 5 6 7 8 9 10 11 12
Monte Carlo Random Sampling 1 An Example Randomly generate n = 6 pts such that theirabscissaelie in [dl, dr]= [3.5, 8.5]. They contain M = 1.7 to 3M = 5.1 feasible pts, where M = (n/2)(Nf/N), Nf=12, N= 21. • Input: • A = 1, 3, 5, 7, 9, 11 • ℓ = 2, u = 4 • dl = 3.5, dr = 8.5 • Output: s(2, 4), s(3, 5), s(2, 5) s(3, 4), 0 1 2 3 4 5 6 7 8 9 10 11 12
Monte Carlo Random Sampling 3 • Lemma 4:The Monte Carlo Random Sampling can be solved in O(n) space and expected O (n log n) time. • Proof: • Monte Carlo random sampling subroutinewith success probability p ≧1/2 • By Chebyshev’s inequality.
Using Monte Carlo Random Sampling to Contract Search Interval2 • Assume we have obtained a random sampling S' containing M to 3M feasible points, S' = {s1, s2, …,sF}, where M ≦ F ≦ 3M • For each si in S', it has a probability k/Nf such that it is smaller than or equal to d*. • Consider such an event a "success" in performing F independent Bernoulli trials, each with a probability k/Nf. s4 s1 s2 s3 sF dl d* dr
Using Monte Carlo Random Sampling to Contract Search Interval1 • Let Xi be a random variable, • attaining value 1 with probability p= k/Nf • attaining value 0 with probability q= 1 - k/Nf • X = X1 + X2 +… + XF # sample feasible pts smaller than or equal tod*. • = F p = F k/Nf , = (F p(1-p))1/2 ≦ F1/2/2. • The -th smallest element sin S' should be a good approximation for the k-th smallest feasible intersection point d*. • Let l' = max {1, - t F1/2/2} and r' = min {F, + t F1/2/2} for some constant t to be determined later. • Select l'-th smallest element dl' and the r'-th smallest element dr' in S' by any standard selection algorithm to obtain a subinterval [dl' ,dr']. sr' s sl' dl dl' d* dr' dr
Properties of Subinterval Obtained by Monte Carlo Random Sampling3 • Using the Monte Carlo Random Sampling, wecan find a subinterval [dl',dr'] such that • d*[dl', dr'] with probability p≧1/2. • it contains O(Nf/M1/2) feasible pointswith probability p≧1/2 and O(N/M1/2) intersection pointswith probability p≧1/2.
Properties of Subinterval Obtained by Monte Carlo Random Sampling2 • Lemma 5: • N = # of intersection pts in [dl, dr] • Nf = # of feasible intersection pts in [dl, dr] For a random choice of F independent feasible pts in [dl, dr] where M≦F≦3M, we can find a subinterval [dl', dr'] such that the probability that the k-th smallest feasible intersection pt d* not lying in [dl', dr'] is at most 2e-t2/2. • We can choose t large enough such that 2e-t2/2≦ ½.
Properties of Subinterval Obtained by Monte Carlo Random Sampling 1 • Lemma 6: • N = # of intersection pts in [dl, dr] • Nf = # of feasible intersection pts in [dl, dr] • For a random choice of F independent feasible pts in [dl, dr] where M≦F≦3M, we can find a subinterval [dl', dr'] such that the probability that it contains at least (t2/(t-1))(Nf/M1/2) feasible pts is at most e-sqrt{M}/2(t-1)and the probability that it contains at least (3t2/2(t-1))(N/M1/2) pts is at most e-sqrt{M}/2(t-1). • We can choose M large enough such that e-sqrt{M}/2(t-1) ≦ ½.
Density Selection Range Query Problem 3 • Input: • a sequence A of n ordered pairs of real numbers (a1, w1), (a2, w2), …, (an, wn), wi > 0 • two nonnegative real numbers ℓ, u with ℓ u • an interval [dl, dr] • a positive integer k. • Output: • The feasible segment A(i*, j*) such that the rank of its density d*[dl, dr] in the set of densities of possiblefeasible segments in [dl, dr] is k.
DSP: A Special Case of DSRQP 2 • The Density Selection Problem is a special case of Density Selection Range Query Problem such that [dl, dr] = (-, ).
Example: DSRQP 1 • Input: • A = 1, 3, 5, 7, 9, 11 • ℓ = 2, u = 4 • dl = 3.5, dr = 8.5 • k = 6 • Output: s(3, 5) 0 1 2 3 4 5 6 7 8 9 10 11 12
Algorithm for Density Selection Range Query Problem 2 • Use Monte Carlo Random Sampling to select F feasible segments S = {s1, s2, …, sF} in [dl, dr]. • Let l' = max {1, - (t/2)} and r' = min {F, + (t/2)}, for some t and select the l'-th smallest element dl' and the r'-th smallest element dr' in S, where is expected value of d* and is standard deviation. dl dl' dl' dr' d* dr' dr dl' dr' Until d* lies in [dl', dr'] and [dl', dr']contains < Nf'=(t2/(t-1))(Nf/M1/2) feasible pts & < (3t2/2(t-1))(N/M1/2) pts If [dl', dr'] contains ≧(t2/(t-1))(Nf/M1/2)feasible pts or ≧ (3t2/2(t-1))(N/M1/2) pts, then repeat the random experiment. If d* doesn’t lie in [dl', dr'], then repeat the random experiment.
Algorithm for Density Selection Range Query Problem 1 • We first run the algorithm in [dl, dr] until: d* lies in [dl', dr'] and [dl', dr'] contains less than Nf' = (t2/(t-1))(Nf/M1/2) feasible intersection points • We then run the algorithm once more in [dl', dr'] until: d* lies in [dl'', dr''] and [dl'', dr''] contains less than Nf'' = (t2/(t-1))( Nf'/M1/2) =O(n) feasible intersection points • Then, we can enumerate all feasible densities in the interval [dl'', dr''] by the reporting mode of Density Range Query Problem • Then select from those densities theκ-th smallest density d* for an appropriate κby using any standard selection algorithm. dl'' dl d* dr dl' dr'' dr'
Main Theorem • Theorem 1: The Density Selection Problem can be solved in O(n) space and expected (n log n) time.
Conclusion • We have presented a randomized algorithm for the Density Selection Problem that runs in expected (n log n) time. • It is a generalization of three well known problems, • maximum density segment problem, • slope selection problem • selection problem. • How to find a deterministic algorithm for the problem that runs within the same time bound is still open.