van emde boas trees

209
Advanced Algorithms – COMS31900 van Emde Boas trees Benjamin Sach

Upload: benjamin-sach

Post on 13-Apr-2017

68 views

Category:

Education


13 download

TRANSCRIPT

Page 1: van Emde Boas trees

Advanced Algorithms – COMS31900

van Emde Boas trees

Benjamin Sach

Page 2: van Emde Boas trees

Dictionaries

Three operations are supported:

In a dynamic dictionary data structure we store (key, value)-pairs

� add(x, v) Add the the pair (x, v) where x ∈ U , the universe

� lookup(x) Return v if (x, v) is in dictionary, or NULL otherwise.

� delete(x) Remove pair (x, v) (assuming (x, v) is in the dictionary).

In previous lectures we have focussed on solutions using Hashing

such that for any key there is at most one pair (key, value) in the dictionary.

Page 3: van Emde Boas trees

Dictionaries

Three operations are supported:

In a dynamic dictionary data structure we store (key, value)-pairs

� add(x, v) Add the the pair (x, v) where x ∈ U , the universe

� lookup(x) Return v if (x, v) is in dictionary, or NULL otherwise.

� delete(x) Remove pair (x, v) (assuming (x, v) is in the dictionary).

In previous lectures we have focussed on solutions using Hashing

such that for any key there is at most one pair (key, value) in the dictionary.

in particular. . .

Page 4: van Emde Boas trees

Dictionaries

Three operations are supported:

In a dynamic dictionary data structure we store (key, value)-pairs

� add(x, v) Add the the pair (x, v) where x ∈ U , the universe

� lookup(x) Return v if (x, v) is in dictionary, or NULL otherwise.

� delete(x) Remove pair (x, v) (assuming (x, v) is in the dictionary).

In previous lectures we have focussed on solutions using Hashing

such that for any key there is at most one pair (key, value) in the dictionary.

THEOREM

In the Cuckoo hashing scheme:

• Every lookup and every delete takes O(1) worst-case time,

• The space is O(n) where n is the number of keys stored

• An insert takes amortised expected O(1) time

in particular. . .

Page 5: van Emde Boas trees

Dictionaries

Three operations are supported:

In a dynamic dictionary data structure we store (key, value)-pairs

� add(x, v) Add the the pair (x, v) where x ∈ U , the universe

� lookup(x) Return v if (x, v) is in dictionary, or NULL otherwise.

� delete(x) Remove pair (x, v) (assuming (x, v) is in the dictionary).

In previous lectures we have focussed on solutions using Hashing

such that for any key there is at most one pair (key, value) in the dictionary.

What’s not to like?

THEOREM

In the Cuckoo hashing scheme:

• Every lookup and every delete takes O(1) worst-case time,

• The space is O(n) where n is the number of keys stored

• An insert takes amortised expected O(1) time

in particular. . .

Page 6: van Emde Boas trees

Dictionaries

Three operations are supported:

In a dynamic dictionary data structure we store (key, value)-pairs

� add(x, v) Add the the pair (x, v) where x ∈ U , the universe

� lookup(x) Return v if (x, v) is in dictionary, or NULL otherwise.

� delete(x) Remove pair (x, v) (assuming (x, v) is in the dictionary).

In previous lectures we have focussed on solutions using Hashing

such that for any key there is at most one pair (key, value) in the dictionary.

What’s not to like?

THEOREM

In the Cuckoo hashing scheme:

• Every lookup and every delete takes O(1) worst-case time,

• The space is O(n) where n is the number of keys stored

• An insert takes amortised expected O(1) time

in particular. . .

Except the randomness,

Page 7: van Emde Boas trees

Dictionaries

Three operations are supported:

In a dynamic dictionary data structure we store (key, value)-pairs

� add(x, v) Add the the pair (x, v) where x ∈ U , the universe

� lookup(x) Return v if (x, v) is in dictionary, or NULL otherwise.

� delete(x) Remove pair (x, v) (assuming (x, v) is in the dictionary).

In previous lectures we have focussed on solutions using Hashing

such that for any key there is at most one pair (key, value) in the dictionary.

What’s not to like?

THEOREM

In the Cuckoo hashing scheme:

• Every lookup and every delete takes O(1) worst-case time,

• The space is O(n) where n is the number of keys stored

• An insert takes amortised expected O(1) time

in particular. . .

Except the randomness, the amortisation,

Page 8: van Emde Boas trees

Dictionaries

Three operations are supported:

In a dynamic dictionary data structure we store (key, value)-pairs

� add(x, v) Add the the pair (x, v) where x ∈ U , the universe

� lookup(x) Return v if (x, v) is in dictionary, or NULL otherwise.

� delete(x) Remove pair (x, v) (assuming (x, v) is in the dictionary).

In previous lectures we have focussed on solutions using Hashing

such that for any key there is at most one pair (key, value) in the dictionary.

What’s not to like?

THEOREM

In the Cuckoo hashing scheme:

• Every lookup and every delete takes O(1) worst-case time,

• The space is O(n) where n is the number of keys stored

• An insert takes amortised expected O(1) time

in particular. . .

Except the randomness, the amortisation, and the inflexibility

Page 9: van Emde Boas trees

Dictionaries

Three operations are supported:

In a dynamic dictionary data structure we store (key, value)-pairs

� add(x, v) Add the the pair (x, v) where x ∈ U , the universe

� lookup(x) Return v if (x, v) is in dictionary, or NULL otherwise.

� delete(x) Remove pair (x, v) (assuming (x, v) is in the dictionary).

In previous lectures we have focussed on solutions using Hashing

such that for any key there is at most one pair (key, value) in the dictionary.

What’s not to like?

THEOREM

In the Cuckoo hashing scheme:

• Every lookup and every delete takes O(1) worst-case time,

• The space is O(n) where n is the number of keys stored

• An insert takes amortised expected O(1) time

in particular. . .

Except the randomness, the amortisation, and the inflexibility

whatinflexibility?

Page 10: van Emde Boas trees

Supporting more operations

Three operations are supported:

In a dynamic dictionary data structure we store (key, value)-pairs

� add(x, v) Add the the pair (x, v) where x ∈ U - the universe

� lookup(x) Return v if (x, v) is in dictionary, or NULL otherwise.

� delete(x) Remove pair (x, v) (assuming (x, v) is in the dictionary).

such that for any key there is at most one pair (key, value) in the dictionary.

Page 11: van Emde Boas trees

Supporting more operations

Three operations are supported:

In a dynamic dictionary data structure we store (key, value)-pairs

� add(x, v) Add the the pair (x, v) where x ∈ U - the universe

� lookup(x) Return v if (x, v) is in dictionary, or NULL otherwise.

� delete(x) Remove pair (x, v) (assuming (x, v) is in the dictionary).

such that for any key there is at most one pair (key, value) in the dictionary.

What happens if we add more operations?

Page 12: van Emde Boas trees

Supporting more operations

predecessor(k) - returns the (unique) element (x, v) in the dictionarywith the largest key, x such that x 6 k

We also want our data structure to support:

Three operations are supported:

In a dynamic dictionary data structure we store (key, value)-pairs

� add(x, v) Add the the pair (x, v) where x ∈ U - the universe

� lookup(x) Return v if (x, v) is in dictionary, or NULL otherwise.

� delete(x) Remove pair (x, v) (assuming (x, v) is in the dictionary).

such that for any key there is at most one pair (key, value) in the dictionary.

What happens if we add more operations?

Page 13: van Emde Boas trees

Supporting more operations

predecessor(k) - returns the (unique) element (x, v) in the dictionarywith the largest key, x such that x 6 k

We also want our data structure to support:

Three operations are supported:

In a dynamic dictionary data structure we store (key, value)-pairs

� add(x, v) Add the the pair (x, v) where x ∈ U - the universe

� lookup(x) Return v if (x, v) is in dictionary, or NULL otherwise.

� delete(x) Remove pair (x, v) (assuming (x, v) is in the dictionary).

such that for any key there is at most one pair (key, value) in the dictionary.

What happens if we add more operations?

Page 14: van Emde Boas trees

Supporting more operations

predecessor(k) - returns the (unique) element (x, v) in the dictionarywith the largest key, x such that x 6 k

We also want our data structure to support:

Three operations are supported:

In a dynamic dictionary data structure we store (key, value)-pairs

� add(x, v) Add the the pair (x, v) where x ∈ U - the universe

� lookup(x) Return v if (x, v) is in dictionary, or NULL otherwise.

� delete(x) Remove pair (x, v) (assuming (x, v) is in the dictionary).

such that for any key there is at most one pair (key, value) in the dictionary.

What happens if we add more operations?

the universe

Page 15: van Emde Boas trees

Supporting more operations

predecessor(k) - returns the (unique) element (x, v) in the dictionarywith the largest key, x such that x 6 k

We also want our data structure to support:

Three operations are supported:

In a dynamic dictionary data structure we store (key, value)-pairs

� add(x, v) Add the the pair (x, v) where x ∈ U - the universe

� lookup(x) Return v if (x, v) is in dictionary, or NULL otherwise.

� delete(x) Remove pair (x, v) (assuming (x, v) is in the dictionary).

such that for any key there is at most one pair (key, value) in the dictionary.

What happens if we add more operations?

keys in the dictionary

the universe

Page 16: van Emde Boas trees

Supporting more operations

predecessor(k) - returns the (unique) element (x, v) in the dictionarywith the largest key, x such that x 6 k

We also want our data structure to support:

Three operations are supported:

In a dynamic dictionary data structure we store (key, value)-pairs

� add(x, v) Add the the pair (x, v) where x ∈ U - the universe

� lookup(x) Return v if (x, v) is in dictionary, or NULL otherwise.

� delete(x) Remove pair (x, v) (assuming (x, v) is in the dictionary).

such that for any key there is at most one pair (key, value) in the dictionary.

What happens if we add more operations?

Page 17: van Emde Boas trees

Supporting more operations

predecessor(k) - returns the (unique) element (x, v) in the dictionarywith the largest key, x such that x 6 k

We also want our data structure to support:

Three operations are supported:

In a dynamic dictionary data structure we store (key, value)-pairs

� add(x, v) Add the the pair (x, v) where x ∈ U - the universe

� lookup(x) Return v if (x, v) is in dictionary, or NULL otherwise.

� delete(x) Remove pair (x, v) (assuming (x, v) is in the dictionary).

such that for any key there is at most one pair (key, value) in the dictionary.

What happens if we add more operations?

k

Page 18: van Emde Boas trees

Supporting more operations

predecessor(k) - returns the (unique) element (x, v) in the dictionarywith the largest key, x such that x 6 k

We also want our data structure to support:

Three operations are supported:

In a dynamic dictionary data structure we store (key, value)-pairs

� add(x, v) Add the the pair (x, v) where x ∈ U - the universe

� lookup(x) Return v if (x, v) is in dictionary, or NULL otherwise.

� delete(x) Remove pair (x, v) (assuming (x, v) is in the dictionary).

such that for any key there is at most one pair (key, value) in the dictionary.

What happens if we add more operations?

k

predecessor(k)

Page 19: van Emde Boas trees

Supporting more operations

predecessor(k) - returns the (unique) element (x, v) in the dictionarywith the largest key, x such that x 6 k

We also want our data structure to support:

Three operations are supported:

In a dynamic dictionary data structure we store (key, value)-pairs

� add(x, v) Add the the pair (x, v) where x ∈ U - the universe

� lookup(x) Return v if (x, v) is in dictionary, or NULL otherwise.

� delete(x) Remove pair (x, v) (assuming (x, v) is in the dictionary).

such that for any key there is at most one pair (key, value) in the dictionary.

What happens if we add more operations?

successor(k) - returns the (unique) element (x, v) in the dictionarywith the smallest key, x such that x > k

k

predecessor(k)

Page 20: van Emde Boas trees

Supporting more operations

predecessor(k) - returns the (unique) element (x, v) in the dictionarywith the largest key, x such that x 6 k

We also want our data structure to support:

Three operations are supported:

In a dynamic dictionary data structure we store (key, value)-pairs

� add(x, v) Add the the pair (x, v) where x ∈ U - the universe

� lookup(x) Return v if (x, v) is in dictionary, or NULL otherwise.

� delete(x) Remove pair (x, v) (assuming (x, v) is in the dictionary).

such that for any key there is at most one pair (key, value) in the dictionary.

What happens if we add more operations?

successor(k) - returns the (unique) element (x, v) in the dictionarywith the smallest key, x such that x > k

