Van Emde Boas Trees - NYU Media Research Lab
Download
Report
Transcript Van Emde Boas Trees - NYU Media Research Lab
Van Emde Boas Trees
Elif Tosun (252a-aa)
CSC 252 – Final Project
Outline
Introduction
“Silly” Priority Queue
Stratified Tree Structure
Operations on the Stratified Tree Structure
Conclusions
My Contribution
References
Introduction
Main problem in operations for Set Manipulation
Random Access (insert/delete/membership)
Ordered Representation (predecessor/successor)
Some data structures: binary heap, AVL trees,
2-3 trees, etc.
Lower Bounds for a Restricted Universe
Motivation: Enumeration Algorithms
“Silly” Priority Queue
Structure
n = 2k leaves, height = k
Leaves with priorities from {1, 2,…, n}
k-bit representation (root to leaf)
0, for left
1, for right
“Silly” PQ – Structure (Cont’d)
Subset S {1,..,n} Representation
Mark leaves in S and all nodes on the paths
from root to the marked leaves.
“Silly” PQ – (Cont’d)
Sketches of Algorithms
Insert(i)
Delete(i)
Member(i)
Min
Predecessor
“Silly” PQ – (Cont’d)
Sketches of Algorithms
Insert(i)
Delete(i)
Member(i)
Min
Predecessor
“Silly” PQ – (Cont’d)
Sketches of Algorithms
Insert(i)
Delete(i)
Member(i)
Min
Predecessor
“Silly” PQ – (Cont’d)
Sketches of Algorithms
Insert(i)
Delete(i)
Member(i)
Min
Predecessor
“Silly” PQ – (Cont’d)
Sketches of Algorithms
Insert(i)
Delete(i)
Member(i)
Min
Predecessor
“Silly” PQ – (Cont’d)
Sketches of Algorithms
Insert(i)
Delete(i)
Member(i)
Min
Predecessor
Improvements?
Divide and Conquer Strategy.
Start with a tree of height 2k, n = 2^(2k)
Divide the universe {1, …, n} into n^(1/2)
blocks of size n^(1/2). Insert/Delete locally
Run time recurrence:
T(n) = T(n^(1/2)) + 1
Result : T(n) = O(loglogn)
Stratified Tree Structure
Based on Divide and Conquer Approach
mentioned before.
Two types of information available for each
node:
Static Information
Dynamic Information
Static Information
Level: Length of path from a node to its leaves
Rank: x, for greatest divisor 2^x of the level of a node.
For leaves, rank = k+1 where height= 2^k
Position:
Leaves: number in {1, …, n} representing the leaf
Internal nodes:position of rightmost leaf of its
lefthand son.
Canonical Subtree of rank d (CS): Binary subtree
having as a root node of rank >= d, as leaves
descendants at the nearest level of rank >=d.
Static Information(Cont’d)
Left Canonical Subtree(LCS): Includes all
left hand side descendants
Upper Canonical Subtree(UC): Subtree of
rank d, having the node as a leaf.
Lower Canonical Subtree(LC): Subtree of
rank d, having the node as a root.
Reach: LC+UC
Static Information Visualized
Dynamic Information
Internal Nodes:
lmin: leftmost present leaf in LLC(v)
lmax: rightmost present leaf in LLC(v)
rmin: leftmost present leaf in RLC(v)
rmax: rightmost present leaf in RLC(v)
ub: +, if there exists a branchpoint on the path
between the top of LC and v.
-, otherwise
Some definitions…
Branch Point: An internal node with 2
present sons
Active Node: A present node that has at
least one dynamic field that doesn’t equal
null.
Note: For some operations to be done in O(1)
nodes are prevented from being active
unless needed.
Properness Condition
Let v be a present internal node.
V is active
there exists a branchpoint in
the interior of the reach of v.
Note: a leaf is active
root is active
it’s present
set null
Representation of S
1. Leaves corresponding to elements of S
and their ancestors are marked to be
present.
2. Information on which present nodes are
active is computed. – using Properness
Condition
3. Dynamic fields of all active and nonactive nodes are given their proper values.
An Example:
level
rank lmin
lmax
rmin
rmax
ub
t
16
4
a
c
~
~
-
j
12
2
h
h
i
i
-
h
8
3
~
~
a
b
+(j)
i
8
3
~
~
c
c
+(j)
g
6
1
d
d
e
e
-
d
4
2
a
a
~
~
+(g)
e
4
2
~
~
b
b
+(g)
f
4
2
~
~
~
~
~
An Example:
level
rank lmin
lmax
rmin
rmax
ub
t
16
4
a
c
~
~
-
j
12
2
h
h
i
i
-
h
8
3
~
~
a
b
+(j)
i
8
3
~
~
c
c
+(j)
g
6
1
d
d
e
e
-
d
4
2
a
a
~
~
+(g)
e
4
2
~
~
b
b
+(g)
f
4
2
~
~
~
~
~
An Example:
level
rank lmin
lmax
rmin
rmax
ub
t
16
4
a
c
~
~
-
j
12
2
h
h
i
i
-
h
8
3
~
~
a
b
+(j)
i
8
3
~
~
c
c
+(j)
g
6
1
d
d
e
e
-
d
4
2
a
a
~
~
+(g)
e
4
2
~
~
b
b
+(g)
f
4
2
~
~
~
~
~
An Example:
level
rank lmin
lmax
rmin
rmax
ub
t
16
4
a
c
~
~
-
j
12
2
h
h
i
i
-
h
8
3
~
~
a
b
+(j)
i
8
3
~
~
c
c
+(j)
g
6
1
d
d
e
e
-
d
4
2
a
a
~
~
+(g)
e
4
2
~
~
b
b
+(g)
f
4
2
~
~
~
~
~
An Example:
level
rank lmin
lmax
rmin
rmax
ub
t
16
4
a
c
~
~
-
j
12
2
h
h
i
i
-
h
8
3
~
~
a
b
+(j)
i
8
3
~
~
c
c
+(j)
g
6
1
d
d
e
e
-
d
4
2
a
a
~
~
+(g)
e
4
2
~
~
b
b
+(g)
f
4
2
~
~
~
~
~
An Example:
level
rank lmin
lmax
rmin
rmax
ub
t
16
4
a
c
~
~
-
j
12
2
h
h
i
i
-
h
8
3
~
~
a
b
+(j)
i
8
3
~
~
c
c
+(j)
g
6
1
d
d
e
e
-
d
4
2
a
a
~
~
+(g)
e
4
2
~
~
b
b
+(g)
f
4
2
~
~
~
~
~
An Example:
level
rank lmin
lmax
rmin
rmax
ub
t
16
4
a
c
~
~
-
j
12
2
h
h
i
i
-
h
8
3
~
~
a
b
+(j)
i
8
3
~
~
c
c
+(j)
g
6
1
d
d
e
e
-
d
4
2
a
a
~
~
+(g)
e
4
2
~
~
b
b
+(g)
f
4
2
~
~
~
~
~
An Example:
level
rank lmin
lmax
rmin
rmax
ub
t
16
4
a
c
~
~
-
j
12
2
h
h
i
i
-
h
8
3
~
~
a
b
+(j)
i
8
3
~
~
c
c
+(j)
g
6
1
d
d
e
e
-
d
4
2
a
a
~
~
+(g)
e
4
2
~
~
b
b
+(g)
f
4
2
~
~
~
~
~
An Example:
level
rank lmin
lmax
rmin
rmax
ub
t
16
4
a
c
~
~
-
j
12
2
h
h
i
i
-
h
8
3
~
~
a
b
+(j)
i
8
3
~
~
c
c
+(j)
g
6
1
d
d
e
e
-
d
4
2
a
a
~
~
+(g)
e
4
2
~
~
b
b
+(g)
f
4
2
~
~
~
~
~
Operations on the Stratified Tree
Insert: Let l to be the leaf to be inserted.
If (no present leaves exists on l’s side of the tree)
insert as before
Else
compute the fathers of l (=hl) and
the present leaf p (=hp).
if no branchpoint exists on l’s side of CS
hp is present without being active.
hl is present iff hp = hl
Operations- Insert (Cont’d)
if hl is present
insert l under hp = hl
if hl is not present
insert l as a leaf to a node
above hp.
Operations – Insert (Cont’d)
If a branch point does exist on l’s side of CS
hl is present iff it’s active
if hl is active
insert leaf as a child to hl
if hl is not active
insert leaf as a child to a node
above hp
Operations on the Stratified Tree
Delete:
Makes a leaf non-present as well as its ancestors up to the
lowest branch point.
Compute hl
Proceed to the upper branch point of hl
Consider the other son of the branchpoint
Change path from that son to the root of tree so that
hl is not included
Mark as non-present the leaf and the path above
until the “former” upper brachpoint of hl
Operations – Delete(Visualized)
Summary
What is important in these operations is that when
inserting or deleting you only deal with the
canonical subtree of the father of a leaf.
Basically the operations are done on the subtree
of height k, which affects the whole tree of height
2^k, without touching the rest of the tree. And
that’s why the time complexity of operations is
O(loglogn) instead of O(logn).
Conclusions
Comparisons
Implementation
Insert
Extract-Min
Ease of Prog.
Sorted linked list
O(n)
O(1)
Easy
Unsorted linked list
O(1)
O(n)
Easy
Red/Black Tree
O(logn)
O(logn)
Hard
Binary Heap
O(logn)
O(logn)
Easy
Van Emde Boas Tree
O(log logn) O(log logn)
VERY HARD
Conclusions(Cont’d)
Advantages
Efficient PQ to work with VERY large
amounts of data
Disadvantages
VERY difficult to implement
Can’t be used for Real-Valued Priority
Queues.
Space – uses a full tree just for leaves
My Contributions
Research on Subject
Web
Periodicals
Books
LEDA
Reading Papers
UNDERSTANDING the Data Structure
References
P.van Emde Boas, R.Kaas, E.Zulstra. Design and
Implementation of an Efficient Priority Queue.
Mathematical Systems Theory. 1977:vol10, pgs 99-127
P.van Emde Boas. An O(nloglogn) Online Algorithm
for the Insert/Extract Min Problem. 1974
http://www.cs.mcgill.ca/~mwozni/cs251/welcome.html
LEDA
eb_tree.h
_eb_tree.c