All Range Medians S. Muthukrishnan March 14, 2009 We are given an array A[1, . . . , n] of numbers. Our problem is to output, for each interval [l, r], • The median of items A[l], A[l + 1], . . . , A[r], denoted med[l, r], • The left sum, that is,

P

• The right sum, that is,

i∈[l,r] | A[i]≤med[l,r] (med[l, r]

P

i∈[l,r] | A[i]≥med[l,r] (A[i]

− A[i]), and

− med[l, r]).

The currently best known algorithm [1] takes O(n log n + k log n) time for finding the median of each of the k intervals (we assume that this algorithm can be extended to find the left and right sums). Since we have O(n2 ) total intervals in all, this algorithm takes O(n2 log n) time for our problem. We give an improved algorithm here. We will focus on finding the median and the left sum; finding right sum is analogous. Step 1. For each interval [l, r] with its endpoints at multiples of integer x, for some x to be determined later, we find sorted set S[l, r] of items of rank [|l − r + 1|/2 − 2x, . . . , [|l − r + 1|/2 + 2x] in A[l], . . . , A[r]; if the interval has fewer than 4x + 1 items,keep them all. For each such item i ∈ S[l, r], we keep the sum si of smaller items in the interval. This step can be done using [1] to find for each interval, the item L of rank |l − r + 1|/2 − 2x and U of rank |l − r + 1|/2 + 2x. We use a 2d range structure on points (i, A[i]) to determine the points in the set S[l, r] (and their total sum) in time O(log n + x) for each interval with the range query [l, r] × [L, U ]. Further, we assume the points in S[l, r] can be sorted in O(x log x) time. This also suffices to compute si for such items i ∈ S[l, r]. The total time for this step is O((n/x)2 (log n + x log x)). Step 2. For each interval [l, r] such that jx ≤ l < r ≤ (j + 1)x, we sort all points and keep prefix and suffix sums for all points. There are O(x2 ) such intervals for each j, and for each, we take O(x log x) time. In all, the time taken is O((n/x)x3 log x). Step 3. Now we complete the computation for the remaining intervals [l, r]. These intervals have the form [l, jx − 1] : [jx, j 0 x] : [j 0 x + 1, r] where the middle interval [jx, j 0 x] was processed in Step 1, and the other intervals were processed in Step 2. We have, Lemma 1 med[l, r] is the median of the set of elements in [l, jx − 1], those in [j 0 x + 1, r], and those in set S[jx, j 0 x]. Proof. Recall the definition of L and U for the interval [jx, j 0 x]. Observe that we have all the elements in [l, r] between L and U in the set under consideration. Further observe that med[l, r] has to lie between L and U , because we add no more than 2x elements to [jx, j 0 x]. Now the lemma follows. There are O(n2 ) such intervals and each takes O(x) time to process, for total running time O(n2 x). The complexity of the entire algorithm is O((n/x)2 (log n + x log x) + (n/x)x3 log x + n2 x). We will have x log x < log n. Hence, the dominating complexity is O((n/x)2 log n + n2 x) which is minimized when x = log1/3 n, giving: 1

Theorem 1 There is an O(n2 log1/3 n) time algorithm for our problem. An improvement follows from observing that Step 3 involves finding the median of three sorted arrays of total size O(x) which can be done in O(log x) time. Then the overall complexity is O((n/x)2 (log n + x log x) + (n/x)x3 log x + n2 log x). The dominating complexity is now O((n/x)2 (log n + x log x) + q log n n2 log x) which is minimized when x2 log x = log n, or x ∼ log log n . The overall complexity is then O(n2 log log n). Theorem 2 There is an O(n2 log log n) time algorithm for our problem. To extend this further, notice that the algorithm above in fact can be used to solve Step 1 for a subset of positions. Then, if we iterate, we should minimize complexity when x2 log x = log log n which gives O(n2 log log log n) and so on.

References [1] B. Gfeller and P. Sanders. Towards Optimal Range Medians Manuscript, 2009.

2

All Range Medians

Mar 14, 2009 - The currently best known algorithm [1] takes O(nlog n+k log n) time for finding the median of each of the k intervals (we assume that this ...

69KB Sizes 1 Downloads 276 Views

Recommend Documents

Triangles with three rational medians - OoCities
Sep 5, 2002 - Theorem 1 Every rational-sided triangle with three rational medians corre- sponds to a point on the one parameter elliptic curve. E[φ] : y2 = x(x2 ...

Triangles with three rational medians
Sep 5, 2002 - tion of such triangles in which all three such lengths were rational, namely, a = 2q(−9q4 + ..... Table 1: Rank of some curves E[p, q] verified via ...

Symmetries of triangles with two rational medians
Keywords : rational area triangle, fundamental domain, elliptic curve, rational medians. 1 Introduction. A perfect triangle, as defined by Richard Guy (see [6] D21) ...

Range extension f Range extension for Thomas' Mastiff bat ... - SciELO
E-mail: [email protected]; [email protected] ... two locations, all bats were roosting in palm leaves while in the later location, a single ...

Idukki Dt -Provisional High Range & Low range Seniority list of ...
Page 2 of 3. '),. -. 47. 3. 6 2012 MinimolChacko VH Chackkupalbm. 48. 6. 6 2012 Linta PA Sub Centre K.Chappathu. 49. 6 2012 Dilip Varqhese Sub Centre Sdnthanpara. 50. 8. 6 2012 sanitha S Nair Sub cent.e Kallar. 51 12. 5 2012 Johney Chacko RPC Kumily.

Consequences of Range Contractions and Range ...
neighboring demes, implying that these edges act as par- tially absorbing ... plus a 5-deme thick layer containing two refuge areas of size 5 В 5 demes. The four gray ..... Page 6 ... The comparison of range shift scenarios with isotropic and anisot

COMPREHENSIVE EQUIPMENT RANGE
processing hard and soft rock, sand and gravel, ore and industrial minerals. Our offering ..... construction, and affordable wear components, separate us from the .... rail-car loading and unloading stations, ore pass recovery ..... Motor Drive.

High Dynamic Range Imaging - GitHub
Oct 2, 2009 - Page 3 .... IC 2233 is an isolated superthin galaxy (D ~ 10.5 +/- 1 Mpc). • Mk 86 is a blue compact dwarf, spiral galaxy (D ~ 7 +/- 1 Mpc).

Scale Range Requirement.pdf
North County High School Bands Scale Test Octave Requirements. State Audition Octave Requirements. Note: State Mallet Scales have an altered ending with ...

Interface Range Specification
VLAN interfaces not displayed by the show running-configuration command cannot be used with the interface range command. Supported Platforms. The Interface Range Specification feature runs on all platforms that support Cisco IOS. Release 12.0(7)XE, R

forest range officer.pdf
The rate of land revenue was highest during the reign of. 5. a) Ghiyasuddin Balban b) Mohammed Bin Tughlaq c) Allauddin ... The heaviest mass revolving round the Sun? a) Moon b) Jupiter c) Neptune d)Pluto. 54. The line join the areas ... forest range