k

successor(k)predecessor(k)

Page 21: van Emde Boas trees

Supporting more operations

predecessor(k) - returns the (unique) element (x, v) in the dictionarywith the largest key, x such that x 6 k

We also want our data structure to support:

Three operations are supported:

In a dynamic dictionary data structure we store (key, value)-pairs

� add(x, v) Add the the pair (x, v) where x ∈ U - the universe

� lookup(x) Return v if (x, v) is in dictionary, or NULL otherwise.

� delete(x) Remove pair (x, v) (assuming (x, v) is in the dictionary).

such that for any key there is at most one pair (key, value) in the dictionary.

What happens if we add more operations?

successor(k) - returns the (unique) element (x, v) in the dictionarywith the smallest key, x such that x > k

Page 22: van Emde Boas trees

Supporting more operations

predecessor(k) - returns the (unique) element (x, v) in the dictionarywith the largest key, x such that x 6 k

We also want our data structure to support:

Three operations are supported:

In a dynamic dictionary data structure we store (key, value)-pairs

� add(x, v) Add the the pair (x, v) where x ∈ U - the universe

� lookup(x) Return v if (x, v) is in dictionary, or NULL otherwise.

� delete(x) Remove pair (x, v) (assuming (x, v) is in the dictionary).

such that for any key there is at most one pair (key, value) in the dictionary.

What happens if we add more operations?

successor(k) - returns the (unique) element (x, v) in the dictionarywith the smallest key, x such that x > k

These are very natural operations that the Hashing-based solutionsthat we have seen are very unsuited to

Page 23: van Emde Boas trees

What could we use instead?

We could use a self-balancing binary search tree. . .like a 2-3-4 tree, a red-black tree or an AVL tree

4

52 58

51 53 5556 9

55 57

4 8

1 2 3 5 6 7 9

Page 24: van Emde Boas trees

What could we use instead?

We could use a self-balancing binary search tree. . .like a 2-3-4 tree, a red-black tree or an AVL tree

All three of these data structures support:

add(x, v),lookup(x), delete(x),predecessor(k) and successor(k)

4

52 58

51 53 5556 9

55 57

4 8

1 2 3 5 6 7 9

Page 25: van Emde Boas trees

What could we use instead?

We could use a self-balancing binary search tree. . .like a 2-3-4 tree, a red-black tree or an AVL tree

All three of these data structures support:

add(x, v),lookup(x), delete(x),predecessor(k) and successor(k)

each in O(logn) worst case time and O(n) space

4

52 58

51 53 5556 9

55 57

4 8

1 2 3 5 6 7 9

Page 26: van Emde Boas trees

What could we use instead?

We could use a self-balancing binary search tree. . .like a 2-3-4 tree, a red-black tree or an AVL tree

All three of these data structures support:

add(x, v),lookup(x), delete(x),predecessor(k) and successor(k)

each in O(logn) worst case time and O(n) space

where n is the number of elements stored

4

52 58

51 53 5556 9

55 57

4 8

1 2 3 5 6 7 9

Page 27: van Emde Boas trees

What could we use instead?

We could use a self-balancing binary search tree. . .like a 2-3-4 tree, a red-black tree or an AVL tree

All three of these data structures support:

add(x, v),lookup(x), delete(x),predecessor(k) and successor(k)

each in O(logn) worst case time and O(n) space

where n is the number of elements storedthey are also deterministic

4

52 58

51 53 5556 9

55 57

4 8

1 2 3 5 6 7 9

Page 28: van Emde Boas trees

van Emde Boas Trees

Five operations will be supported:

In this lecture, we will see the van Emde Boas (vEB) tree

� add(x) Insert the integer x into S (where x ∈ U )

� lookup(x) Return yes if x is in S, or no otherwise.

� delete(x) Remove x from S

which stores a set S of integer keys from a universe U = {1, 2, 3, 4 . . . u} (i.e. u = |U |).

predecessor(k) Return the largest integer x in S such that x 6 k

successor(k) Return the smallest integer x in S such that x > k

k

successor(k)predecessor(k)

1 2 3 4 . . . u

Page 29: van Emde Boas trees

van Emde Boas Trees

Five operations will be supported:

In this lecture, we will see the van Emde Boas (vEB) tree

� add(x) Insert the integer x into S (where x ∈ U )

� lookup(x) Return yes if x is in S, or no otherwise.

� delete(x) Remove x from S

which stores a set S of integer keys from a universe U = {1, 2, 3, 4 . . . u} (i.e. u = |U |).

predecessor(k) Return the largest integer x in S such that x 6 k

successor(k) Return the smallest integer x in S such that x > k

Warning: As stated the operations do not store any data (values) with the integers (keys)

k

successor(k)predecessor(k)

1 2 3 4 . . . u

Page 30: van Emde Boas trees

van Emde Boas Trees

Five operations will be supported:

In this lecture, we will see the van Emde Boas (vEB) tree

� add(x) Insert the integer x into S (where x ∈ U )

� lookup(x) Return yes if x is in S, or no otherwise.

� delete(x) Remove x from S

which stores a set S of integer keys from a universe U = {1, 2, 3, 4 . . . u} (i.e. u = |U |).

predecessor(k) Return the largest integer x in S such that x 6 k

successor(k) Return the smallest integer x in S such that x > k

Warning: As stated the operations do not store any data (values) with the integers (keys)

It is straightforward to extend the van Emde Boas tree to store (key, value) pairswhen the keys are integers from U

k

successor(k)predecessor(k)

1 2 3 4 . . . u

Page 31: van Emde Boas trees

van Emde Boas Trees

Five operations will be supported:

In this lecture, we will see the van Emde Boas (vEB) tree

� add(x) Insert the integer x into S (where x ∈ U )

� lookup(x) Return yes if x is in S, or no otherwise.

� delete(x) Remove x from S

which stores a set S of integer keys from a universe U = {1, 2, 3, 4 . . . u} (i.e. u = |U |).

predecessor(k) Return the largest integer x in S such that x 6 k

successor(k) Return the smallest integer x in S such that x > k

Warning: As stated the operations do not store any data (values) with the integers (keys)

It is straightforward to extend the van Emde Boas tree to store (key, value) pairswhen the keys are integers from U

k

successor(k)predecessor(k)

1 2 3 4 . . . u

(but I think it’s easier to think about like this)

Page 32: van Emde Boas trees

van Emde Boas Trees

Five operations will be supported:

In this lecture, we will see the van Emde Boas (vEB) tree

� add(x) Insert the integer x into S (where x ∈ U )

� lookup(x) Return yes if x is in S, or no otherwise.

� delete(x) Remove x from S

which stores a set S of integer keys from a universe U = {1, 2, 3, 4 . . . u} (i.e. u = |U |).

predecessor(k) Return the largest integer x in S such that x 6 k

successor(k) Return the smallest integer x in S such that x > k

k

successor(k)predecessor(k)

1 2 3 4 . . . u

Page 33: van Emde Boas trees

van Emde Boas Trees

Five operations will be supported:

In this lecture, we will see the van Emde Boas (vEB) tree

� add(x) Insert the integer x into S (where x ∈ U )

� lookup(x) Return yes if x is in S, or no otherwise.

� delete(x) Remove x from S

which stores a set S of integer keys from a universe U = {1, 2, 3, 4 . . . u} (i.e. u = |U |).

predecessor(k) Return the largest integer x in S such that x 6 k

successor(k) Return the smallest integer x in S such that x > k

k

successor(k)predecessor(k)

1 2 3 4 . . . u

All operations will take O(log log u) worst case time

and the space used is O(u)

Page 34: van Emde Boas trees

van Emde Boas Trees

Five operations will be supported:

In this lecture, we will see the van Emde Boas (vEB) tree

� add(x) Insert the integer x into S (where x ∈ U )

� lookup(x) Return yes if x is in S, or no otherwise.

� delete(x) Remove x from S

which stores a set S of integer keys from a universe U = {1, 2, 3, 4 . . . u} (i.e. u = |U |).

predecessor(k) Return the largest integer x in S such that x 6 k

successor(k) Return the smallest integer x in S such that x > k

k

successor(k)predecessor(k)

1 2 3 4 . . . u

All operations will take O(log log u) worst case time

and the space used is O(u)

and it is a deterministic data structure

Page 35: van Emde Boas trees

van Emde Boas Trees

Five operations will be supported:

In this lecture, we will see the van Emde Boas (vEB) tree

� add(x) Insert the integer x into S (where x ∈ U )

� lookup(x) Return yes if x is in S, or no otherwise.

� delete(x) Remove x from S

which stores a set S of integer keys from a universe U = {1, 2, 3, 4 . . . u} (i.e. u = |U |).

predecessor(k) Return the largest integer x in S such that x 6 k

successor(k) Return the smallest integer x in S such that x > k

k

successor(k)predecessor(k)

1 2 3 4 . . . u

All operations will take O(log log u) worst case time

and the space used is O(u)

and it is a deterministic data structure

Example: If U = {1, 2, 3, 4 . . . 100 · n}, you get O(log logn) time and O(n) space

Page 36: van Emde Boas trees

van Emde Boas Trees

Five operations will be supported:

In this lecture, we will see the van Emde Boas (vEB) tree

� add(x) Insert the integer x into S (where x ∈ U )

� lookup(x) Return yes if x is in S, or no otherwise.

� delete(x) Remove x from S

which stores a set S of integer keys from a universe U = {1, 2, 3, 4 . . . u} (i.e. u = |U |).

predecessor(k) Return the largest integer x in S such that x 6 k

successor(k) Return the smallest integer x in S such that x > k

k

successor(k)predecessor(k)

1 2 3 4 . . . u

All operations will take O(log log u) worst case time

and the space used is O(u)

and it is a deterministic data structure

Example: If U = {1, 2, 3, 4 . . . n2}, you get O(log logn) time and O(n2) space

Page 37: van Emde Boas trees

van Emde Boas Trees

Five operations will be supported:

In this lecture, we will see the van Emde Boas (vEB) tree

� add(x) Insert the integer x into S (where x ∈ U )

� lookup(x) Return yes if x is in S, or no otherwise.

� delete(x) Remove x from S

which stores a set S of integer keys from a universe U = {1, 2, 3, 4 . . . u} (i.e. u = |U |).

predecessor(k) Return the largest integer x in S such that x 6 k

successor(k) Return the smallest integer x in S such that x > k

k

successor(k)predecessor(k)

1 2 3 4 . . . u

All operations will take O(log log u) worst case time

and the space used is O(u)

and it is a deterministic data structure

Example: If U = {1, 2, 3, 4 . . . n3}, you get O(log logn) time and O(n3) space

Page 38: van Emde Boas trees

Attempt 1: a big array

161 2 3 4 5 6 7 8 9 10 11 12 13 14 15

00 1 1 1 1 0 1 0 0 0 0 0 0 1 1AA

u

Build an array of length u. . .

Page 39: van Emde Boas trees

Attempt 1: a big array

161 2 3 4 5 6 7 8 9 10 11 12 13 14 15

00 1 1 1 1 0 1 0 0 0 0 0 0 1 1AA

u

Build an array of length u. . .

A[i] = 1 iff i is in S

Page 40: van Emde Boas trees

Attempt 1: a big array

161 2 3 4 5 6 7 8 9 10 11 12 13 14 15

00 1 1 1 1 0 1 0 0 0 0 0 0 1 1AA

u

Build an array of length u. . .

A[i] = 1 iff i is in S

The operations add, delete and lookup all take O(1) time.

Page 41: van Emde Boas trees

Attempt 1: a big array

161 2 3 4 5 6 7 8 9 10 11 12 13 14 15

00 1 1 1 1 0 1 0 0 0 0 0 0 1 1AA

u

Build an array of length u. . .

A[i] = 1 iff i is in S

The operations add, delete and lookup all take O(1) time.

add(12)

Page 42: van Emde Boas trees

Attempt 1: a big array

161 2 3 4 5 6 7 8 9 10 11 12 13 14 15

00 1 1 1 1 0 1 0 0 0 0 0 0 1 1AA

u

Build an array of length u. . .

A[i] = 1 iff i is in S

The operations add, delete and lookup all take O(1) time.

add(12)

Page 43: van Emde Boas trees

Attempt 1: a big array

161 2 3 4 5 6 7 8 9 10 11 12 13 14 15

00 1 1 1 1 0 1 0 0 0 0 0 0 1 1AA

u

Build an array of length u. . .

A[i] = 1 iff i is in S

