Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 Nearest Common Ancestors (NCA) Discrete Range Maximum 1234567891011 4716 6213583 4 7 1 6 11 6 8 2 35 Cartesian Tree [Vuillemin 1980] i j max(i, j) i.

Similar presentations


Presentation on theme: "1 Nearest Common Ancestors (NCA) Discrete Range Maximum 1234567891011 4716 6213583 4 7 1 6 11 6 8 2 35 Cartesian Tree [Vuillemin 1980] i j max(i, j) i."— Presentation transcript:

1 1 Nearest Common Ancestors (NCA) Discrete Range Maximum 1234567891011 4716 6213583 4 7 1 6 11 6 8 2 35 Cartesian Tree [Vuillemin 1980] i j max(i, j) i j nca(i, j) 1 2 11 13 Preprocessing Time vs Query Time ? Org. [D. Harel, R.E. Tarjan, Fast algorithms for finding nearest common ancestors, SIAM J. on Comp. 13 (2): 338–355, 1984]

2  Incremental construction left-to-right  O(n) time (Φ = #nodes on rightmost path) 2 Cartesian Tree Construction 18∙∙∙13∙∙∙8 210 18 8 13 2 10 + 18 8 13 2 START HERE

3 A B C D E F J G KI 3 Reduction: NCA   1 Discrete Range Maximum Euler Tour HEBABDCDBEFGFEHJIJKJH 123434543234321232321 node depth i j nca(i, j) E G C j i 2 minimum depth nca(i, j) H

4 4 NCA on Perfect Binary Trees i 2i2i2i+1 1 23 45 10 11 20212223 = nca(11,21) 11 = 1011 2 21 = 10101 2 nca(21,21) = 5 = 101 2 = lcp( 1011 2, 10101 2 ) longest common prefix proc lcp(x, y) if y < x then swap (x, y) return x >> (msb(x XOR (y >> (msb(y)-msb(x))) position of most significant bit ≠ 0

5 5 Discrete Range Mimimum – Space O(n∙log n) words 2343454322112343 11233234 1 1 1 1 123 1234345432343212 1 33 2 33 3 33 d 32 5 11 j 0 1 i ∙ ∙ ∙ right i left j drm(i, j) = min(right i (d), left j (d)) d = msb(i XOR j) nca(i, j)

6 6 Blocked solution – Space O(n) words 1234345414343232 1212 block of O(log n) elements 01011 54321 j i W j (One for each j) Block query: j+1-msb(W j AND ((1 << (j-i+1))-1)) General query: 1 top query + 2 bottom queries Top structure O(n/log n) elements Space O(n) Query O(1) O(n) Preprocessing Time O(1) Query Time

7 7 Summary... General Discrete Range Searching Cartesian Tree NCA Discrete Range Max on Depth Array ”O(n∙log n)” solution on O(n/log n) blocks O(log n) size blocks 12345678 47168629 i j 4 7 1 6 8 6 2 9 i j nca(i, j) 123434543234321 O(n) Preprocessing Time O(1) Query Time

8 1d & 2D DRM Results better upper or lower bound ? Indexing Model (input accessible) Encoding Model (input not accessable) m = 1 1D 2n+o(n) bits, O(1) time [FH07] n/c bits  Ω(c) time [BDR10] n/c bits, O(c) time [BDR10] ≥ 2n - O(log n) bits 2n+o(n) bits, O(1) time [F10] 1 < m < n1 < m < n O(mn  log n) bits, O(1) time [AY10] O(mn) bits, O(1) time [BDR10] mn/c bits  Ω(c) time [BDR10] O(c  log 2 c) time [BDR10] O(c  log c  (loglog c) 2 ) time [BDLRR12] Ω(mn  log m) bits [BDR10] O(mn  log n) bits, O(1) time [BDR10] O(mn  log m) bits, O(mn) time [BBD13] m = n squared Ω(mn  log n) bits [DLW09] O(mn  log n) bits, O(1) time [AY10]

9 A B C D E F J G KI 9 DRM encoding - O(n) bits Euler Tour HEBABDCDBEFGFEHJIJKJH 123434543234321232321 node depth i j nca(i, j) E G C 2 minimum depth nca(i, j) H 000110110111001011100 ++++-++---++---++-+-- A1A1 B2B2 C3C3 D4D4 E5E5 F6F6 G7G7 H8H8 I9I9 J 10 K 11 4716116213583 Cartesian Tree depth = # + - # - = min-prefix-sum(p i,p j ) j’th ”1” = select(j) 4n bits rank(p) = drm(i,j) = # 1 left of p p select(i) = i’th ”1” pipi pjpj i j

10 10 Succinct data structures for DRM, O(n) bits 000110110111001011100 i’th ”1” = select(i) rank(p) = R 1 [ └ p/α ┘ ] + T rank [B[ └ p/α ┘ ], p mod α] p B0B0 B1B1 B2B2 α = ½  log n bits α+log α bits R 1 [i] = # 1 in first i blocks (n/α  log n bits) T rank = rank inside block, table lookup (2 α+log α  log α bits) B3B3 … select(i) = αb + T select [B[b], i-rank(αb-1)] b = R nonempty [rank leader (i)] i is in block B[b] leader[i] = is the ith ”1” the first ”1” in its block? (n bits) rank leader (i) = rank structure for leader array (O(n) bits) R nonempty = index of nonempty blocks (n/α  log n bits) T select = select inside block, table lookup (2 α+log α  log α bits) 0 1  min-prefix-sum(p i, p j ) = α(b k -1)+d k b 1 = └ p i /α ┘ b 3 = └ p j /α ┘ b 2 = drm PS (b 1 +1, b 3 -1) d 1 = T mps [B[b 1 ], p i mod α, α-1] d 2 = T mps [B[b 2 ], 0, α-1] d 3 = T mps [B[b 3 ], 0, p j mod α] k = argmin t=1..3 PS[b t -1]+T ps [B[b t ], d t ] PS[b] = # + - # - for blocks B 0..B b (n/α  log n bits) T ps = # + - # - for block prefix, table lookup (2 α+log α  (1+log α) bits) T mps = index of minimum prefix sum # + - # - inside range in a block, table lookup (2 α+2log α  log α bits) MPS[b] = PS[b-1]+ T mps [B[b], 0, α-1] (n/α  log n bits) drm MPS = drmin structure for MPS, O(n/α) words (O(n) bits) ++++-++---++---++-+-- 132121 Bb1Bb1 Bb3Bb3 Bb2Bb2 b2b2 pipi pjpj b1b1 b3b3 d 1 =3 d 2 =2 d 3 =1 MPS


Download ppt "1 Nearest Common Ancestors (NCA) Discrete Range Maximum 1234567891011 4716 6213583 4 7 1 6 11 6 8 2 35 Cartesian Tree [Vuillemin 1980] i j max(i, j) i."

Similar presentations


Ads by Google