Title: Finger search trees
1Finger search trees
2Goal
Keep sorted lists subject to the following
operations find(x,L) insert(x,L) delete(x,L) cate
nate(L1,L2) Assumes that all items in L2 are
greater than all items in L1. split(x,L)
returns two lists one with all item less than or
equal to x and the other with all items greater
than x.
3Goal (cont)
In addition, we want to speed up operations near
the ends of the list.
Take a regular search tree and reverse the
direction of the pointers on the leftmost and the
rightmost spines (paths).
4Finger 2-4 trees
. . . . . . . .
. .
. . . . . .
3
1
12
18
15
14
20
28
21
40
5Finger 2-4 trees
Start the search in parallel from the leftmost
and rightmost nodes on the spines.
Search for an element at distance d from one of
the endpoints of the list takes O(log d) time.
Insertions and deletions still take O(log n)
worst case time but O(log d) amortized time
(including the search time).
6Finger trees catenation
Like for regular trees but the search on the
spine of the tall tree for a node of the same
height as the small tree starts from the lowest
node on the spine.
7Finger trees catenation (cont)
Catenation takes O(log n) on the worst-case But
amortized O(1 minh1, h2) O(1 minlog
(n1), log (n2))
8Splitting finger search trees
Catenate bottom-up trees to the left of the path
from v to x and to the right of the path from v
to x. Obtain T1 and T2. Delete v as a child from
p(v), rebalance as in deletion. Obtain T3.
P(v)
v
x
9Splitting finger search trees (cont)
Make T1 and T2 finger trees. Fix the spine of
T3. Return T1 and the tree obtained from the
catenation of T2 and T3.
v
x
T3
T2
T1
10Split -- analysis
Split takes O(log n) worst-case. But O(log d)
amortized.
11Homogenous finger search trees
Want to be able to get from every element to
every other element in time proportional to the
logarithm of the distance between them.
d
O(log min d, n-d)
12Homogenous finger search trees (cont)
Add level links.
. . . . . . . .
. .
. . . . . .
3
1
12
18
15
14
20
28
21
40
13Search
Start from x and search for y. Say x lt y. Keep
going up until one of the following conditions
holds 1) You hit the right path of the tree 2)
Your right neighbor has a key which is not
smaller than y 3) You are on the left path and
your neighbor on the right path has a key smaller
than y
Search down one or two subtrees
14Search (analysis)
Suppose the search went up to level h. Consider
the node x reached on the way up on level
h-1. The leftmost subtree of the right neighbor
of x contains only items larger than x and
smaller than y. gt d ? 2h-2 The rightmost
subtree of the left neighbor of x contains items
either smaller than x or larger than y. gt n-d
? 2h-2
152-pivot split
Split(x,y)
x
y
162-pivot split
Like in searching for y from x. We go up
concurrently from x and y until reaching a node e
which is an ancestor of both x and y or
reaching a pair of adjacent nodes e and f on the
same level such that e is an ancestor of x and f
is an ancestor of y.
e
f
x
y
172-pivot split
Case 1 (f does not exists) Detach the subtree T
rooted at e from its parent. Split T at x into T1
and T2. Split T2 at y into T3 and T4. Catenate T1
and T4 into T5. If the height of T5 is smaller
than e then add unary nodes to make it of the
same height as e. Replace e with that tree and
eliminate unary nodes. If the height of T5 is
larger than the height of e split it into two
trees replace e with those trees and eliminate
the 5-node that may have been created. Return the
modified original tree and T3.
182-pivot split (cont)
Case 2 (f exists and is not on the right spine)
Similar to previous case.
e
f
x
y
192-pivot split
Case 3 (Wrap around) Detach the subtree T rooted
at e from its parent. Fix the resulting tree T
if the parent of e becomes a 1-node. Split T at x
into T1 and T2. Catenate T2 with T. Work
symmetrically with f to obtain T4 of items
greater than y. Catenate T1 and T4.
e
f
x
y
202-pivot split (analysis)
Recall, eliminating a 1-node or a 5-node takes
O(1) amortized time gt 2-way split takes
O(log mind, n-d) amortized time.