The operations add, delete and lookup all take O(1) time.

add(12)

1

Page 44: van Emde Boas trees

Attempt 1: a big array

161 2 3 4 5 6 7 8 9 10 11 12 13 14 15

00 1 1 1 1 0 1 0 0 0 0 0 0 1 1AA

u

Build an array of length u. . .

A[i] = 1 iff i is in S

The operations add, delete and lookup all take O(1) time.

1

Page 45: van Emde Boas trees

Attempt 1: a big array

161 2 3 4 5 6 7 8 9 10 11 12 13 14 15

00 1 1 1 1 0 1 0 0 0 0 0 0 1 1AA

u

Build an array of length u. . .

A[i] = 1 iff i is in S

The operations add, delete and lookup all take O(1) time.

1

delete(14)

Page 46: van Emde Boas trees

Attempt 1: a big array

161 2 3 4 5 6 7 8 9 10 11 12 13 14 15

00 1 1 1 1 0 1 0 0 0 0 0 0 1 1AA

u

Build an array of length u. . .

A[i] = 1 iff i is in S

The operations add, delete and lookup all take O(1) time.

1

delete(14)

Page 47: van Emde Boas trees

Attempt 1: a big array

161 2 3 4 5 6 7 8 9 10 11 12 13 14 15

00 1 1 1 1 0 1 0 0 0 0 0 0 1 1AA

u

Build an array of length u. . .

A[i] = 1 iff i is in S

The operations add, delete and lookup all take O(1) time.

1

delete(14)

0

Page 48: van Emde Boas trees

Attempt 1: a big array

161 2 3 4 5 6 7 8 9 10 11 12 13 14 15

00 1 1 1 1 0 1 0 0 0 0 0 0 1 1AA

u

Build an array of length u. . .

A[i] = 1 iff i is in S

The operations add, delete and lookup all take O(1) time.

1 0

Page 49: van Emde Boas trees

Attempt 1: a big array

161 2 3 4 5 6 7 8 9 10 11 12 13 14 15

00 1 1 1 1 0 1 0 0 0 0 0 0 1 1AA

u

Build an array of length u. . .

A[i] = 1 iff i is in S

The operations add, delete and lookup all take O(1) time.

1 0

lookup(11)

Page 50: van Emde Boas trees

Attempt 1: a big array

161 2 3 4 5 6 7 8 9 10 11 12 13 14 15

00 1 1 1 1 0 1 0 0 0 0 0 0 1 1AA

u

Build an array of length u. . .

A[i] = 1 iff i is in S

The operations add, delete and lookup all take O(1) time.

1 0

lookup(11)

Page 51: van Emde Boas trees

Attempt 1: a big array

161 2 3 4 5 6 7 8 9 10 11 12 13 14 15

00 1 1 1 1 0 1 0 0 0 0 0 0 1 1AA

u

Build an array of length u. . .

A[i] = 1 iff i is in S

The operations add, delete and lookup all take O(1) time.

1 0

Page 52: van Emde Boas trees

Attempt 1: a big array

161 2 3 4 5 6 7 8 9 10 11 12 13 14 15

00 1 1 1 1 0 1 0 0 0 0 0 0 1 1AA

u

Build an array of length u. . .

A[i] = 1 iff i is in S

The operations add, delete and lookup all take O(1) time.

1 0

. . . looks good so far!

Page 53: van Emde Boas trees

Attempt 1: a big array

161 2 3 4 5 6 7 8 9 10 11 12 13 14 15

00 1 1 1 1 0 1 0 0 0 0 0 0 1 1AA

u

Build an array of length u. . .

A[i] = 1 iff i is in S

The operations add, delete and lookup all take O(1) time.

1 0

. . . looks good so far!

What about the predecessor operation?

Page 54: van Emde Boas trees

Attempt 1: a big array

161 2 3 4 5 6 7 8 9 10 11 12 13 14 15

00 1 1 1 1 0 1 0 0 0 0 0 0 1 1AA

u

Build an array of length u. . .

A[i] = 1 iff i is in S

The operations add, delete and lookup all take O(1) time.

1 0

. . . looks good so far!

What about the predecessor operation?

predecessor(11)

Page 55: van Emde Boas trees

Attempt 1: a big array

161 2 3 4 5 6 7 8 9 10 11 12 13 14 15

00 1 1 1 1 0 1 0 0 0 0 0 0 1 1AA

u

Build an array of length u. . .

A[i] = 1 iff i is in S

The operations add, delete and lookup all take O(1) time.

1 0

. . . looks good so far!

What about the predecessor operation?

predecessor(11)

Page 56: van Emde Boas trees

Attempt 1: a big array

161 2 3 4 5 6 7 8 9 10 11 12 13 14 15

00 1 1 1 1 0 1 0 0 0 0 0 0 1 1AA

u

Build an array of length u. . .

A[i] = 1 iff i is in S

The operations add, delete and lookup all take O(1) time.

1 0

. . . looks good so far!

What about the predecessor operation?

predecessor(11)

Page 57: van Emde Boas trees

Attempt 1: a big array

161 2 3 4 5 6 7 8 9 10 11 12 13 14 15

00 1 1 1 1 0 1 0 0 0 0 0 0 1 1AA

u

Build an array of length u. . .

A[i] = 1 iff i is in S

The operations add, delete and lookup all take O(1) time.

1 0

. . . looks good so far!

predecessor(11)

Page 58: van Emde Boas trees

Attempt 1: a big array

161 2 3 4 5 6 7 8 9 10 11 12 13 14 15

00 1 1 1 1 0 1 0 0 0 0 0 0 1 1AA

u

Build an array of length u. . .

A[i] = 1 iff i is in S

The operations add, delete and lookup all take O(1) time.

1 0

. . . looks good so far!

predecessor(11)

Page 59: van Emde Boas trees

Attempt 1: a big array

161 2 3 4 5 6 7 8 9 10 11 12 13 14 15

00 1 1 1 1 0 1 0 0 0 0 0 0 1 1AA

u

Build an array of length u. . .

A[i] = 1 iff i is in S

The operations add, delete and lookup all take O(1) time.

1 0

. . . looks good so far!

predecessor(11)

Page 60: van Emde Boas trees

Attempt 1: a big array

161 2 3 4 5 6 7 8 9 10 11 12 13 14 15

00 1 1 1 1 0 1 0 0 0 0 0 0 1 1AA

u

Build an array of length u. . .

A[i] = 1 iff i is in S

The operations add, delete and lookup all take O(1) time.

1 0

. . . looks good so far!

predecessor(11)

The predecessor and successor operations take O(u) time

Page 61: van Emde Boas trees

Attempt 1: a big array

161 2 3 4 5 6 7 8 9 10 11 12 13 14 15

00 1 1 1 1 0 1 0 0 0 0 0 0 1 1AA

u

Build an array of length u. . .

A[i] = 1 iff i is in S

The operations add, delete and lookup all take O(1) time.

1 0

. . . looks good so far!

The predecessor and successor operations take O(u) time

Page 62: van Emde Boas trees

Attempt 1: a big array

161 2 3 4 5 6 7 8 9 10 11 12 13 14 15

00 1 1 1 1 0 1 0 0 0 0 0 0 1 1AA

u

Build an array of length u. . .

A[i] = 1 iff i is in S

The operations add, delete and lookup all take O(1) time.

1 0

. . . looks good so far!

The predecessor and successor operations take O(u) time. . . not so good!

Page 63: van Emde Boas trees

Attempt 2: a constant height tree(on top of a big array)

161 2 3 4 5 6 7 8 9 10 11 12 13 14 15

00 1 1 1 1 0 1 0 0 0 0 0 0 1 1AA

u

1 0

Page 64: van Emde Boas trees

Attempt 2: a constant height tree(on top of a big array)

Split A into√u blocks each containing

√u bits

161 2 3 4 5 6 7 8 9 10 11 12 13 14 15

00 1 1 1 1 0 1 0 0 0 0 0 0 1 1AA

u

1 0

Page 65: van Emde Boas trees

Attempt 2: a constant height tree(on top of a big array)

161 2 3 4 5 6 7 8 9 10 11 12 13 14 15

AA

u

0 00 1 1 1 1 0 1 0 0 0 1

√u u

√u u

√u u

√u

0

Split A into√u blocks each containing

√u bits

00

Page 66: van Emde Boas trees

Attempt 2: a constant height tree(on top of a big array)

161 2 3 4 5 6 7 8 9 10 11 12 13 14 15

AA

u

0 00 1 1 1 1 0 1 0 0 0 1

√u u

√u u

√u u

√u

0

01 1 1

√u

C

Split A into√u blocks each containing

√u bits

00

Page 67: van Emde Boas trees

Attempt 2: a constant height tree(on top of a big array)

161 2 3 4 5 6 7 8 9 10 11 12 13 14 15

AA

u

0 00 1 1 1 1 0 1 0 0 0 1

√u u

√u u

√u u

√u

0

01 1 1

√u

C

Split A into√u blocks each containing

√u bits

C is called thesummary of A

00

Page 68: van Emde Boas trees

Attempt 2: a constant height tree(on top of a big array)

161 2 3 4 5 6 7 8 9 10 11 12 13 14 15

AA

u

0 00 1 1 1 1 0 1 0 0 0 1

√u u

√u u

√u u

√u

0

01 1 1

√u

C

Split A into√u blocks each containing

√u bits

C is called thesummary of A

00

Page 69: van Emde Boas trees

Attempt 2: a constant height tree(on top of a big array)

161 2 3 4 5 6 7 8 9 10 11 12 13 14 15

AA

u

0 00 1 1 1 1 0 1 0 0 0 1

√u u

√u u

√u u

√u

0

01 1 1

√u

this is 1 ifany bit in the child block is 1

C

Split A into√u blocks each containing

√u bits

C is called thesummary of A

00

Page 70: van Emde Boas trees

Attempt 2: a constant height tree(on top of a big array)

161 2 3 4 5 6 7 8 9 10 11 12 13 14 15

AA

u

0 00 1 1 1 1 0 1 0 0 0 1

√u u

√u u

√u u

√u

0

01 1 1

√u

this is 1 ifany bit in the child block is 1

C

Split A into√u blocks each containing

√u bits

C is called thesummary of A

The lookup and add operations take O(1) time.

00

Page 71: van Emde Boas trees

Attempt 2: a constant height tree(on top of a big array)

161 2 3 4 5 6 7 8 9 10 11 12 13 14 15

AA

u

0 00 1 1 1 1 0 1 0 0 0 1

√u u

√u u

√u u

√u

0

01 1 1

√u

this is 1 ifany bit in the child block is 1

C

Split A into√u blocks each containing

√u bits

C is called thesummary of A

The lookup and add operations take O(1) time.

lookup(12)

00

Page 72: van Emde Boas trees

Attempt 2: a constant height tree(on top of a big array)

161 2 3 4 5 6 7 8 9 10 11 12 13 14 15

AA

u

0 00 1 1 1 1 0 1 0 0 0 1

√u u

√u u

√u u

√u

0

01 1 1

√u

this is 1 ifany bit in the child block is 1

C

Split A into√u blocks each containing

√u bits

C is called thesummary of A

The lookup and add operations take O(1) time.

lookup(12)

00

Page 73: van Emde Boas trees

Attempt 2: a constant height tree(on top of a big array)

161 2 3 4 5 6 7 8 9 10 11 12 13 14 15

AA

u

0 00 1 1 1 1 0 1 0 0 0 1

√u u

√u u

√u u

√u

0

01 1 1

√u

this is 1 ifany bit in the child block is 1

C

Split A into√u blocks each containing

√u bits

C is called thesummary of A

The lookup and add operations take O(1) time.

00

Page 74: van Emde Boas trees

Attempt 2: a constant height tree(on top of a big array)

161 2 3 4 5 6 7 8 9 10 11 12 13 14 15

AA

u

0 00 1 1 1 1 0 1 0 0 0 1

√u u

√u u

√u u

√u

0

01 1 1

√u

this is 1 ifany bit in the child block is 1

C

Split A into√u blocks each containing

√u bits

C is called thesummary of A

The lookup and add operations take O(1) time.

add(9)

00

Page 75: van Emde Boas trees

Attempt 2: a constant height tree(on top of a big array)

161 2 3 4 5 6 7 8 9 10 11 12 13 14 15

AA

u

0 00 1 1 1 1 0 1 0 0 0 1

√u u

√u u

√u u

√u

0

01 1 1

√u

this is 1 ifany bit in the child block is 1

C

