• Non ci sono risultati.

Range Maximum Queries

N/A
N/A
Protected

Academic year: 2021

Condividi "Range Maximum Queries"

Copied!
161
0
0

Testo completo

(1)

Range Maximum Queries

Auto-completion as our target application

Rossano Venturini

(2)
(3)
(4)
(5)
(6)
(7)
(8)

Dataset?

(9)

Dataset? All the past queries

(10)

Dataset?

Searches?

All the past queries

(11)

Dataset?

Prefix search Searches?

All the past queries

(12)

Dataset?

Prefix search Searches?

All the past queries

Data structure?

(13)

Dataset?

Prefix search Searches?

All the past queries

Data structure? Trie

(14)

Dataset?

Prefix search Searches?

All the past queries

Data structure? Trie

How to find top-k efficiently?

(15)

Trie

(16)

D = { ab (7), bab (2), bca (1), cab (4), cac (1), cbac (6), cbba (2) }

Trie

(17)

D = { ab (7), bab (2), bca (1), cab (4), cac (1), cbac (6), cbba (2) } n = |D|, m total length of strings in D

Trie

(18)

D = { ab (7), bab (2), bca (1), cab (4), cac (1), cbac (6), cbba (2) } n = |D|, m total length of strings in D

7

2 1

4 1 6 2

ab b

ab ca

c

a b

ba ac

b c

Trie

(19)

D = { ab (7), bab (2), bca (1), cab (4), cac (1), cbac (6), cbba (2) } n = |D|, m total length of strings in D

7

2 1

4 1 6 2

ab b

ab ca

c

a b

ba ac

b c

Trie

O(n) nodes

O(n log n + m log σ) bits of space

(20)

D = { ab (7), bab (2), bca (1), cab (4), cac (1), cbac (6), cbba (2) } n = |D|, m total length of strings in D

7

2 1

4 1 6 2

ab b

ab ca

c

a b

ba ac

b c

Trie

O(n) nodes

O(n log n + m log σ) bits of space Find all the strings prefixed by

any pattern P in O(|P|) time

(21)

D = { ab (7), bab (2), bca (1), cab (4), cac (1), cbac (6), cbba (2) } n = |D|, m total length of strings in D

7

2 1

4 1 6 2

ab b

ab ca

c

a b

ba ac

b c

P = c

Trie

O(n) nodes

O(n log n + m log σ) bits of space Find all the strings prefixed by

any pattern P in O(|P|) time

(22)

D = { ab (7), bab (2), bca (1), cab (4), cac (1), cbac (6), cbba (2) } n = |D|, m total length of strings in D

7

2 1

4 1 6 2

ab b

ab ca

c

a b

ba ac

b c

P = c

Trie

O(n) nodes

O(n log n + m log σ) bits of space Find all the strings prefixed by

any pattern P in O(|P|) time

(23)

D = { ab (7), bab (2), bca (1), cab (4), cac (1), cbac (6), cbba (2) } N = |D|, n = total length of strings in D, σ = alphabet size

7

2 1

4 1 6 2

ab b

ab ca

c

a b

ba ac

b c

P = c

Finding Top-1

(24)

D = { ab (7), bab (2), bca (1), cab (4), cac (1), cbac (6), cbba (2) } N = |D|, n = total length of strings in D, σ = alphabet size

7

2 1

4 1 6 2

ab b

ab ca

c

a b

ba ac

b c

P = c

Finding Top-1

Score

(25)

D = { ab (7), bab (2), bca (1), cab (4), cac (1), cbac (6), cbba (2) } N = |D|, n = total length of strings in D, σ = alphabet size

7

2 1

4 1 6 2

ab b

ab ca

c

a b

ba ac

b c

P = c

How to find Top-1?

Finding Top-1

(26)

D = { ab (7), bab (2), bca (1), cab (4), cac (1), cbac (6), cbba (2) } N = |D|, n = total length of strings in D, σ = alphabet size

7

2 1

4 1 6 2

ab b

ab ca

c

a b

ba ac

b c

P = c

How to find Top-1?

Finding Top-1

(27)

D = { ab (7), bab (2), bca (1), cab (4), cac (1), cbac (6), cbba (2) } N = |D|, n = total length of strings in D, σ = alphabet size

7

2 1

4 1 6 2

ab b

ab ca

c

a b

ba ac

b c

P = c

How to find Top-1?

Scan to find the maximum!

Finding Top-1

(28)

D = { ab (7), bab (2), bca (1), cab (4), cac (1), cbac (6), cbba (2) } N = |D|, n = total length of strings in D, σ = alphabet size

7

2 1

4 1 6 2

ab b

ab ca

c

a b

ba ac

b c

P = c

How to find Top-1?

Scan to find the maximum!

Finding Top-1

(29)

D = { ab (7), bab (2), bca (1), cab (4), cac (1), cbac (6), cbba (2) } N = |D|, n = total length of strings in D, σ = alphabet size

7

2 1

4 1 6 2

ab b

ab ca

c

a b

ba ac

b c

P = c

How to find Top-1?

Scan to find the maximum!

Finding Top-1

(30)

D = { ab (7), bab (2), bca (1), cab (4), cac (1), cbac (6), cbba (2) } N = |D|, n = total length of strings in D, σ = alphabet size

