Space Efficient Rang ge Minimum Queries

advertisement
Pooya Davoodi
Aarhus University
Space Efficient Rang
ge Minimum Queries
Introduction
Indexing Lower Bound (1D and 2D) (1)
Problem
Preprocessing an input array such that the given query asking for the position of the
minimum element in a rectangular range within the array is solved efficiently.
efficiently
Succinct Models
ƒ Indexing:
I d i
Probes
P b into
i t the
th input.
i
t
ƒ Encoding:
E
di
No
N access to
t the
th input.
i
t
10
65
7
17
4
14
28
48
13
6
9
19
9
11
16
2
12
30
52
23
IIn 2D version,
i
th input
the
i
t array
h N=m×n
has
N
elements
l
t ((m≤n))
Minimum
Applications
A
li ti
D t b
Databases,
geographic
hi iinformation
f
ti systems,
t
graphics,
hi
computing
ti lowest
l
t common
ancestors iin trees, pattern matching,
hi
d
document retrieval
i
l queries,
i
maximum
i
segment
queries and more.
One Dimensional Data Structure
ƒ A Cartesian Tree encodes the input 1D array of size n elements in 4n+o(n) bits s.t.
st
the query can be solved without accessing the input in O(1) time (Sadakane’07)
(Sadakane 07).
A:
3
1
2
7
20 2
4
5
6
7
10 8
5
16 6
D:
8
3
LCA
1
6
2
q = [4
[ · · · 7]]
5
4
Theorem
Any
y RMQ algorithm
g
using
g n / c bits additional space,
p
requires Ω(c ) probes into th
he input.
input
Proof
ƒ Consider
C
id n/c
/ queries
i for
f cn/c different
diff
t {0
{0,1}
1} iinputs
t with
ith exactly
tl
one zero iin each
h bl
block.
k
1
2
11101111111 11111111011
q1
q2
n/c
The path (1
(1,0,1,...,1)
0 1 1) ending at the leaf j
shows that the answer of the query over
the input matching with the probes of
the path is j.
j
i1
1
0
0
i2
1
0
ƒ Combine queries to a decision tree.
tree
ƒ Prune
P
non-reachable
h bl branches
b
h ffor the
th
i
inputs
t sharing
h i the
th data
d t structure.
t t
ƒ # zeroes on any path
th ≤ n/c.
/
0
i3
1
1
01111111111
qn/c
/ / 2n/c
/ inputs
ƒ cn/c
i
t share
h
som
me data
d t structure.
t t
ƒ Fix
Fi the
h data
d
structure.
ƒ Every query is a decision tree off height ≤ d.
ip
ƒ
j
ƒ Query
Q
titime d = Ω(c).
Ω( )
Indexing 2D Data S
Structure: Linear Space (2)
ƒ Partition the input into blocks recursively.
recursively
ƒ Construct a binary tree on
n top of the blocks at each level
level.
ƒ Solve the queries spannin
ng over the blocks
blocks.
Indexing 2D Data Structure: Time
Time-space
space Trade
Trade-off
off (3)
ƒ Partition the input into blocks of size 2i x c/2i in log c steps.
steps
ƒ In each step
step, construct an indexing data structure of size O(N/c) bits for
the compressed matrix
matrix.
1
RMQ(A,
RMQ(A [4 · · · 7]) = 6
LCA
8
c
Remaining part of size
O(clog c) is scanned.
scanned
Compress
7
c
c
ƒ Th
The best
b t indexing
i d i and
d encoding
di data
d t structures
t t
have
h
size
i 2n+o(n)
2
( ) bit
bits matching
t hi
th llower bound
the
b
d off 2n-Ɵ(log
2 Ɵ(l n)) bit
bits (Fischer
(Fi h and
d Heun’03,
H
’03 Fischer’07).
Fi h ’07)
ƒ Use
U table
bl lookup
l k in
i the
h las
l st level
l
l where
h
the
h block
bl k size
i is
i O(log
O(l N).
Results
Query time
Space (bits)
Encoding 2D Lower Bound (4)
Preprocessing time
( )
(1)
Ω( )
Ω(c)
O( / ) | |
O(N/c)+|A|
-
((2))
O(1)
( )
O(N)+|A|
( ) | |
O(N)
( )
(3)
O(clog2c)
O(N/c)+|A|
O(N)
(4)
-
Ω(N log
l m))
-
(5)
O(1)
O(N log n)
ƒ Define
D fi a sett off
m
m n
−
( 2 !) 2 4
diff
differentt matrices.
ti
n
2
ƒ Bits required is at least:
llog(( m
2 !)
n
m
2− 4
[1] Brodal, Davoodi, Rao. On Space Efficient Two Dimensional Range Minimum
Data Structures. ESA 2010 / Invited to special
p
issue of Algorithmica.
g
MADALGO – Center for Massive Data Algorithmics,
Algorithmics a Center of the Danish National Research Foundation
m
4
1
3
5
= Θ(N llog m))
O(N)
−
q
m
2
n
2
−
m
4
6
m
2
2
4
π1 a permutation of {2, 4, 6, . . . , m}
Download