Split A into√u blocks each containing

√u bits

C is called thesummary of A

The lookup and add operations take O(1) time.

add(9)

1

1

00

Page 76: van Emde Boas trees

Attempt 2: a constant height tree(on top of a big array)

161 2 3 4 5 6 7 8 9 10 11 12 13 14 15

AA

u

0 00 1 1 1 1 0 1 0 0 0 1

√u u

√u u

√u u

√u

0

01 1 1

√u

this is 1 ifany bit in the child block is 1

C

Split A into√u blocks each containing

√u bits

C is called thesummary of A

The lookup and add operations take O(1) time.

add(9)

1

1

00

Page 77: van Emde Boas trees

Attempt 2: a constant height tree(on top of a big array)

161 2 3 4 5 6 7 8 9 10 11 12 13 14 15

AA

u

0 00 1 1 1 1 0 1 0 0 0 1

√u u

√u u

√u u

√u

0

01 1 1

√u

this is 1 ifany bit in the child block is 1

C

Split A into√u blocks each containing

√u bits

C is called thesummary of A

The lookup and add operations take O(1) time.

1

1

00

Page 78: van Emde Boas trees

Attempt 2: a constant height tree(on top of a big array)

161 2 3 4 5 6 7 8 9 10 11 12 13 14 15

AA

u

0 00 1 1 1 1 0 1 0 0 0 1

√u u

√u u

√u u

√u

0

01 1 1

√u

this is 1 ifany bit in the child block is 1

C

Split A into√u blocks each containing

√u bits

C is called thesummary of A

The lookup and add operations take O(1) time.

The operations delete, predecessor and successor take O(√u) time.

1

1

00

Page 79: van Emde Boas trees

Attempt 2: a constant height tree(on top of a big array)

161 2 3 4 5 6 7 8 9 10 11 12 13 14 15

AA

u

0 00 1 1 1 1 0 1 0 0 0 1

√u u

√u u

√u u

√u

0

01 1 1

√u

this is 1 ifany bit in the child block is 1

C

Split A into√u blocks each containing

√u bits

C is called thesummary of A

The lookup and add operations take O(1) time.

The operations delete, predecessor and successor take O(√u) time.

1

1

delete(7)

00

Page 80: van Emde Boas trees

Attempt 2: a constant height tree(on top of a big array)

161 2 3 4 5 6 7 8 9 10 11 12 13 14 15

AA

u

0 00 1 1 1 1 0 1 0 0 0 1

√u u

√u u

√u u

√u

0

01 1 1

√u

this is 1 ifany bit in the child block is 1

C

Split A into√u blocks each containing

√u bits

C is called thesummary of A

The lookup and add operations take O(1) time.

The operations delete, predecessor and successor take O(√u) time.

1

1

delete(7)

0

?

00

Page 81: van Emde Boas trees

Attempt 2: a constant height tree(on top of a big array)

161 2 3 4 5 6 7 8 9 10 11 12 13 14 15

AA

u

0 00 1 1 1 1 0 1 0 0 0 1

√u u

√u u

√u u

√u

0

01 1 1

√u

this is 1 ifany bit in the child block is 1

C

Split A into√u blocks each containing

√u bits

C is called thesummary of A

The lookup and add operations take O(1) time.

The operations delete, predecessor and successor take O(√u) time.

1

1

delete(7)

0

?

to determine this bityou have to look through this block

00

Page 82: van Emde Boas trees

Attempt 2: a constant height tree(on top of a big array)

161 2 3 4 5 6 7 8 9 10 11 12 13 14 15

AA

u

0 00 1 1 1 1 0 1 0 0 0 1

√u u

√u u

√u u

√u

0

01 1 1

√u

this is 1 ifany bit in the child block is 1

C

Split A into√u blocks each containing

√u bits

C is called thesummary of A

The lookup and add operations take O(1) time.

The operations delete, predecessor and successor take O(√u) time.

1

1

delete(7)

0 00

Page 83: van Emde Boas trees

Attempt 2: a constant height tree(on top of a big array)

161 2 3 4 5 6 7 8 9 10 11 12 13 14 15

AA

u

0 00 1 1 1 1 0 1 0 0 0 1

√u u

√u u

√u u

√u

0

01 1 1

√u

this is 1 ifany bit in the child block is 1

C

Split A into√u blocks each containing

√u bits

C is called thesummary of A

The lookup and add operations take O(1) time.

The operations delete, predecessor and successor take O(√u) time.

1

1

0 00

Page 84: van Emde Boas trees

Attempt 2: a constant height tree(on top of a big array)

161 2 3 4 5 6 7 8 9 10 11 12 13 14 15

AA

u

0 00 1 1 1 1 0 1 0 0 0 1

√u u

√u u

√u u

√u

0

01 1 1

√u

this is 1 ifany bit in the child block is 1

C

Split A into√u blocks each containing

√u bits

C is called thesummary of A

The lookup and add operations take O(1) time.

The operations delete, predecessor and successor take O(√u) time.

1

1

0

delete(9)

00

Page 85: van Emde Boas trees

Attempt 2: a constant height tree(on top of a big array)

161 2 3 4 5 6 7 8 9 10 11 12 13 14 15

AA

u

0 00 1 1 1 1 0 1 0 0 0 1

√u u

√u u

√u u

√u

0

01 1 1

√u

this is 1 ifany bit in the child block is 1

C

Split A into√u blocks each containing

√u bits

C is called thesummary of A

The lookup and add operations take O(1) time.

The operations delete, predecessor and successor take O(√u) time.

1

1

0

delete(9)

0

0?

00

Page 86: van Emde Boas trees

Attempt 2: a constant height tree(on top of a big array)

161 2 3 4 5 6 7 8 9 10 11 12 13 14 15

AA

u

0 00 1 1 1 1 0 1 0 0 0 1

√u u

√u u

√u u

√u

0

01 1 1

√u

this is 1 ifany bit in the child block is 1

C

Split A into√u blocks each containing

√u bits

C is called thesummary of A

The lookup and add operations take O(1) time.

The operations delete, predecessor and successor take O(√u) time.

1

1

0

delete(9)

0

0?

to determine this bityou have to look through this block

00

Page 87: van Emde Boas trees

Attempt 2: a constant height tree(on top of a big array)

161 2 3 4 5 6 7 8 9 10 11 12 13 14 15

AA

u

0 00 1 1 1 1 0 1 0 0 0 1

√u u

√u u

√u u

√u

0

01 1 1

√u

this is 1 ifany bit in the child block is 1

C

Split A into√u blocks each containing

√u bits

C is called thesummary of A

The lookup and add operations take O(1) time.

The operations delete, predecessor and successor take O(√u) time.

1

1

0 0

0

00

Page 88: van Emde Boas trees

Attempt 2: a constant height tree(on top of a big array)

161 2 3 4 5 6 7 8 9 10 11 12 13 14 15

AA

u

0 00 1 1 1 1 0 1 0 0 0 1

√u u

√u u

√u u

√u

0

01 1 1

√u

this is 1 ifany bit in the child block is 1

C

Split A into√u blocks each containing

√u bits

C is called thesummary of A

The lookup and add operations take O(1) time.

The operations delete, predecessor and successor take O(√u) time.

1

1

0 0

0

predecessor(14)

00

Page 89: van Emde Boas trees

Attempt 2: a constant height tree(on top of a big array)

161 2 3 4 5 6 7 8 9 10 11 12 13 14 15

AA

u

0 00 1 1 1 1 0 1 0 0 0 1

√u u

√u u

√u u

√u

0

01 1 1

√u

this is 1 ifany bit in the child block is 1

C

Split A into√u blocks each containing

√u bits

C is called thesummary of A

The lookup and add operations take O(1) time.

The operations delete, predecessor and successor take O(√u) time.

1

1

0 0

0

predecessor(14)

00

Page 90: van Emde Boas trees

Attempt 2: a constant height tree(on top of a big array)

161 2 3 4 5 6 7 8 9 10 11 12 13 14 15

AA

u

0 00 1 1 1 1 0 1 0 0 0 1

√u u

√u u

√u u

√u

0

01 1 1

√u

this is 1 ifany bit in the child block is 1

C

Split A into√u blocks each containing

√u bits

C is called thesummary of A

The lookup and add operations take O(1) time.

The operations delete, predecessor and successor take O(√u) time.

1

1

0 0

0

predecessor(14)

00

Page 91: van Emde Boas trees

Attempt 2: a constant height tree(on top of a big array)

161 2 3 4 5 6 7 8 9 10 11 12 13 14 15

AA

u

0 00 1 1 1 1 0 1 0 0 0 1

√u u

√u u

√u u

√u

0

01 1 1

√u

this is 1 ifany bit in the child block is 1

C

Split A into√u blocks each containing

√u bits

C is called thesummary of A

The lookup and add operations take O(1) time.

The operations delete, predecessor and successor take O(√u) time.

1

1

0 0

0

predecessor(14)

1

00

Page 92: van Emde Boas trees

Attempt 2: a constant height tree(on top of a big array)

161 2 3 4 5 6 7 8 9 10 11 12 13 14 15

AA

u

0 00 1 1 1 1 0 1 0 0 0 1

√u u

√u u

√u u

√u

0

01 1 1

√u

this is 1 ifany bit in the child block is 1

C

Split A into√u blocks each containing

√u bits

C is called thesummary of A

The lookup and add operations take O(1) time.

The operations delete, predecessor and successor take O(√u) time.

1

1

0 0

0

predecessor(14)

1

00

Page 93: van Emde Boas trees

Attempt 2: a constant height tree(on top of a big array)

161 2 3 4 5 6 7 8 9 10 11 12 13 14 15

AA

u

0 00 1 1 1 1 0 1 0 0 0 1

√u u

√u u

√u u

√u

0

01 1 1

√u

this is 1 ifany bit in the child block is 1

C

Split A into√u blocks each containing

√u bits

C is called thesummary of A

The lookup and add operations take O(1) time.

The operations delete, predecessor and successor take O(√u) time.

1

1

0 0

0

predecessor(14)

1

00

Page 94: van Emde Boas trees

Attempt 2: a constant height tree(on top of a big array)

161 2 3 4 5 6 7 8 9 10 11 12 13 14 15

AA

u

0 00 1 1 1 1 0 1 0 0 0 1

√u u

√u u

√u u

√u

0

01 1 1

√u

this is 1 ifany bit in the child block is 1

C

Split A into√u blocks each containing

√u bits

C is called thesummary of A

The lookup and add operations take O(1) time.

The operations delete, predecessor and successor take O(√u) time.

1

1

0 0

0

predecessor(14)

1

0

1

0

Page 95: van Emde Boas trees

Attempt 2: a constant height tree(on top of a big array)

161 2 3 4 5 6 7 8 9 10 11 12 13 14 15

AA

u

0 00 1 1 1 1 0 1 0 0 0 1

√u u

√u u

√u u

√u

0

01 1 1

√u

this is 1 ifany bit in the child block is 1

C

Split A into√u blocks each containing

√u bits

C is called thesummary of A

The lookup and add operations take O(1) time.

The operations delete, predecessor and successor take O(√u) time.

1

1

0 0

0

predecessor(14)

1

0

1

0

Page 96: van Emde Boas trees

Attempt 2: a constant height tree(on top of a big array)

161 2 3 4 5 6 7 8 9 10 11 12 13 14 15

AA

u

0 00 1 1 1 1 0 1 0 0 0 1

√u u

√u u

√u u

√u

0

01 1 1

√u

this is 1 ifany bit in the child block is 1

C

Split A into√u blocks each containing

√u bits

C is called thesummary of A

The lookup and add operations take O(1) time.

The operations delete, predecessor and successor take O(√u) time.

1

1

0 0

0

predecessor(14)

1

0

1

0

Page 97: van Emde Boas trees

Attempt 2: a constant height tree(on top of a big array)

161 2 3 4 5 6 7 8 9 10 11 12 13 14 15

AA

u

0 00 1 1 1 1 0 1 0 0 0 1

√u u

√u u

√u u

√u

0

01 1 1

√u

this is 1 ifany bit in the child block is 1

C

Split A into√u blocks each containing

√u bits

C is called thesummary of A

The lookup and add operations take O(1) time.

The operations delete, predecessor and successor take O(√u) time.

1

1

0 0

0

predecessor(14)

1

0

1

0

Page 98: van Emde Boas trees

Attempt 2: a constant height tree(on top of a big array)

161 2 3 4 5 6 7 8 9 10 11 12 13 14 15

AA