Long-range energy transfer in proteins - CiteSeerX
Nov 12, 2009 - destination site, which acts as an efficient energy-accumulating center. Interestingly ..... In summary, despite its coarse-grained nature, the NNM.

Gasoline Range Organics (Inggris).pdf
Page 1 of 1. Gasoline Range Organics (Inggris).pdf. Gasoline Range Organics (Inggris).pdf. Open. Extract. Open with. Sign In. Main menu. Displaying Gasoline ...

Trading the Opening Range - Swing-Trade-Stocks.com
occasionally throughout this book because it is a big contributor to the information and insights ... trading approach uses some basic technical analysis. ..... the common belief that historical price and volume data can be used to indicate when.

RPSC Forest Range Recruitment [email protected] ...
lfpo. &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& www.govnokri,in. Page 2 of 2. RPSC Forest Range Recruitment [email protected]. RPSC Forest Range Recruitment [email protected]. Open. Extract. Open with. Sign In. Main

Processing Probabilistic Range Queries over ...
In recent years, uncertain data management has received considerable attention in the database community. It involves a large variety of real-world applications,.

JCB JS Range Spec.pdf
Loading… Page 1. Whoops! There was a problem loading more pages. Retrying... JCB JS Range Spec.pdf. JCB JS Range Spec.pdf. Open. Extract. Open with. Sign In. Main menu. Displaying JCB JS Range Spec.pdf.

rv Open Range Owners Manual.pdf
Page 3 of 88. rv Open Range Owners Manual.pdf. rv Open Range Owners Manual.pdf. Open. Extract. Open with. Sign In. Main menu. Displaying rv Open Range ...

Domain and Range Matching Game.pdf
There was a problem previewing this document. Retrying... Download. Connect more apps... Try one of the apps below to open or edit this item. Domain and ...

range rover brochure pdf
File: Range rover brochure pdf. Download now. Click here if your download doesn't start automatically. Page 1 of 1. range rover brochure pdf. range rover ...

Range Aggregation with Set Selection
“find the minimum price of 5-star hotels with free parking and a gym whose .... such pairs, such that the storage of all intersection counts ...... free, internet,. 3.

coke gb range images pdf.pdf
IOS и Android. 4 min - Uploaded ... https://play.google.com/store/apps/details?id=com.gameloft.android.ANMP. .... Displaying coke gb range images pdf.pdf.