7

2 1

4 1 6 2

ab b

ab ca

c

a b

ba ac

b c

P = c

How to find Top-1?

Scan to find the maximum!

O(N) query time :-(

Finding Top-1

(31)

D = { ab (7), bab (2), bca (1), cab (4), cac (1), cbac (6), cbba (2) } N = |D|, n = total length of strings in D, σ = alphabet size

7

2 1

4 1 6 2

ab b

ab ca

c

a b

ba ac

b c

P = c

How to find Top-1?

Scan to find the maximum!

O(N) query time :-(

Finding Top-1

Better ideas?

(32)

D = { ab (7), bab (2), bca (1), cab (4), cac (1), cbac (6), cbba (2) } N = |D|, n = total length of strings in D, σ = alphabet size

7

2 1

4 1 6 2

ab b

ab ca

c

a b

ba ac

b c

P = c

How to find Top-1?

Finding Top-1

(33)

D = { ab (7), bab (2), bca (1), cab (4), cac (1), cbac (6), cbba (2) } N = |D|, n = total length of strings in D, σ = alphabet size

7

2 1

4 1 6 2

ab b

ab ca

c

a b

ba ac

b c

P = c

How to find Top-1?

Augment each node with the max (and string id )

within its subtree!

Finding Top-1

(34)

D = { ab (7), bab (2), bca (1), cab (4), cac (1), cbac (6), cbba (2) } N = |D|, n = total length of strings in D, σ = alphabet size

7

2 1

4 1 6 2

ab b

ab ca

c

a b

ba ac

b c

P = c

How to find Top-1?

Augment each node with the max (and string id )

within its subtree!

4,3

Finding Top-1

(35)

D = { ab (7), bab (2), bca (1), cab (4), cac (1), cbac (6), cbba (2) } N = |D|, n = total length of strings in D, σ = alphabet size

7

2 1

4 1 6 2

ab b

ab ca

c

a b

ba ac

b c

P = c

How to find Top-1?

Augment each node with the max (and string id )

within its subtree!

4,3 6,5

Finding Top-1

(36)

D = { ab (7), bab (2), bca (1), cab (4), cac (1), cbac (6), cbba (2) } N = |D|, n = total length of strings in D, σ = alphabet size

7

2 1

4 1 6 2

ab b

ab ca

c

a b

ba ac

b c

P = c

How to find Top-1?

Augment each node with the max (and string id )

within its subtree!

4,3 6,5

6,5

Finding Top-1

(37)

D = { ab (7), bab (2), bca (1), cab (4), cac (1), cbac (6), cbba (2) } N = |D|, n = total length of strings in D, σ = alphabet size

7

2 1

4 1 6 2

ab b

ab ca

c

a b

ba ac

b c

P = c

How to find Top-1?

Augment each node with the max (and string id )

within its subtree!

4,3 6,5

6,5 2,1

Finding Top-1

(38)

D = { ab (7), bab (2), bca (1), cab (4), cac (1), cbac (6), cbba (2) } N = |D|, n = total length of strings in D, σ = alphabet size

7

2 1

4 1 6 2

ab b

ab ca

c

a b

ba ac

b c

P = c

How to find Top-1?

Augment each node with the max (and string id )

within its subtree!

4,3 6,5

6,5 2,1

7,0

Finding Top-1

(39)

D = { ab (7), bab (2), bca (1), cab (4), cac (1), cbac (6), cbba (2) } N = |D|, n = total length of strings in D, σ = alphabet size

7

2 1

4 1 6 2

ab b

ab ca

c

a b

ba ac

b c

P = c

How to find Top-1?

Augment each node with the max (and string id )

within its subtree!

4,3 6,5

6,5 2,1

7,0

Preprocessing time: O(N) Extra space: O(N log N) bits Query time: O(1)

Finding Top-1

(40)

D = { ab (7), bab (2), bca (1), cab (4), cac (1), cbac (6), cbba (2) } N = |D|, n = total length of strings in D, σ = alphabet size

7

2 1

4 1 6 2

ab b

ab ca

c

a b

ba ac

b c

P = c

How to find Top-1?

Augment each node with the max (and string id )

within its subtree!

4,3 6,5

6,5 2,1

7,0

Preprocessing time: O(N) Extra space: O(N log N) bits Query time: O(1)

Solving Top-k?

Finding Top-1

(41)

D = { ab (7), bab (2), bca (1), cab (4), cac (1), cbac (6), cbba (2) } N = |D|, n = total length of strings in D, σ = alphabet size

7

2 1

4 1 6 2

ab b

ab ca

c

a b

ba ac

b c

P = c

How to find Top-1?

Augment each node with the max (and string id )

within its subtree!

4,3 6,5

6,5 2,1

7,0

Preprocessing time: O(N) Extra space: O(N log N) bits Query time: O(1)

Solving Top-k?

Finding Top-1

Solving Top-k?

- Extra space: O(k*N*log N) bits :-(

- You must know k at building time! :-(

(42)

7

2 1

4 1 6 2

ab b

ab ca

c

a b

ba ac

b c

P = c

How to find Top-1?

Finding Top-1

D = { ab (7), bab (2), bca (1), cab (4), cac (1), cbac (6), cbba (2) }

N = |D|, n = total length of strings in D, σ = alphabet size

(43)

7

2 1

4 1 6 2

ab b

ab ca

c

a b

ba ac

b c

P = c

How to find Top-1?

7 2 1 4 1 6 2

S

Finding Top-1

D = { ab (7), bab (2), bca (1), cab (4), cac (1), cbac (6), cbba (2) }

N = |D|, n = total length of strings in D, σ = alphabet size

(44)

7

2 1

4 1 6 2

ab b

ab ca

c

a b

ba ac

b c

P = c

How to find Top-1?

Assume you have a Data Structure on top of S answering in O(1) by using O(N) bits RMQ(i,j) = position of the maximum in the

range S[i,j]

S

7 2 1 4 1 6 2

Finding Top-1

D = { ab (7), bab (2), bca (1), cab (4), cac (1), cbac (6), cbba (2) }

N = |D|, n = total length of strings in D, σ = alphabet size

(45)

7

2 1

4 1 6 2

ab b

ab ca

c

a b

ba ac

b c

P = c

How to find Top-1?

Assume you have a Data Structure on top of S answering in O(1) by using O(N) bits RMQ(i,j) = position of the maximum in the

range S[i,j]

S

7 2 1 4 1 6 2

Finding Top-1

D = { ab (7), bab (2), bca (1), cab (4), cac (1), cbac (6), cbba (2) }

N = |D|, n = total length of strings in D, σ = alphabet size

(46)

7

2 1

4 1 6 2

ab b

ab ca

c

a b

ba ac

b c

P = c

How to find Top-1?

Assume you have a Data Structure on top of S answering in O(1) by using O(N) bits RMQ(i,j) = position of the maximum in the

range S[i,j]

S

7 2 1 4 1 6 2

RMQ(3,6) = 5

Finding Top-1

D = { ab (7), bab (2), bca (1), cab (4), cac (1), cbac (6), cbba (2) }

N = |D|, n = total length of strings in D, σ = alphabet size

(47)

7

2 1

4 1 6 2

ab b

ab ca

c

a b

ba ac

b c

P = c

How to find Top-1?

Assume you have a Data Structure on top of S answering in O(1) by using O(N) bits RMQ(i,j) = position of the maximum in the

range S[i,j]

S

7 2 1 4 1 6 2

RMQ(3,6) = 5 Can you solve Top-2?

Finding Top-1

D = { ab (7), bab (2), bca (1), cab (4), cac (1), cbac (6), cbba (2) }

N = |D|, n = total length of strings in D, σ = alphabet size

(48)

7

2 1

4 1 6 2

ab b

ab ca

c

a b

ba ac

b c

P = c

How to find Top-1?

Assume you have a Data Structure on top of S answering in O(1) by using O(N) bits RMQ(i,j) = position of the maximum in the

range S[i,j] Can you solve Top-2?

S

7 2 1 4 1 6 2

Finding Top-1

D = { ab (7), bab (2), bca (1), cab (4), cac (1), cbac (6), cbba (2) }

N = |D|, n = total length of strings in D, σ = alphabet size

(49)

7

2 1

4 1 6 2

ab b

ab ca

c

a b

ba ac

b c

P = c

How to find Top-1?

Assume you have a Data Structure on top of S answering in O(1) by using O(N) bits RMQ(i,j) = position of the maximum in the

range S[i,j] Can you solve Top-2?

S

7 2 1 4 1 6 2

Finding Top-1

D = { ab (7), bab (2), bca (1), cab (4), cac (1), cbac (6), cbba (2) }

N = |D|, n = total length of strings in D, σ = alphabet size

(50)

Finding Top-k

(51)

Finding Top-k

3 5 1 7 1 6 10

S

9 8 7 1 4 2

(52)

Finding Top-k

3 5 1 7 1 6 10

S

9 8 7 1 4 2

Cartesian Tree

(53)

Finding Top-k

3 5 1 7 1 6 10

S

9 8 7 1 4 2

10

Cartesian Tree

(54)

Finding Top-k

3 5 1 7 1 6 10

S

9 8 7 1 4 2

10

7

Cartesian Tree

(55)

Finding Top-k

3 5 1 7 1 6 10

S

9 8 7 1 4 2

10

7 9

Cartesian Tree

(56)

Finding Top-k

3 5 1 7 1 6 10

S

9 8 7 1 4 2

10

7 9

5

3

6

1

Cartesian Tree

1

(57)

Finding Top-k

3 5 1 7 1 6 10

S

9 8 7 1 4 2

10

7 9

8 5

3

6

1 7

4

1 2

Cartesian Tree

It can be built top-down with RMQ

1

(58)

Finding Top-k

3 5 1 7 1 6 10

S

9 8 7 1 4 2

10

7 9

8 5

3

6

1 7

4

1 2

Cartesian Tree

How to find Top-k?

1

(59)

Finding Top-k

3 5 1 7 1 6 10

S

9 8 7 1 4 2

10

7 9

8 5

3

6

1 7

4

1 2

Cartesian Tree

How to find Top-k?

Visit the node starting from the root and insert each visited node in a max- Heap storing at most k elements.

Extract (and report) the maximum from the heap and visit its children.

1

(60)

Finding Top-k

3 5 1 7 1 6 10

S

9 8 7 1 4 2

10

7 9

8 5

3

6

1 7

4

1 2

Cartesian Tree

How to find Top-k?

Visit the node starting from the root and insert each visited node in a max- Heap storing at most k elements.

Extract (and report) the maximum from the heap and visit its children.

max-Heap k=4

1

(61)

Finding Top-k

3 5 1 7 1 6 10

S

9 8 7 1 4 2

10

7 9

8 5

3

6

1 7

4

1 2

Cartesian Tree

How to find Top-k?

Visit the node starting from the root and insert each visited node in a max- Heap storing at most k elements.

Extract (and report) the maximum from the heap and visit its children.

max-Heap k=4

Results 1

(62)

Finding Top-k

3 5 1 7 1 6 10

S

9 8 7 1 4 2

10

7 9

8 5

3

6

1 7

4

1 2

Cartesian Tree

How to find Top-k?

Visit the node starting from the root and insert each visited node in a max- Heap storing at most k elements.

Extract (and report) the maximum from the heap and visit its children.

max-Heap k=4

Results 1

(63)

Finding Top-k

3 5 1 7 1 6 10

S

9 8 7 1 4 2

10

7 9

8 5

3

6

1 7

4

1 2

Cartesian Tree

How to find Top-k?

Visit the node starting from the root and insert each visited node in a max- Heap storing at most k elements.

Extract (and report) the maximum from the heap and visit its children.

max-Heap k=4

10

Results 1

(64)

Finding Top-k

3 5 1 7 1 6 10

S

9 8 7 1 4 2

10

7 9

8 5

3

6

1 7

4

1 2

Cartesian Tree

How to find Top-k?

Visit the node starting from the root and insert each visited node in a max- Heap storing at most k elements.

Extract (and report) the maximum from the heap and visit its children.

max-Heap k=4

Results 1

(65)

Finding Top-k

3 5 1 7 1 6 10

S

9 8 7 1 4 2

10

7 9

8 5

3

6

1 7

4

1 2

Cartesian Tree

How to find Top-k?

Visit the node starting from the root and insert each visited node in a max- Heap storing at most k elements.

Extract (and report) the maximum from the heap and visit its children.

max-Heap k=4

Results

10

1

(66)

Finding Top-k

3 5 1 7 1 6 10

S

9 8 7 1 4 2

10

7 9

8 5

3

6

1 7

4

1 2

Cartesian Tree

How to find Top-k?

Visit the node starting from the root and insert each visited node in a max- Heap storing at most k elements.

Extract (and report) the maximum from the heap and visit its children.

max-Heap k=4

Results

10

1

(67)

Finding Top-k

3 5 1 7 1 6 10

S

9 8 7 1 4 2

10

7 9

8 5

3

6

1 7

4

1 2

Cartesian Tree

How to find Top-k?

Visit the node starting from the root and insert each visited node in a max- Heap storing at most k elements.

Extract (and report) the maximum from the heap and visit its children.

max-Heap k=4

9 7

Results

10

1

(68)

Finding Top-k

3 5 1 7 1 6 10

S

9 8 7 1 4 2

10

7 9

8 5

3

6

1 7

4

1 2

Cartesian Tree

How to find Top-k?

Visit the node starting from the root and insert each visited node in a max- Heap storing at most k elements.

Extract (and report) the maximum from the heap and visit its children.

max-Heap k=4

9 7

Results

10 7

1

(69)

Finding Top-k

3 5 1 7 1 6 10

S

9 8 7 1 4 2

10

7 9

8 5

3

6

1 7

4

1 2

Cartesian Tree

How to find Top-k?

Visit the node starting from the root and insert each visited node in a max- Heap storing at most k elements.

Extract (and report) the maximum from the heap and visit its children.

max-Heap k=4

9 7

Results

10 7

9

1

(70)

Finding Top-k

3 5 1 7 1 6 10

S

9 8 7 1 4 2

10

7 9

8 5

3

6

1 7

4

1 2

Cartesian Tree

How to find Top-k?

Visit the node starting from the root and insert each visited node in a max- Heap storing at most k elements.

Extract (and report) the maximum from the heap and visit its children.

max-Heap k=4

9 7

Results

10 7

9 8

7

1

(71)

Finding Top-k

3 5 1 7 1 6 10

S

9 8 7 1 4 2

10

7 9

8 5

3

6

1 7

4

1 2

Cartesian Tree

How to find Top-k?

Visit the node starting from the root and insert each visited node in a max- Heap storing at most k elements.

Extract (and report) the maximum from the heap and visit its children.

max-Heap k=4

9 7

Results

10 7

9 8

7 7

1

(72)

Finding Top-k

3 5 1 7 1 6 10

S

9 8 7 1 4 2

10

7 9

8 5

3

6

1 7

4

1 2

Cartesian Tree

How to find Top-k?

Visit the node starting from the root and insert each visited node in a max- Heap storing at most k elements.

Extract (and report) the maximum from the heap and visit its children.

max-Heap k=4

9 7

Results

10 7

9 8

7

8 7

1

(73)

Finding Top-k

3 5 1 7 1 6 10

S

9 8 7 1 4 2

10

7 9

8 5

3

6

1 7

4

1 2

Cartesian Tree

How to find Top-k?

Visit the node starting from the root and insert each visited node in a max- Heap storing at most k elements.

Extract (and report) the maximum from the heap and visit its children.

max-Heap k=4

9 7

Results

10 7

9 8

7

8 77

7

1

(74)

Finding Top-k

3 5 1 7 1 6 10

S

9 8 7 1 4 2

10

7 9

8 5

3

6

1 7

4

1 2

Cartesian Tree

How to find Top-k?

Visit the node starting from the root and insert each visited node in a max- Heap storing at most k elements.

Extract (and report) the maximum from the heap and visit its children.

max-Heap k=4

9 7

Results

10 7

9 8

7

8 77

7 7

7

1

(75)

Finding Top-k

3 5 1 7 1 6 10

S

9 8 7 1 4 2

10

7 9

8 5

3

6

1 7

4

1 2

Cartesian Tree

How to find Top-k?

Visit the node starting from the root and insert each visited node in a max- Heap storing at most k elements.

Extract (and report) the maximum from the heap and visit its children.

max-Heap k=4

9 7

Results

10 7

9 8

7

8 77

7 7

7

Claim: we “touch” at most 2k nodes.

Query time O(k log k) 1

(76)

Finding Top-k

3 5 1 7 1 6 10

S

9 8 7 1 4 2

10

7 9

8 5

3

6

1 7

4

1 2

Cartesian Tree

How to find Top-k?

Visit the node starting from the root and insert each visited node in a max- Heap storing at most k elements.

Extract (and report) the maximum from the heap and visit its children.

max-Heap k=4

9 7

Results

10 7

9 8

7

8 77

7 7

7

Claim: we “touch” at most 2k nodes.

Query time O(k log k)

Important: the cartesian tree is not built.

Use RMQ instead!

1

(77)

Finding Top-k

3 5 1 7 1 6 10

S

9 8 7 1 4 2

10

7 9

8 5

3

6

1 7

4

1 2

Cartesian Tree

How to find Top-k?

Visit the node starting from the root and insert each visited node in a max- Heap storing at most k elements.

Extract (and report) the maximum from the heap and visit its children.

max-Heap k=4

9 7

Results

10 7

9 8

7

8 77

7 7

7

Claim: we “touch” at most 2k nodes.

Query time O(k log k)

Important: the cartesian tree is not built.

Use RMQ instead!

1 Assume you have a Data Structure on top of S answering in O(1) by using O(N) bits RMQ(i,j) = position of the maximum in the range S[i,j]

(78)

Range Maximum Query (1)

3 5 1 7 1 6 10

S

9 8 7 1 4

0 1 2 3 4 5 6 7 8 9 10 11

(79)

Range Maximum Query (1)

3 5 1 7 1 6 10

S

9 8 7 1 4

0 1 2 3 4 5 6 7 8 9 10 11

Space: O(N2 log n) bits Query time: O(1)

(80)

Range Maximum Query (1)

3 5 1 7 1 6 10

S

9 8 7 1 4

0 1 2 3 4 5 6 7 8 9 10 11

Space: O(N2 log n) bits Query time: O(1)

Precompute the answer to any possible query.

There are O(N2) possible queries!

(81)

Range Maximum Query (1)

3 5 1 7 1 6 10

S

9 8 7 1 4

0 1 2 3 4 5 6 7 8 9 10 11

Space: O(N2 log n) bits

Query time: O(1)

M[i,j] = RMQ(i,j)

Precompute the answer to any possible query.

There are O(N2) possible queries!

(82)

Range Maximum Query (1)

3 5 1 7 1 6 10

S

9 8 7 1 4

0 1 2 3 4 5 6 7 8 9 10 11

Space: O(N2 log n) bits Query time: O(1)

M

0 1 2 3 4 5 6 7 8 9 10 11

0 1

5 2 3 4

6 7 8 9 10 11

M[i,j] = RMQ(i,j)

Precompute the answer to any possible query.

There are O(N2) possible queries!

(83)

Range Maximum Query (1)

3 5 1 7 1 6 10

S

9 8 7 1 4

0 1 2 3 4 5 6 7 8 9 10 11

Space: O(N2 log n) bits Query time: O(1)

M

0 1 2 3 4 5 6 7 8 9 10 11

0 1

5 2 3 4

6 7 8 9 10 11

M[i,j] = RMQ(i,j)

Precompute the answer to any possible query.

There are O(N2) possible queries!

3

(84)

Range Maximum Query (2)

3 5 1 7 1 6 10

S

9 8 7 1 4

0 1 2 3 4 5 6 7 8 9 10 11

(85)

Range Maximum Query (2)

3 5 1 7 1 6 10

S

9 8 7 1 4

0 1 2 3 4 5 6 7 8 9 10 11

Space: O(N log2 N) bits Query time: O(1)

(86)

Range Maximum Query (2)

3 5 1 7 1 6 10

S

9 8 7 1 4

0 1 2 3 4 5 6 7 8 9 10 11

Space: O(N log2 N) bits Query time: O(1)

Maximum in a interval is the max between the maxima of any its

subintervals

(87)

Range Maximum Query (2)

3 5 1 7 1 6 10

S

9 8 7 1 4

0 1 2 3 4 5 6 7 8 9 10 11

Space: O(N log2 N) bits Query time: O(1)

Precompute the answer to every

interval whose length is a power of 2.

There are O(log N) possible intervals starting at any position i.

Maximum in a interval is the max between the maxima of any its

subintervals

(88)

Range Maximum Query (2)

3 5 1 7 1 6 10

S

9 8 7 1 4

0 1 2 3 4 5 6 7 8 9 10 11

Space: O(N log2 N) bits

Query time: O(1)

M[i,j] = RMQ(i,i+2

j

)

Precompute the answer to every

interval whose length is a power of 2.

There are O(log N) possible intervals starting at any position i.

M

0 1 2 3 4

0 1

5 2 3 4

6 7 8 9 10 11

Maximum in a interval is the max between the maxima of any its

subintervals

(89)

Range Maximum Query (2)

3 5 1 7 1 6 10

S

9 8 7 1 4

0 1 2 3 4 5 6 7 8 9 10 11

Space: O(N log2 N) bits

Query time: O(1)

M[i,j] = RMQ(i,i+2

j

)

Precompute the answer to every

interval whose length is a power of 2.

There are O(log N) possible intervals starting at any position i.

M

0 1 2 3 4

0 1

5 2 3 4

6 7 8 9 10 11

?

Maximum in a interval is the max between the maxima of any its

subintervals

(90)

Range Maximum Query (2)

3 5 1 7 1 6 10

S

9 8 7 1 4

0 1 2 3 4 5 6 7 8 9 10 11

Space: O(N log2 N) bits

Query time: O(1)

M[i,j] = RMQ(i,i+2

j

)

Precompute the answer to every

interval whose length is a power of 2.

There are O(log N) possible intervals starting at any position i.

M

0 1 2 3 4

0 1

5 2 3 4

6 7 8 9 10 11

?

Maximum in a interval is the max between the maxima of any its

subintervals

9=1+23

(91)

Range Maximum Query (2)

3 5 1 7 1 6 10

S

9 8 7 1 4

0 1 2 3 4 5 6 7 8 9 10 11

Space: O(N log2 N) bits

Query time: O(1)

M[i,j] = RMQ(i,i+2

j

)

Precompute the answer to every

interval whose length is a power of 2.

There are O(log N) possible intervals starting at any position i.

M

0 1 2 3 4

0 1

5 2 3 4

6 7 8 9 10 11

?

Maximum in a interval is the max between the maxima of any its

subintervals

9=1+23

6

(92)

Range Maximum Query (2)

3 5 1 7 1 6 10

S

9 8 7 1 4

0 1 2 3 4 5 6 7 8 9 10 11

Space: O(N log2 N) bits

Query time: O(1)

M[i,j] = RMQ(i,i+2

j

)

Precompute the answer to every

interval whose length is a power of 2.

There are O(log N) possible intervals starting at any position i.

M

0 1 2 3 4

0 1

5 2 3 4

6 7 8 9 10 11

Maximum in a interval is the max between the maxima of any its

subintervals

(93)

Range Maximum Query (2)

3 5 1 7 1 6 10

S

9 8 7 1 4

0 1 2 3 4 5 6 7 8 9 10 11

Space: O(N log2 N) bits

Query time: O(1)

M[i,j] = RMQ(i,i+2

j

)

Precompute the answer to every

interval whose length is a power of 2.

There are O(log N) possible intervals starting at any position i.

M

0 1 2 3 4

0 1

5 2 3 4

6 7 8 9 10 11

Maximum in a interval is the max between the maxima of any its

subintervals

RMQ(1,7) =

(94)

Range Maximum Query (2)

3 5 1 7 1 6 10

S

9 8 7 1 4

0 1 2 3 4 5 6 7 8 9 10 11

Space: O(N log2 N) bits

Query time: O(1)

M[i,j] = RMQ(i,i+2

j

)

Precompute the answer to every

interval whose length is a power of 2.

There are O(log N) possible intervals starting at any position i.

M

0 1 2 3 4

0 1

5 2 3 4

6 7 8 9 10 11

Maximum in a interval is the max between the maxima of any its

subintervals

argmax(S[M[1,1+22]], S[M[7-22,7]]) = 6 RMQ(1,7) =

(95)

Range Maximum Query (2)

3 5 1 7 1 6 10

S

9 8 7 1 4

0 1 2 3 4 5 6 7 8 9 10 11

Space: O(N log2 N) bits

Query time: O(1)

M[i,j] = RMQ(i,i+2

j

)

Precompute the answer to every

interval whose length is a power of 2.

There are O(log N) possible intervals starting at any position i.

M

0 1 2 3 4

0 1

5 2 3 4

6 7 8 9 10 11

Maximum in a interval is the max between the maxima of any its

subintervals

argmax(S[M[1,1+22]], S[M[7-22,7]]) = 6 RMQ(1,7) =

(96)

Range Maximum Query (2)

3 5 1 7 1 6 10

S

9 8 7 1 4

0 1 2 3 4 5 6 7 8 9 10 11

Space: O(N log2 N) bits

Query time: O(1)

M[i,j] = RMQ(i,i+2

j

)

Precompute the answer to every

interval whose length is a power of 2.

There are O(log N) possible intervals starting at any position i.

M

0 1 2 3 4

0 1

5 2 3 4

6 7 8 9 10 11

3

Maximum in a interval is the max between the maxima of any its

subintervals

argmax(S[M[1,1+22]], S[M[7-22,7]]) = 6 RMQ(1,7) =

(97)

Range Maximum Query (2)

3 5 1 7 1 6 10

S

9 8 7 1 4

0 1 2 3 4 5 6 7 8 9 10 11

Space: O(N log2 N) bits

Query time: O(1)

M[i,j] = RMQ(i,i+2

j

)

Precompute the answer to every

interval whose length is a power of 2.

There are O(log N) possible intervals starting at any position i.

M

0 1 2 3 4

0 1

5 2 3 4

6 7 8 9 10 11

3

Maximum in a interval is the max between the maxima of any its

subintervals

argmax(S[M[1,1+22]], S[M[7-22,7]]) = 6 RMQ(1,7) =

(98)

Range Maximum Query (2)

3 5 1 7 1 6 10

S

9 8 7 1 4

0 1 2 3 4 5 6 7 8 9 10 11

Space: O(N log2 N) bits

Query time: O(1)

M[i,j] = RMQ(i,i+2

j

)

Precompute the answer to every

interval whose length is a power of 2.

There are O(log N) possible intervals starting at any position i.

M

0 1 2 3 4

0 1

5 2 3 4

6 7 8 9 10 11

3

Maximum in a interval is the max between the maxima of any its

subintervals

argmax(S[M[1,1+22]], S[M[7-22,7]]) = 6 RMQ(1,7) =

6

(99)

Range Maximum Query (2)

3 5 1 7 1 6 10

S

9 8 7 1 4

0 1 2 3 4 5 6 7 8 9 10 11

Space: O(N log2 N) bits

Query time: O(1)

M[i,j] = RMQ(i,i+2

j

)

Precompute the answer to every

interval whose length is a power of 2.

There are O(log N) possible intervals starting at any position i.

M

0 1 2 3 4

0 1

5 2 3 4

6 7 8 9 10 11

3

Maximum in a interval is the max between the maxima of any its

subintervals

argmax(S[M[1,1+22]], S[M[7-22,7]]) = 6 RMQ(1,7) =

where len = log (j-i+1)

RMQ(i,j) = argmax(S[M[i,i+2len]], S[M[j-2len,j]])

6

(100)

Range Maximum Query (3)

3 5 1 7 1 6 10

S

9 8 7 1 4

0 1 2 3 4 5 6 7 8 9 10 11

(101)

Range Maximum Query (3)

Space: O(N log N) bits Query time: O(log N)

3 5 1 7 1 6 10

S

9 8 7 1 4

0 1 2 3 4 5 6 7 8 9 10 11

(102)

Range Maximum Query (3)

Space: O(N log N) bits Query time: O(log N)

3 5 1 7 1 6 10

S

9 8 7 1 4

0 1 2 3 4 5 6 7 8 9 10 11

log N

(103)

Range Maximum Query (3)

Space: O(N log N) bits Query time: O(log N)

3 5 1 7 1 6 10

S

9 8 7 1 4

0 1 2 3 4 5 6 7 8 9 10 11

log N

(104)

Range Maximum Query (3)

Space: O(N log N) bits Query time: O(log N)

3 5 1 7 1 6 10

S

9 8 7 1 4

0 1 2 3 4 5 6 7 8 9 10 11

log N

R

(105)

Range Maximum Query (3)

Space: O(N log N) bits Query time: O(log N)

3 5 1 7 1 6 10

S

9 8 7 1 4

0 1 2 3 4 5 6 7 8 9 10 11

log N

R

5

(106)

Range Maximum Query (3)

Space: O(N log N) bits Query time: O(log N)

3 5 1 7 1 6 10

S

9 8 7 1 4

0 1 2 3 4 5 6 7 8 9 10 11

log N

R

5 7 10 7

(107)

Range Maximum Query (3)

Space: O(N log N) bits Query time: O(log N)

3 5 1 7 1 6 10

S

9 8 7 1 4

0 1 2 3 4 5 6 7 8 9 10 11

log N

R

5 7 10 7

Use the previous solution on R!

Space: ? bits Query time: O(1)

(108)

Range Maximum Query (3)

Space: O(N log N) bits Query time: O(log N)

3 5 1 7 1 6 10

S

9 8 7 1 4

0 1 2 3 4 5 6 7 8 9 10 11

log N

R

5 7 10 7

Use the previous solution on R!

Space: ? bits Query time: O(1)

Space: O(N log N) bits Query time: O(1)

(109)

Range Maximum Query (3)

Space: O(N log N) bits Query time: O(log N)

3 5 1 7 1 6 10

S

9 8 7 1 4

0 1 2 3 4 5 6 7 8 9 10 11

log N

R

5 7 10 7

Use the previous solution on R!

Space: ? bits Query time: O(1)

Space: O(N log N) bits Query time: O(1)

RMQ(1,10) = ?

(110)

Range Maximum Query (3)

Space: O(N log N) bits Query time: O(log N)

3 5 1 7 1 6 10

S

9 8 7 1 4

0 1 2 3 4 5 6 7 8 9 10 11

log N

R

5 7 10 7

Use the previous solution on R!

Space: ? bits Query time: O(1)

Space: O(N log N) bits Query time: O(1)

RMQ(1,10) = ?

(111)

Range Maximum Query (3)

Space: O(N log N) bits Query time: O(log N)

3 5 1 7 1 6 10

S

9 8 7 1 4

0 1 2 3 4 5 6 7 8 9 10 11

log N

R

5 7 10 7

Use the previous solution on R!

Space: ? bits Query time: O(1)

Space: O(N log N) bits Query time: O(1)

RMQ(1,10) = ?

(112)

Range Maximum Query (3)

Space: O(N log N) bits Query time: O(log N)

3 5 1 7 1 6 10

S

9 8 7 1 4

0 1 2 3 4 5 6 7 8 9 10 11

log N

R

5 7 10 7

Use the previous solution on R!

Space: ? bits Query time: O(1)

Space: O(N log N) bits Query time: O(1)

RMQ(1,10) = ?

(113)

Range Maximum Query (3)

Space: O(N log N) bits Query time: O(log N)

3 5 1 7 1 6 10

S

9 8 7 1 4

0 1 2 3 4 5 6 7 8 9 10 11

log N

R

5 7 10 7

Use the previous solution on R!

Space: ? bits Query time: O(1)

Space: O(N log N) bits Query time: O(1)

RMQ(1,10) = ?

O(1) time

(114)

Range Maximum Query (3)

Space: O(N log N) bits Query time: O(log N)

3 5 1 7 1 6 10

S

9 8 7 1 4

0 1 2 3 4 5 6 7 8 9 10 11

log N

R

5 7 10 7

Use the previous solution on R!

Space: ? bits Query time: O(1)

Space: O(N log N) bits Query time: O(1)

RMQ(1,10) = ?

O(1) time

O(log n) time O(log n) time

(115)

Range Maximum Query (3)

Space: O(N log N) bits Query time: O(log N)

3 5 1 7 1 6 10

S

9 8 7 1 4

0 1 2 3 4 5 6 7 8 9 10 11

log N

R

5 7 10 7

Use the previous solution on R!

Space: ? bits Query time: O(1)

Space: O(N log N) bits Query time: O(1)

RMQ(1,10) = ?

O(1) time

O(log n) time O(log n) time

Space: O(N log N) bits Query time: O(1)

(116)

Range Maximum Query (3)

Space: O(N log N) bits Query time: O(log N)

3 5 1 7 1 6 10

S

9 8 7 1 4

0 1 2 3 4 5 6 7 8 9 10 11

log N

R

5 7 10 7

Use the previous solution on R!

Space: ? bits Query time: O(1)

Space: O(N log N) bits Query time: O(1)

RMQ(1,10) = ?

O(1) time

O(log n) time O(log n) time

Space: O(N log N) bits Query time: O(1)

O(1) time O(1) time

(117)

Range Maximum Query (4)

3 5 1 7 1 6 10

S

9 8 7 1 4

0 1 2 3 4 5 6 7 8 9 10 11

(118)

Range Maximum Query (4)

Space: 4N + o(N) bits Query time: O(1)

3 5 1 7 1 6 10

S

9 8 7 1 4

0 1 2 3 4 5 6 7 8 9 10 11

(119)

Range Maximum Query (4)

Space: 4N + o(N) bits Query time: O(1)

3 5 1 7 1 6 10

S

9 8 7 1 4

0 1 2 3 4 5 6 7 8 9 10 11

Cartesian Tree

10

7 9

8 5

3

6

1 7

4

1 1

(120)

Range Maximum Query (4)

Space: 4N + o(N) bits Query time: O(1)

3 5 1 7 1 6 10

S

9 8 7 1 4

0 1 2 3 4 5 6 7 8 9 10 11

Cartesian Tree

10

7 9

8 5

3

6

1 7

4

1 1

0

1

2

3

4

5

6

7

8

9

10

11

Riferimenti

Documenti correlati

To answer a relaxed instance query is to compute for a given concept C, a CSM ∼ and a degree t between 0 and 1, a set of concepts such that each of these concepts is similar to C by

Esta modalidad acogedora de aquello que ocurre es la modalidad que la hermenéutica filosófica contrapone al dominio metódico; es aquella que, en el fondo, Heidegger ha llamado

Finally, concerning forest short-term temporal decorrelation [7,11,14,16], in this work first results are presented of an innovative short-term decorrelation profiling

Since the computational server cannot selectively omit tuples from the join result (i.e., it cannot recognize.. Probability of the omission of o tuples to go undetected when

More precisely, CC seeks a clustering minimizing the number of errors, where an error is given by any pair of elements having similarity −1 and belonging to the same cluster, or

Find the names of the suppliers that supply at least one product supplied by suppliers of red products. D B

Find the codes and the names of the pilots who are qualified to fly on an aircraft that can cover distances greater than 5,000 km (MaximumRange>=5,000). AIRCRAFT (AId,

Find the codes of the sailors who have never booked a red boat SAILOR (SId, SName, Expertise, DateofBirth). BOOKING (SId, BId, Date) BOAT(Bid,