u

0 00 1 1 1 1 0 1 0 0 0 1

√u u

√u u

√u u

√u

0

01 1 1

√u

this is 1 ifany bit in the child block is 1

C

Split A into√u blocks each containing

√u bits

C is called thesummary of A

The lookup and add operations take O(1) time.

The operations delete, predecessor and successor take O(√u) time.

1

1

0 0

0

predecessor(14)

1

0

1

1 0

Page 99: van Emde Boas trees

Attempt 2: a constant height tree(on top of a big array)

161 2 3 4 5 6 7 8 9 10 11 12 13 14 15

AA

u

0 00 1 1 1 1 0 1 0 0 0 1

√u u

√u u

√u u

√u

0

01 1 1

√u

this is 1 ifany bit in the child block is 1

C

Split A into√u blocks each containing

√u bits

C is called thesummary of A

The lookup and add operations take O(1) time.

The operations delete, predecessor and successor take O(√u) time.

1

1

0 0

0

predecessor(14)

1

0

1

1 0

In the worst case we look atall of C and all of two blocks

Page 100: van Emde Boas trees

Attempt 2: a constant height tree(on top of a big array)

161 2 3 4 5 6 7 8 9 10 11 12 13 14 15

AA

u

0 00 1 1 1 1 0 1 0 0 0 1

√u u

√u u

√u u

√u

0

01 1 1

√u

this is 1 ifany bit in the child block is 1

C

Split A into√u blocks each containing

√u bits

C is called thesummary of A

The lookup and add operations take O(1) time.

The operations delete, predecessor and successor take O(√u) time.

1

1

0 0

0

predecessor(14)

1

0

1

1 0

In the worst case we look atall of C and all of two blocks

(successor is the same)

Page 101: van Emde Boas trees

An abstract view

u

Split the universe U into√u blocks each associated with

√u elements

1 2 3 4 . . . u

there is a whole lotmore universe in here

Page 102: van Emde Boas trees

An abstract view

u

√u u

√u u

√u u

√u

Split the universe U into√u blocks each associated with

√u elements

1 2 3 4 . . . u

there is a whole lotmore universe in here

Page 103: van Emde Boas trees

An abstract view

u

√u u

√u u

√u u

√u

Split the universe U into√u blocks each associated with

√u elements

there is a whole lotmore universe in here

Page 104: van Emde Boas trees

An abstract view

u

√u u

√u u

√u u

√u

Split the universe U into√u blocks each associated with

√u elements

there is a whole lotmore universe in here

we can think of each blockas a ‘little’ universe of size

√u

Page 105: van Emde Boas trees

An abstract view

u

√u u

√u u

√u u

√u

Split the universe U into√u blocks each associated with

√u elements

we can think of each blockas a ‘little’ universe of size

√u

Page 106: van Emde Boas trees

An abstract view

u

√u u

√u u

√u u

√u

Split the universe U into√u blocks each associated with

√u elements

we can think of each blockas a ‘little’ universe of size

√u

For block i, we build a data structure B[i]

which stores elements from {1, 2, 3, . . .√u}

Page 107: van Emde Boas trees

An abstract view

u

√u u

√u u

√u u

√u

Split the universe U into√u blocks each associated with

√u elements

B[1] B[2] B[3] B[√

u]

we can think of each blockas a ‘little’ universe of size

√u

For block i, we build a data structure B[i]

which stores elements from {1, 2, 3, . . .√u}

Page 108: van Emde Boas trees

An abstract view

u

√u u

√u u

√u u

√u

Split the universe U into√u blocks each associated with

√u elements

B[1] B[2] B[3] B[√

u]

we can think of each blockas a ‘little’ universe of size

√u

For block i, we build a data structure B[i]

which stores elements from {1, 2, 3, . . .√u}

x is stored in B[i] iff(x+ (i− 1)

√u)∈ S

Page 109: van Emde Boas trees

An abstract view

u

√u u

√u u

√u u

√u

Split the universe U into√u blocks each associated with

√u elements

B[1] B[2] B[3] B[√

u]

we can think of each blockas a ‘little’ universe of size

√u

For block i, we build a data structure B[i]

which stores elements from {1, 2, 3, . . .√u}

x is stored in B[i] iff(x+ (i− 1)

√u)∈ S

(this is just to deal with the offset from the start of the real universe)

Page 110: van Emde Boas trees

An abstract view

u

√u u

√u u

√u u

√u

Split the universe U into√u blocks each associated with

√u elements

B[1] B[2] B[3] B[√

u]

For block i, we build a data structure B[i]

which stores elements from {1, 2, 3, . . .√u}

x is stored in B[i] iff(x+ (i− 1)

√u)∈ S

(this is just to deal with the offset from the start of the real universe)

Page 111: van Emde Boas trees

An abstract view

u

√u u

√u u

√u u

√u

Split the universe U into√u blocks each associated with

√u elements

B[1] B[2] B[3] B[√

u]

For block i, we build a data structure B[i]

which stores elements from {1, 2, 3, . . .√u}

x is stored in B[i] iff(x+ (i− 1)

√u)∈ S

Page 112: van Emde Boas trees

An abstract view

u

√u u

√u u

√u u

√u

√u

C

Split the universe U into√u blocks each associated with

√u elements

B[1] B[2] B[3] B[√

u]

For block i, we build a data structure B[i]

which stores elements from {1, 2, 3, . . .√u}

We also build a summary data structure C

x is stored in B[i] iff(x+ (i− 1)

√u)∈ S

which stores elements from {1, 2, 3, . . .√u}

i is stored in C iff B[i] is non-empty

Page 113: van Emde Boas trees

An abstract view

u

√u u

√u u

√u u

√u

√u

C

Split the universe U into√u blocks each associated with

√u elements

B[1] B[2] B[3] B[√

u]

For block i, we build a data structure B[i]

which stores elements from {1, 2, 3, . . .√u}

We also build a summary data structure C

x is stored in B[i] iff(x+ (i− 1)

√u)∈ S

which stores elements from {1, 2, 3, . . .√u}

i is stored in C iff B[i] is non-empty

Page 114: van Emde Boas trees

An abstract view

u

√u u

√u u

√u u

√u

√u

C

Split the universe U into√u blocks each associated with

√u elements

B[1] B[2] B[3] B[√

u]

How should we build B[1], B[2], . . . B[√u] and C?

Page 115: van Emde Boas trees

An abstract view

u

√u u

√u u

√u u

√u

√u

C

Split the universe U into√u blocks each associated with

√u elements

B[1] B[2] B[3] B[√

u]

How should we build B[1], B[2], . . . B[√u] and C?

Recursion!

Page 116: van Emde Boas trees

An abstract view

u

√u u

√u u

√u u

√u

√u

C

Split the universe U into√u blocks each associated with

√u elements

B[1] B[2] B[3] B[√

u]

How should we build B[1], B[2], . . . B[√u] and C?

Recursion!

Each B[i] has universe {1, 2, 3, . . .√u}

Page 117: van Emde Boas trees

An abstract view

u

√u u

√u u

√u u

√u

√u

C

Split the universe U into√u blocks each associated with

√u elements

B[1] B[2] B[3] B[√

u]

How should we build B[1], B[2], . . . B[√u] and C?

Recursion!

Each B[i] has universe {1, 2, 3, . . .√u}

We recursively split this into 4√u blocks each associated with 4

√u elements. . .

Page 118: van Emde Boas trees

An abstract view

u

√u u

√u u

√u u

√u

√u

C

Split the universe U into√u blocks each associated with

√u elements

B[1] B[2] B[3] B[√

u]

How should we build B[1], B[2], . . . B[√u] and C?

Recursion!

Each B[i] has universe {1, 2, 3, . . .√u}

We recursively split this into 4√u blocks each associated with 4

√u elements. . .

eventually (after some more work), this will lead to an O(log logn) time solution

Page 119: van Emde Boas trees

Attempt 3: Recursion

u

√u u

√u u

√u u

√u

√u

C

Split the universe U into√u blocks each associated with

√u elements

B[1] B[2] B[3] B[√

u]

Page 120: van Emde Boas trees

Attempt 3: Recursion

How do we perform the operations?

u

√u u

√u u

√u u

√u

√u

C

Split the universe U into√u blocks each associated with

√u elements

B[1] B[2] B[3] B[√

u]

Page 121: van Emde Boas trees

Attempt 3: Recursion

To perform add(x):

Step 1 Determine which B[i] the element x belongs in(this takes O(1) time with a little bit twiddling)

Step 3 add x to B[i](suitably adjusting the offset from the start of B[i])

Step 2 If B[i] is empty, add i to C

u

√u u

√u u

√u u

√u

√u

C

Split the universe U into√u blocks each associated with

√u elements

B[1] B[2] B[3] B[√

u]

Page 122: van Emde Boas trees

Attempt 3: Recursion

To perform add(x):

Step 1 Determine which B[i] the element x belongs in(this takes O(1) time with a little bit twiddling)

Step 3 add x to B[i](suitably adjusting the offset from the start of B[i])

Step 2 If B[i] is empty, add i to C

u

√u u

√u u

√u u

√u

√u

C

Split the universe U into√u blocks each associated with

√u elements

B[1] B[2] B[3] B[√

u]

x

Page 123: van Emde Boas trees

Attempt 3: Recursion

To perform add(x):

Step 1 Determine which B[i] the element x belongs in(this takes O(1) time with a little bit twiddling)

Step 3 add x to B[i](suitably adjusting the offset from the start of B[i])

Step 2 If B[i] is empty, add i to C

u

√u u

√u u

√u u

√u

√u

C

Split the universe U into√u blocks each associated with

√u elements

B[1] B[2] B[3] B[√

u]

x

Page 124: van Emde Boas trees

Attempt 3: Recursion

To perform add(x):

Step 1 Determine which B[i] the element x belongs in(this takes O(1) time with a little bit twiddling)

Step 3 add x to B[i](suitably adjusting the offset from the start of B[i])

Step 2 If B[i] is empty, add i to C

u

√u u

√u u

√u u

√u

√u

C

Split the universe U into√u blocks each associated with

√u elements

B[1] B[2] B[3] B[√

u]

x

Page 125: van Emde Boas trees

Attempt 3: Recursion

To perform add(x):

Step 1 Determine which B[i] the element x belongs in(this takes O(1) time with a little bit twiddling)

Step 3 add x to B[i](suitably adjusting the offset from the start of B[i])

Step 2 If B[i] is empty, add i to C

u

√u u

√u u

√u u

√u

√u

C

Split the universe U into√u blocks each associated with

√u elements

B[1] B[2] B[3] B[√

u]

x

Page 126: van Emde Boas trees

Attempt 3: Recursion

To perform add(x):

Step 1 Determine which B[i] the element x belongs in(this takes O(1) time with a little bit twiddling)

Step 3 add x to B[i](suitably adjusting the offset from the start of B[i])

Step 2 If B[i] is empty, add i to C

u

√u u

√u u

√u u

√u

√u

C

Split the universe U into√u blocks each associated with

√u elements

B[1] B[2] B[3] B[√

u]

x

Page 127: van Emde Boas trees

Attempt 3: Recursion

To perform add(x):

Step 1 Determine which B[i] the element x belongs in(this takes O(1) time with a little bit twiddling)

Step 3 add x to B[i](suitably adjusting the offset from the start of B[i])

Step 2 If B[i] is empty, add i to C

u

√u u

√u u

√u u

√u

√u

C

Split the universe U into√u blocks each associated with

√u elements

B[1] B[2] B[3] B[√

u]

x

We actually insert x′ where

x =(x′ + (i− 1)

√u)

Page 128: van Emde Boas trees

Attempt 3: Recursion

To perform add(x):

Step 1 Determine which B[i] the element x belongs in(this takes O(1) time with a little bit twiddling)

Step 3 add x to B[i](suitably adjusting the offset from the start of B[i])

Step 2 If B[i] is empty, add i to C

u

√u u

√u u

√u u

√u

√u

C

Split the universe U into√u blocks each associated with

√u elements

B[1] B[2] B[3] B[√

u]

x

Page 129: van Emde Boas trees

Attempt 3: Recursion

To perform add(x):

Step 1 Determine which B[i] the element x belongs in(this takes O(1) time with a little bit twiddling)

Step 3 add x to B[i](suitably adjusting the offset from the start of B[i])

Step 2 If B[i] is empty, add i to C

u

√u u

√u u

√u u

√u

√u

C

Split the universe U into√u blocks each associated with

√u elements

B[1] B[2] B[3] B[√

u]

Page 130: van Emde Boas trees

Attempt 3: Recursion

u

√u u

√u u

√u u

√u

√u

C

Split the universe U into√u blocks each associated with

√u elements

B[1] B[2] B[3] B[√

u]

Page 131: van Emde Boas trees

Attempt 3: Recursion

u

√u u

√u u

√u u

√u

√u

C

Split the universe U into√u blocks each associated with

√u elements

B[1] B[2] B[3] B[√

u]

To perform predecessor(x):

Step 1 Determine which B[i] the element x belongs in

Compute the predecessor of x in B[j]

(suitably adjusting the offset from the start of B[j])

Compute j = predecessor(i) in C

Step 2 Compute the predecessor of x in B[i]

Step 3 If x has no predecessor in B[i]:

(suitably adjusting the offset from the start of B[i])

Page 132: van Emde Boas trees

Attempt 3: Recursion

u

√u u

√u u

√u u

√u

√u

C

Split the universe U into√u blocks each associated with

√u elements

B[1] B[2] B[3] B[√

u]

To perform predecessor(x):

Step 1 Determine which B[i] the element x belongs in

Compute the predecessor of x in B[j]

(suitably adjusting the offset from the start of B[j])

Compute j = predecessor(i) in C

Step 2 Compute the predecessor of x in B[i]

Step 3 If x has no predecessor in B[i]:

(suitably adjusting the offset from the start of B[i])

x

Page 133: van Emde Boas trees

Attempt 3: Recursion

u

√u u

√u u

√u u

√u

√u

C

Split the universe U into√u blocks each associated with

√u elements

B[1] B[2] B[3] B[√

u]

To perform predecessor(x):

Step 1 Determine which B[i] the element x belongs in

Compute the predecessor of x in B[j]

(suitably adjusting the offset from the start of B[j])

Compute j = predecessor(i) in C

Step 2 Compute the predecessor of x in B[i]

Step 3 If x has no predecessor in B[i]:

(suitably adjusting the offset from the start of B[i])

x

Page 134: van Emde Boas trees

Attempt 3: Recursion

u

√u u

√u u

√u u

√u

√u

C

Split the universe U into√u blocks each associated with

√u elements

B[1] B[2] B[3] B[√

u]

To perform predecessor(x):

Step 1 Determine which B[i] the element x belongs in

Compute the predecessor of x in B[j]

(suitably adjusting the offset from the start of B[j])

Compute j = predecessor(i) in C

Step 2 Compute the predecessor of x in B[i]

Step 3 If x has no predecessor in B[i]:

(suitably adjusting the offset from the start of B[i])

x

Page 135: van Emde Boas trees

Attempt 3: Recursion

u

√u u

√u u

√u u

√u

√u

C

Split the universe U into√u blocks each associated with

√u elements

B[1] B[2] B[3] B[√

u]

To perform predecessor(x):

Step 1 Determine which B[i] the element x belongs in

Compute the predecessor of x in B[j]

(suitably adjusting the offset from the start of B[j])

Compute j = predecessor(i) in C

Step 2 Compute the predecessor of x in B[i]

Step 3 If x has no predecessor in B[i]:

(suitably adjusting the offset from the start of B[i])

x

done!

Page 136: van Emde Boas trees

Attempt 3: Recursion

u

√u u

√u u

√u u

√u

√u

C

Split the universe U into√u blocks each associated with

√u elements

B[1] B[2] B[3] B[√

u]

To perform predecessor(x):

Step 1 Determine which B[i] the element x belongs in

Compute the predecessor of x in B[j]

(suitably adjusting the offset from the start of B[j])

Compute j = predecessor(i) in C

Step 2 Compute the predecessor of x in B[i]

Step 3 If x has no predecessor in B[i]:

(suitably adjusting the offset from the start of B[i])

Page 137: van Emde Boas trees

Attempt 3: Recursion

u

√u u

√u u

√u u

√u

√u

C

Split the universe U into√u blocks each associated with

√u elements

B[1] B[2] B[3] B[√

u]

To perform predecessor(x):

Step 1 Determine which B[i] the element x belongs in

Compute the predecessor of x in B[j]

(suitably adjusting the offset from the start of B[j])

Compute j = predecessor(i) in C

Step 2 Compute the predecessor of x in B[i]

Step 3 If x has no predecessor in B[i]:

(suitably adjusting the offset from the start of B[i])

x

Page 138: van Emde Boas trees

Attempt 3: Recursion

u

√u u

√u u

√u u

√u

√u

C

Split the universe U into√u blocks each associated with

√u elements

B[1] B[2] B[3] B[√

u]

To perform predecessor(x):

Step 1 Determine which B[i] the element x belongs in

Compute the predecessor of x in B[j]

(suitably adjusting the offset from the start of B[j])

Compute j = predecessor(i) in C

Step 2 Compute the predecessor of x in B[i]

Step 3 If x has no predecessor in B[i]:

(suitably adjusting the offset from the start of B[i])

x

Page 139: van Emde Boas trees

Attempt 3: Recursion

u

√u u

√u u

√u u

√u

√u

C

Split the universe U into√u blocks each associated with

√u elements

B[1] B[2] B[3] B[√

u]

To perform predecessor(x):

Step 1 Determine which B[i] the element x belongs in

Compute the predecessor of x in B[j]

(suitably adjusting the offset from the start of B[j])

Compute j = predecessor(i) in C

Step 2 Compute the predecessor of x in B[i]

Step 3 If x has no predecessor in B[i]:

(suitably adjusting the offset from the start of B[i])

x

x has no predecessor in here

Page 140: van Emde Boas trees

Attempt 3: Recursion

u

√u u

√u u

√u u

√u

√u

C

Split the universe U into√u blocks each associated with

√u elements

B[1] B[2] B[3] B[√

u]

To perform predecessor(x):

Step 1 Determine which B[i] the element x belongs in

Compute the predecessor of x in B[j]

(suitably adjusting the offset from the start of B[j])

Compute j = predecessor(i) in C

Step 2 Compute the predecessor of x in B[i]

Step 3 If x has no predecessor in B[i]:

(suitably adjusting the offset from the start of B[i])

x

x has no predecessor in herei

Page 141: van Emde Boas trees

Attempt 3: Recursion

u

√u u

√u u

√u u

√u

√u

C

Split the universe U into√u blocks each associated with

√u elements

B[1] B[2] B[3] B[√

u]

To perform predecessor(x):

Step 1 Determine which B[i] the element x belongs in

Compute the predecessor of x in B[j]

(suitably adjusting the offset from the start of B[j])

Compute j = predecessor(i) in C

Step 2 Compute the predecessor of x in B[i]

Step 3 If x has no predecessor in B[i]:

(suitably adjusting the offset from the start of B[i])

x

x has no predecessor in hereij = 2

Page 142: van Emde Boas trees

Attempt 3: Recursion

u

√u u

√u u

√u u

√u

√u

C

Split the universe U into√u blocks each associated with

√u elements

B[1] B[2] B[3] B[√

u]

To perform predecessor(x):

Step 1 Determine which B[i] the element x belongs in

Compute the predecessor of x in B[j]

(suitably adjusting the offset from the start of B[j])

Compute j = predecessor(i) in C

Step 2 Compute the predecessor of x in B[i]

Step 3 If x has no predecessor in B[i]:

(suitably adjusting the offset from the start of B[i])

x

x has no predecessor in hereij = 2

Page 143: van Emde Boas trees

Attempt 3: Recursion

u

√u u

√u u

√u u

√u

√u

C

Split the universe U into√u blocks each associated with

√u elements

B[1] B[2] B[3] B[√

u]

To perform predecessor(x):

Step 1 Determine which B[i] the element x belongs in

Compute the predecessor of x in B[j]

(suitably adjusting the offset from the start of B[j])

Compute j = predecessor(i) in C

Step 2 Compute the predecessor of x in B[i]

Step 3 If x has no predecessor in B[i]:

(suitably adjusting the offset from the start of B[i])

x

x has no predecessor in hereij = 2

Page 144: van Emde Boas trees

Attempt 3: Recursion

u

√u u

√u u

√u u

√u

√u

C

Split the universe U into√u blocks each associated with

√u elements

B[1] B[2] B[3] B[√

u]

Page 145: van Emde Boas trees

Attempt 3: Recursion

u

√u u

√u u

√u u

√u

√u

C

Split the universe U into√u blocks each associated with

√u elements

B[1] B[2] B[3] B[√

u]

The operations lookup, delete and successor canall also be defined in a similar, recursive manner

Page 146: van Emde Boas trees

Attempt 3: Recursion

u

√u u

√u u

√u u

√u

√u

C

Split the universe U into√u blocks each associated with

√u elements

B[1] B[2] B[3] B[√

u]

The operations lookup, delete and successor canall also be defined in a similar, recursive manner

How efficient are the operations?

Page 147: van Emde Boas trees

Attempt 3: Recursion

To perform add(x):

Step 1 Determine which B[i] the element x belongs in(this takes O(1) time with a little bit twiddling)

Step 3 add x to B[i](suitably adjusting the offset from the start of B[i])

Step 2 If B[i] is empty, add i to C

u

√u u

√u u

√u u

√u

√u

C

Split the universe U into√u blocks each associated with

√u elements

B[1] B[2] B[3] B[√

u]

Page 148: van Emde Boas trees

Attempt 3: Recursion

To perform add(x):

Step 1 Determine which B[i] the element x belongs in(this takes O(1) time with a little bit twiddling)

Step 3 add x to B[i](suitably adjusting the offset from the start of B[i])

Step 2 If B[i] is empty, add i to C

u

√u u

√u u

√u u

√u

√u

C

Split the universe U into√u blocks each associated with

√u elements

B[1] B[2] B[3] B[√

u]

up to two recursivecalls

add makes

Page 149: van Emde Boas trees

Attempt 3: Recursion

To perform add(x):

Step 1 Determine which B[i] the element x belongs in(this takes O(1) time with a little bit twiddling)

Step 3 add x to B[i](suitably adjusting the offset from the start of B[i])

Step 2 If B[i] is empty, add i to C

u

√u u

√u u

√u u

√u

√u

C

Split the universe U into√u blocks each associated with

√u elements

B[1] B[2] B[3] B[√

u]

up to two recursivecalls

add makes

Page 150: van Emde Boas trees

Attempt 3: Recursion

u

√u u

√u u

√u u

√u

√u

C

Split the universe U into√u blocks each associated with

√u elements

B[1] B[2] B[3] B[√

u]

To perform predecessor(x):

Step 1 Determine which B[i] the element x belongs in

Compute the predecessor of x in B[j]

(suitably adjusting the offset from the start of B[j])

Compute j = predecessor(i) in C

Step 2 Compute the predecessor of x in B[i]

Step 3 If x has no predecessor in B[i]:

(suitably adjusting the offset from the start of B[i])

up to three recursivecalls!

predecessor makes

Page 151: van Emde Boas trees

Attempt 3: Recursion

u

√u u

√u u

√u u

√u

√u

C

Split the universe U into√u blocks each associated with

√u elements

B[1] B[2] B[3] B[√

u]

The operations lookup, delete and successor canall also be defined in a similar, recursive manner

How efficient are the operations?

Page 152: van Emde Boas trees

Attempt 3: Recursion

u

√u u

√u u

√u u

√u

√u

C

Split the universe U into√u blocks each associated with

√u elements

B[1] B[2] B[3] B[√

u]

The operations lookup, delete and successor canall also be defined in a similar, recursive manner

How efficient are the operations?

The add operation makes up to two recursive callsand the predecessor operation makes up to three

Page 153: van Emde Boas trees

Attempt 3: Recursion

u

√u u

√u u

√u u

√u

√u

C

Split the universe U into√u blocks each associated with

√u elements

B[1] B[2] B[3] B[√

u]

The operations lookup, delete and successor canall also be defined in a similar, recursive manner

How efficient are the operations?

The add operation makes up to two recursive callsand the predecessor operation makes up to three

Each recursive call could in turn make multiple recursive calls. . .

Page 154: van Emde Boas trees

Attempt 3: Recursion

u

√u u

√u u

√u u

√u

√u

C

Split the universe U into√u blocks each associated with

√u elements

B[1] B[2] B[3] B[√

u]

The operations lookup, delete and successor canall also be defined in a similar, recursive manner

How efficient are the operations?

The add operation makes up to two recursive callsand the predecessor operation makes up to three

Each recursive call could in turn make multiple recursive calls. . .

this could get out of hand!

Page 155: van Emde Boas trees

A closer look at predecessor

To perform predecessor(x):

Step 1 Determine which B[i] the element x belongs in

Return the predecessor of x in B[j]

Compute j = predecessor(i) in C

Step 2 Compute the predecessor of x in B[i]

Step 3 If x has no predecessor in B[i]:

x

u

√u u

√u u

√u u

√u

√u

C

B[1] B[2] B[3] B[√

u]

Page 156: van Emde Boas trees

A closer look at predecessor

To perform predecessor(x):

Step 1 Determine which B[i] the element x belongs in

Return the predecessor of x in B[j]

Compute j = predecessor(i) in C

Step 2 Compute the predecessor of x in B[i]

Step 3 If x has no predecessor in B[i]:

x

u

√u u

√u u

√u u

√u

√u

C

B[1] B[2] B[3] B[√

u]

Observation 1: if x has a predecessor in B[i] we only make one recursive call

Page 157: van Emde Boas trees

A closer look at predecessor

To perform predecessor(x):

Step 1 Determine which B[i] the element x belongs in

Return the predecessor of x in B[j]

Compute j = predecessor(i) in C

Step 2 Compute the predecessor of x in B[i]

Step 3 If x has no predecessor in B[i]:

x

u

√u u

√u u

√u u

√u

√u

C

B[1] B[2] B[3] B[√

u]

Observation 1: if x has a predecessor in B[i] we only make one recursive call

x has a predecessor in B[i] iffx > the minimum in B[i]

Page 158: van Emde Boas trees

A closer look at predecessor

To perform predecessor(x):

Step 1 Determine which B[i] the element x belongs in

Return the predecessor of x in B[j]

Compute j = predecessor(i) in C

Step 2 Compute the predecessor of x in B[i]

Step 3 If x has no predecessor in B[i]:

u

√u u

√u u

√u u

√u

√u

C

B[1] B[2] B[3] B[√

u]

Observation 1: if x has a predecessor in B[i] we only make one recursive call

x has a predecessor in B[i] iffx > the minimum in B[i]

x

Page 159: van Emde Boas trees

A closer look at predecessor

To perform predecessor(x):

Step 1 Determine which B[i] the element x belongs in

Return the predecessor of x in B[j]

Compute j = predecessor(i) in C

Step 2 Compute the predecessor of x in B[i]

u

√u u

√u u

√u u

√u

√u

C

B[1] B[2] B[3] B[√

u]

Observation 1: if x has a predecessor in B[i] we only make one recursive call

x has a predecessor in B[i] iffx > the minimum in B[i]

x

Step 3 If x < the minimum in B[i]:

Page 160: van Emde Boas trees

A closer look at predecessor

To perform predecessor(x):

Step 1 Determine which B[i] the element x belongs in

Return the predecessor of x in B[j]

Compute j = predecessor(i) in C

u

√u u

√u u

√u u

√u

√u

C

B[1] B[2] B[3] B[√

u]

Observation 1: if x has a predecessor in B[i] we only make one recursive call

x has a predecessor in B[i] iffx > the minimum in B[i]

x

Step 3 If x < the minimum in B[i]:

Return the predecessor of x in B[i]

Step 2 If x > the minimum in B[i]:

Page 161: van Emde Boas trees

A closer look at predecessor

To perform predecessor(x):

Step 1 Determine which B[i] the element x belongs in

Return the predecessor of x in B[j]

Compute j = predecessor(i) in C

u

√u u

√u u

√u u

√u

√u

C

B[1] B[2] B[3] B[√

u]

Observation 1: if x has a predecessor in B[i] we only make one recursive call

x has a predecessor in B[i] iffx > the minimum in B[i]

x

Step 3 If x < the minimum in B[i]:

Return the predecessor of x in B[i]

Step 2 If x > the minimum in B[i]:

Now we make at mosttwo recursive calls

Page 162: van Emde Boas trees

A closer look at predecessor

To perform predecessor(x):

Step 1 Determine which B[i] the element x belongs in

Return the predecessor of x in B[j]

Compute j = predecessor(i) in C

u

√u u

√u u

√u u

√u

√u

C

B[1] B[2] B[3] B[√

u]

Observation 1: if x has a predecessor in B[i] we only make one recursive call

x has a predecessor in B[i] iffx > the minimum in B[i]

x

Step 3 If x < the minimum in B[i]:

Return the predecessor of x in B[i]

Step 2 If x > the minimum in B[i]:

Now we make at mosttwo recursive calls

(ignoring finding the minimum)

Page 163: van Emde Boas trees

A closer look at predecessor

To perform predecessor(x):

Step 1 Determine which B[i] the element x belongs in

Return the predecessor of x in B[j]

Compute j = predecessor(i) in C

u

√u u

√u u

√u u

√u

√u

C

B[1] B[2] B[3] B[√

u]

x

Step 3 If x < the minimum in B[i]:

Return the predecessor of x in B[i]

Step 2 If x > the minimum in B[i]:

Page 164: van Emde Boas trees

A closer look at predecessor

To perform predecessor(x):

Step 1 Determine which B[i] the element x belongs in

Return the predecessor of x in B[j]

Compute j = predecessor(i) in C

u

√u u

√u u

√u u

√u

√u

C

B[1] B[2] B[3] B[√

u]

x

Step 3 If x < the minimum in B[i]:

Return the predecessor of x in B[i]

Step 2 If x > the minimum in B[i]:we need to get rid

of one of theserecursive calls

Page 165: van Emde Boas trees

A closer look at predecessor

To perform predecessor(x):

Step 1 Determine which B[i] the element x belongs in

Return the predecessor of x in B[j]

Compute j = predecessor(i) in C

u

√u u

√u u

√u u

√u

√u

C

B[1] B[2] B[3] B[√

u]

x

Step 3 If x < the minimum in B[i]:

Return the predecessor of x in B[i]

Step 2 If x > the minimum in B[i]:

ij = 2

we need to get ridof one of these

recursive calls

Page 166: van Emde Boas trees

A closer look at predecessor

To perform predecessor(x):

Step 1 Determine which B[i] the element x belongs in

Return the predecessor of x in B[j]

Compute j = predecessor(i) in C

u

√u u

√u u

√u u

√u

√u

C

B[1] B[2] B[3] B[√

u]

x

Step 3 If x < the minimum in B[i]:

Return the predecessor of x in B[i]

Step 2 If x > the minimum in B[i]:

Observation 2: In Step 3, the predecessor of x in B[j] is the maximum in B[j]

ij = 2

we need to get ridof one of these

recursive calls

Page 167: van Emde Boas trees

A closer look at predecessor

To perform predecessor(x):

Step 1 Determine which B[i] the element x belongs in

Return the predecessor of x in B[j]

Compute j = predecessor(i) in C

u

√u u

√u u

√u u

√u

√u

C

B[1] B[2] B[3] B[√

u]

x

Step 3 If x < the minimum in B[i]:

Return the predecessor of x in B[i]

Step 2 If x > the minimum in B[i]:

Observation 2: In Step 3, the predecessor of x in B[j] is the maximum in B[j]

ij = 2

Page 168: van Emde Boas trees

A closer look at predecessor

To perform predecessor(x):

Step 1 Determine which B[i] the element x belongs in

Compute j = predecessor(i) in C

u

√u u

√u u

√u u

√u

√u

C

B[1] B[2] B[3] B[√

u]

x

Step 3 If x < the minimum in B[i]:

Return the predecessor of x in B[i]

Step 2 If x > the minimum in B[i]:

Observation 2: In Step 3, the predecessor of x in B[j] is the maximum in B[j]

ij = 2

Return the maximum in B[j]

Page 169: van Emde Boas trees

A closer look at predecessor

To perform predecessor(x):

Step 1 Determine which B[i] the element x belongs in

Compute j = predecessor(i) in C

u

√u u

√u u

√u u

√u

√u

C

B[1] B[2] B[3] B[√

u]

x

Step 3 If x < the minimum in B[i]:

Return the predecessor of x in B[i]

Step 2 If x > the minimum in B[i]:

Observation 2: In Step 3, the predecessor of x in B[j] is the maximum in B[j]

ij = 2

Return the maximum in B[j]

Now we make exactlyone recursive call

(ignoring finding the min/max)

Page 170: van Emde Boas trees

Finally: van Emde Boas Trees

u

√u u

√u u

√u u

√u

√u

C

B[1] B[2] B[3] B[√

u]

min max

37 483

So that we can find the min/max quickly we store them seperately. . .

Page 171: van Emde Boas trees

Finally: van Emde Boas Trees

u

√u u

√u u

√u u

√u

√u

C

B[1] B[2] B[3] B[√

u]

min max

37 483

So that we can find the min/max quickly we store them seperately. . .

Page 172: van Emde Boas trees

Finally: van Emde Boas Trees

u

√u u

√u u

√u u

√u

√u

C

B[1] B[2] B[3] B[√

u]

min max

37 483

So that we can find the min/max quickly we store them seperately. . .

Remember that each B[i] and C are also vEB (van Emde Boas) treeseach over the universe {1, 2, 3, . . .

√u}

Page 173: van Emde Boas trees

Finally: van Emde Boas Trees

u

√u u

√u u

√u u

√u

√u

C

B[1] B[2] B[3] B[√

u]

min max

37 483

So that we can find the min/max quickly we store them seperately. . .

Remember that each B[i] and C are also vEB (van Emde Boas) treeseach over the universe {1, 2, 3, . . .

√u}

In particular B[i] also stores it’s min/max elements seperatelyso recovering the minimum or maximum in B[i] (or C) takes O(1) time

Page 174: van Emde Boas trees

Finally: van Emde Boas Trees

u

√u u

√u u

√u u

√u

√u

C

B[1] B[2] B[3] B[√

u]

min max

37 483

So that we can find the min/max quickly we store them seperately. . .

Remember that each B[i] and C are also vEB (van Emde Boas) treeseach over the universe {1, 2, 3, . . .

√u}

In particular B[i] also stores it’s min/max elements seperatelyso recovering the minimum or maximum in B[i] (or C) takes O(1) time

There is one more important thing, the minimum is not also stored in B[i]

Page 175: van Emde Boas trees

Finally: van Emde Boas Trees

u

√u u

√u u

√u u

√u

√u

C

B[1] B[2] B[3] B[√

u]

min max

37 483

So that we can find the min/max quickly we store them seperately. . .

Remember that each B[i] and C are also vEB (van Emde Boas) treeseach over the universe {1, 2, 3, . . .

√u}

In particular B[i] also stores it’s min/max elements seperatelyso recovering the minimum or maximum in B[i] (or C) takes O(1) time

There is one more important thing, the minimum is not also stored in B[i]

Page 176: van Emde Boas trees

Finally: van Emde Boas Trees

u

√u u

√u u

√u u

√u

√u

C

B[1] B[2] B[3] B[√

u]

min max

37 483

So that we can find the min/max quickly we store them seperately. . .

Remember that each B[i] and C are also vEB (van Emde Boas) treeseach over the universe {1, 2, 3, . . .

√u}

In particular B[i] also stores it’s min/max elements seperatelyso recovering the minimum or maximum in B[i] (or C) takes O(1) time

There is one more important thing, the minimum is not also stored in B[i]

the min isonly stored here

Page 177: van Emde Boas trees

Finally: van Emde Boas Trees

u

√u u

√u u

√u u

√u

√u

C

B[1] B[2] B[3] B[√

u]

min max

37 483

So that we can find the min/max quickly we store them seperately. . .

Remember that each B[i] and C are also vEB (van Emde Boas) treeseach over the universe {1, 2, 3, . . .

√u}

In particular B[i] also stores it’s min/max elements seperatelyso recovering the minimum or maximum in B[i] (or C) takes O(1) time

There is one more important thing, the minimum is not also stored in B[i]

the min isonly stored here

this allows us to avoid making multiple recursive calls when adding an element

Page 178: van Emde Boas trees

Another look at add

To perform add(x):

Step 1 Determine which B[i] the element x belongs in

Step 3 If B[i] is not empty, add x to B[i]

Step 2 If B[i] is empty, add i to C

u

√u u

√u u

√u u

√u

√u

C

B[1] B[2] B[3] B[√

u]

min max

37 483

the min isonly stored here

and set the min and max in B[i] to x (adjusting the offset)

Page 179: van Emde Boas trees

Another look at add

To perform add(x):

Step 1 Determine which B[i] the element x belongs in

Step 3 If B[i] is not empty, add x to B[i]

Step 2 If B[i] is empty, add i to C

u

√u u

√u u

√u u

√u

√u

C

B[1] B[2] B[3] B[√

u]

min max

37 483

the min isonly stored here

x

and set the min and max in B[i] to x (adjusting the offset)

Page 180: van Emde Boas trees

Another look at add

To perform add(x):

Step 1 Determine which B[i] the element x belongs in

Step 3 If B[i] is not empty, add x to B[i]

Step 2 If B[i] is empty, add i to C

u

√u u

√u u

√u u

√u

√u

C

B[1] B[2] B[3] B[√

u]

min max

37 483

the min isonly stored here

x

and set the min and max in B[i] to x (adjusting the offset)

one recursive callwe make

Page 181: van Emde Boas trees

Another look at add

To perform add(x):

Step 1 Determine which B[i] the element x belongs in

Step 3 If B[i] is not empty, add x to B[i]

Step 2 If B[i] is empty, add i to C

u

√u u

√u u

√u u

√u

√u

C

B[1] B[2] B[3] B[√

u]

min max

37 483

the min isonly stored here

x

and set the min and max in B[i] to x (adjusting the offset)

one recursive callwe make

Page 182: van Emde Boas trees

Another look at add

To perform add(x):

Step 1 Determine which B[i] the element x belongs in

Step 3 If B[i] is not empty, add x to B[i]

Step 2 If B[i] is empty, add i to C

u

√u u

√u u

√u u

√u

√u

C

B[1] B[2] B[3] B[√

u]

min max

37 483

the min isonly stored here

x

and set the min and max in B[i] to x (adjusting the offset)

Page 183: van Emde Boas trees

Another look at add

To perform add(x):

Step 1 Determine which B[i] the element x belongs in

Step 3 If B[i] is not empty, add x to B[i]

Step 2 If B[i] is empty, add i to C

u

√u u

√u u

√u u

√u

√u

C

B[1] B[2] B[3] B[√

u]

min max

37 483

the min isonly stored here

and set the min and max in B[i] to x (adjusting the offset)

x

Page 184: van Emde Boas trees

Another look at add

To perform add(x):

Step 1 Determine which B[i] the element x belongs in

Step 3 If B[i] is not empty, add x to B[i]

Step 2 If B[i] is empty, add i to C

u

√u u

√u u

√u u

√u

√u

C

B[1] B[2] B[3] B[√

u]

min max

37 483

the min isonly stored here

and set the min and max in B[i] to x (adjusting the offset)

x

one recursive callwe make

Page 185: van Emde Boas trees

Another look at add

To perform add(x):

Step 1 Determine which B[i] the element x belongs in

Step 3 If B[i] is not empty, add x to B[i]

Step 2 If B[i] is empty, add i to C

u

√u u

√u u

√u u

√u

√u

C

B[1] B[2] B[3] B[√

u]

min max

37 483

the min isonly stored here

and set the min and max in B[i] to x (adjusting the offset)

x

one recursive callwe make

Page 186: van Emde Boas trees

Another look at add

To perform add(x):

Step 1 Determine which B[i] the element x belongs in

Step 3 If B[i] is not empty, add x to B[i]

Step 2 If B[i] is empty, add i to C

u

√u u

√u u

√u u

√u

√u

C

B[1] B[2] B[3] B[√

u]

min max

37 483

the min isonly stored here

and set the min and max in B[i] to x (adjusting the offset)

x

one recursive callwe make

Page 187: van Emde Boas trees

Another look at add

To perform add(x):

Step 1 Determine which B[i] the element x belongs in

Step 3 If B[i] is not empty, add x to B[i]

Step 2 If B[i] is empty, add i to C

u

√u u

√u u

√u u

√u

√u

C

B[1] B[2] B[3] B[√

u]

min max

37 483

the min isonly stored here

and set the min and max in B[i] to x (adjusting the offset)

x

one recursive callwe make

this is notrecursive

Page 188: van Emde Boas trees

Another look at add

To perform add(x):

Step 1 Determine which B[i] the element x belongs in

Step 3 If B[i] is not empty, add x to B[i]

Step 2 If B[i] is empty, add i to C

u

√u u

√u u

√u u

√u

√u

C

B[1] B[2] B[3] B[√

u]

min max

37 483

the min isonly stored here

and set the min and max in B[i] to x (adjusting the offset)

x

one recursive callwe make

this is notrecursive

Page 189: van Emde Boas trees

Another look at add

To perform add(x):

Step 1 Determine which B[i] the element x belongs in

Step 3 If B[i] is not empty, add x to B[i]

Step 2 If B[i] is empty, add i to C

u

√u u

√u u

√u u

√u

√u

C

B[1] B[2] B[3] B[√

u]

min max

37 483

the min isonly stored here

and set the min and max in B[i] to x (adjusting the offset)

Now we always make exactly one recursive call

Page 190: van Emde Boas trees

Another look at add

To perform add(x):

Step 1 Determine which B[i] the element x belongs in

Step 3 If B[i] is not empty, add x to B[i]

Step 2 If B[i] is empty, add i to C

u

√u u

√u u

√u u

√u

√u

C

B[1] B[2] B[3] B[√

u]

min max

37 483

the min isonly stored here

and set the min and max in B[i] to x (adjusting the offset)

Now we always make exactly one recursive callbut what happens when the min/max change?

Page 191: van Emde Boas trees

Another look at add

To perform add(x):

Step 1 Determine which B[i] the element x belongs in

Step 3 If B[i] is not empty, add x to B[i]

Step 2 If B[i] is empty, add i to C

u

√u u

√u u

√u u

√u

√u

C

B[1] B[2] B[3] B[√

u]

min max

37 483

the min isonly stored here

and set the min and max in B[i] to x (adjusting the offset)

Now we always make exactly one recursive callx

but what happens when the min/max change?

Page 192: van Emde Boas trees

Another look at add

To perform add(x):

Step 1 Determine which B[i] the element x belongs in

Step 3 If B[i] is not empty, add x to B[i]

Step 2 If B[i] is empty, add i to C

u

√u u

√u u

√u u

√u

√u

C

B[1] B[2] B[3] B[√

u]

min max

37 483

the min isonly stored here

and set the min and max in B[i] to x (adjusting the offset)

Now we always make exactly one recursive callx

but what happens when the min/max change?

Page 193: van Emde Boas trees

Another look at add

To perform add(x):

Step 1 Determine which B[i] the element x belongs in

Step 3 If B[i] is not empty, add x to B[i]

Step 2 If B[i] is empty, add i to C

u

√u u

√u u

√u u

√u

√u

C

B[1] B[2] B[3] B[√

u]

min max

37 483

the min isonly stored here

and set the min and max in B[i] to x (adjusting the offset)

Now we always make exactly one recursive call

Step 0 If x < min then swap x and min

x

but what happens when the min/max change?

Step 4 Update the max

Page 194: van Emde Boas trees

Time Complexity

u

√u u

√u u

√u u

√u

√u

C

B[1] B[2] B[3] B[√

u]

min max

37 483

the min isonly stored here

Page 195: van Emde Boas trees

Time Complexity

u

√u u

√u u

√u u

√u

√u

C

B[1] B[2] B[3] B[√

u]

min max

37 483

the min isonly stored here

We have seen that the operations add and predecessor can be definedso that they make only one recursive call

Page 196: van Emde Boas trees

Time Complexity

The operations lookup, delete and successor canall also be defined in a similar, recursive manner

u

√u u

√u u

√u u

√u

√u

C

B[1] B[2] B[3] B[√

u]

min max

37 483

the min isonly stored here

We have seen that the operations add and predecessor can be definedso that they make only one recursive call

so that they make only one recursive call

Page 197: van Emde Boas trees

Time Complexity

The operations lookup, delete and successor canall also be defined in a similar, recursive manner

u

√u u

√u u

√u u

√u

√u

C

B[1] B[2] B[3] B[√

u]

min max

37 483

the min isonly stored here

We have seen that the operations add and predecessor can be definedso that they make only one recursive call

so that they make only one recursive call

How long do the operations take?

Page 198: van Emde Boas trees

Time Complexity

u

√u u

√u u

√u u

√u

√u

C

B[1] B[2] B[3] B[√

u]

min max

37 483

the min isonly stored here

Page 199: van Emde Boas trees

Time Complexity

u

√u u

√u u

√u u

√u

√u

C

B[1] B[2] B[3] B[√

u]

min max

37 483

the min isonly stored here

Let T (u) be the time complexity of the add operation(where u is the universe size)

Page 200: van Emde Boas trees

Time Complexity

u

√u u

√u u

√u u

√u

√u

C

B[1] B[2] B[3] B[√

u]

min max

37 483

the min isonly stored here

Let T (u) be the time complexity of the add operation

We have that, T (u) = T (√u)+O(1)

(where u is the universe size)

Page 201: van Emde Boas trees

Time Complexity

u

√u u

√u u

√u u

√u

√u

C

B[1] B[2] B[3] B[√

u]

min max

37 483

the min isonly stored here

Let T (u) be the time complexity of the add operation

We have that, T (u) = T (√u)+O(1)

Using substitution and the master method you can show that. . . T (u) = O(log log u)

(where u is the universe size)

Page 202: van Emde Boas trees

Time Complexity

u

√u u

√u u

√u u

√u

√u

C

B[1] B[2] B[3] B[√

u]

min max

37 483

the min isonly stored here

We have that, T (u) = T (√u)+O(1)

Using substitution and the master method you can show that. . . T (u) = O(log log u)

Let T (u) be the time complexity of the predecessor operation(where u is the universe size)

Page 203: van Emde Boas trees

Time Complexity

u

√u u

√u u

√u u

√u

√u

C

B[1] B[2] B[3] B[√

u]

min max

37 483

the min isonly stored here

We have that, T (u) = T (√u)+O(1)

Using substitution and the master method you can show that. . . T (u) = O(log log u)

Let T (u) be the time complexity of the predecessor operation(where u is the universe size)

this holds for all the operations

Page 204: van Emde Boas trees

Space Complexity

u

√u u

√u u

√u u

√u

√u

C

B[1] B[2] B[3] B[√

u]

min max

37 483

the min isonly stored here

Page 205: van Emde Boas trees

Space Complexity

u

√u u

√u u

√u u

√u

√u

C

B[1] B[2] B[3] B[√

u]

min max

37 483

the min isonly stored here

Let Z(u) be the space used by a vEB tree over a universe of size u

Page 206: van Emde Boas trees

Space Complexity

u

√u u

√u u

√u u

√u

√u

C

B[1] B[2] B[3] B[√

u]

min max

37 483

the min isonly stored here

Let Z(u) be the space used by a vEB tree over a universe of size u

We have that, Z(u) = (√u+ 1)·Z(

√u)+O(1)

Page 207: van Emde Boas trees

Space Complexity

u

√u u

√u u

√u u

√u

√u

C

B[1] B[2] B[3] B[√

u]

min max

37 483

the min isonly stored here

Let Z(u) be the space used by a vEB tree over a universe of size u

We have that, Z(u) = (√u+ 1)·Z(

√u)+O(1)

If you solve this you get that. . . Z(u) = O(u)

Page 208: van Emde Boas trees

van Emde Boas Trees

Five operations are supported:

The van Emde Boas (vEB) tree

� add(x) Insert the integer x into S (where x ∈ U )

� lookup(x) Return yes if x is in S, or no otherwise.

� delete(x) Remove x from S

stores a set S of integer keys from a universe U = {1, 2, 3, 4 . . . u} (i.e. u = |U |).

predecessor(k) Return the largest integer x in S such that x 6 k

successor(k) Return the smallest integer x in S such that x > k

k

successor(k)predecessor(k)

1 2 3 4 . . . u

All operations take O(log log u) worst case time

and the space used is O(u)

Page 209: van Emde Boas trees

van Emde Boas Trees

Five operations are supported:

The van Emde Boas (vEB) tree

� add(x) Insert the integer x into S (where x ∈ U )

� lookup(x) Return yes if x is in S, or no otherwise.

� delete(x) Remove x from S

stores a set S of integer keys from a universe U = {1, 2, 3, 4 . . . u} (i.e. u = |U |).

predecessor(k) Return the largest integer x in S such that x 6 k

successor(k) Return the smallest integer x in S such that x > k

k

successor(k)predecessor(k)

1 2 3 4 . . . u

All operations take O(log log u) worst case time

and the space used is O(u)

The space can be improved to O(n) using hashing (see y-fast trees)