Вы находитесь на странице: 1из 12

Treaps T-Treaps

1. Randomized Treaps .......................................................................................................................... 2


1.1 Treaps ..................................................................................................................................... 2
1.2 BST....................................................................................................................... 3
1.3 .................................................................................................................................... 5
1.4 ........................................................................................................ 6
1.5 ...................................................................................................................... 8
2. T-Treaps ........................................................................................................................................... 8
2.1 .............................................................................................................................. 8
2.2 BST....................................................................................................................... 9
2.3 ...................................................................... 11
2.4 T-Treap ........................................................... 11
2.5 ............................................................................................................................... 12
........................................................................................................................................ 12
.................................................................................................................................. 12

, 2006
http://rain.ifmo.ru/cat/

1. Randomized Treaps
1.1 Treaps
,
, .
, . Treap ,
BST (binary search tree), , .
, treap BST heap .

. 1. Treap. , .

, .
, treap
. heap, V
. BST, U, key(U) < key(V),
, . , treap,
, treap .
treap.
, treap BST,
.
treap
, 2006
http://rain.ifmo.ru/cat/

. treap , .
. ;
.
, .
[1].

. 2. treap, . 1.

Treap (Jean Vuillemin) 1980 ,


. treap
(Edward McCreight) 80- ,
, treap PST (priority search
trees). Treap (Cecilia Aragon)
(Raimund Seidel) 1989 .

,
(Conrado Martnez) (Salvador Roura) 1996 .

1.2 BST
, BST.
.
( ). K,
, 2006
http://rain.ifmo.ru/cat/

BST.
BST, heap-order.
, K,
, . K .
, K.

. 3.

3 ( 1, 2, 3, 4) (G, 0):
BST heap-order .
, (G, 0):
, , .
, , .
, V. V , V
, . V
, 2006
http://rain.ifmo.ru/cat/

.
heap-order V. V , .
treap T 2 treap T1 T2 -
K , T1 K, T2 .
K -.
treap, T1 T2
. treap
K.
treap T1 T2,
T1 T2.
T1 T2,
.

1.3
d(V) - V
treap.

: K O(d(V)), key(V) = K.
, Vleft Vright K
. Vleft,
Vright, O(d(Vleft))
O(d(Vright)).

/: V O(d(Vleft))
O(d(Vright)). .

/: treap K O(d(Vleft))
O(d(Vright)),
K -. treap ,
, .
treap (n), n

, (n).
, 2006
http://rain.ifmo.ru/cat/

1.4
treap,
. , ,
0 1,
.
. treap.

. ,
, - ,
.
, ,
- treap. ,
O(log n). ,
O(log n).
x[k] k- .
A, 0 1 ( ):
A(i, k) = (x[i] x[k])
, d(V) - V,
:
n

d(x[k]) =

A(i, k)

i =1

,
:
n

E(d(x[k])) =

Pr[A(i, k) = 1]

i =1

E , E[X] = Pr[X=1] X.
, ,
i k.
, .
: X(i, k) {x[i], x[k]} {x[k],x[i]},
, 2006
http://rain.ifmo.ru/cat/

i k (i < k i > k). X(i, k) X(k, i)


, |k - i| + 1.
: i k , x[i] x[k] , x[i]
X(i, k).
: x[i] , x[k]
, , X(i, k).
, x[k] , x[i] x[k], x[k]
treap; , x[i]
X(i, k).
, - x[m] . , x[i]
x[k] , i < m < k i > m > k, , x[m]
X(i , k). x[i] x[k], X(i, k)
m.
, x[i] x[k] ,
, treap. treap

X(i, k) ,
:

k 1i +1 , i < k

Pr[ A(i, k ) = 1] = 0, i = k
1 , i>k
i k +1
x[k],
:
n

E[d ( x[k ])] = Pr[ A(i, k ) = 1] =


i =1

k 1

n
1
1
+
=
i =1 k i +1 i =k +1 i k +1

= H k 1+ H nk 1 < ln k + ln (n k) 2 < 2 ln n 2
, 2006
http://rain.ifmo.ru/cat/

: , , ,
n- treap O(log n).
treap ,
, treap
. ,
,
( ).

1.5
Treap , (
), . ,
treap [2] . [3] , treap
RBT (red-black trees)
. , treap , RBT. [4]
treap DVD .
[5], treap
. [6] treap
, , , treap BST. [7]
treap .

2. T-Treaps
2.1
T-Treap
, , treap,
. T-Treap
,
.
, . T-Treap
.

, 2006
http://rain.ifmo.ru/cat/

T-Treap ,
.
. ,
, .

. 4. T-Treap: V , p .

. 5. T-Treap.

, -
,
.

2.2 BST

, BST. ,
. , ,

. T-Treap, ,
,

, . -
9
, 2006
http://rain.ifmo.ru/cat/

(, ),
.

: -
, . ,
, ,
.

T-Treap,
, .
, .
T-Treap

.
.
, .
, .

, , ,
T-Treap.
, . ,
,
, treap .
, ,
.
,
. ,
.
.
, .
.
- ,
,
, 2006
http://rain.ifmo.ru/cat/

10

, ,
, .

2.3
- , T-Treap ,
, , , T-Treap
. ,
. : Min, Max Avg (Average),
. Min Max
, , ,
.
. Avg
.
, , T-Treap
heap-order. , treap,
heap-order.
heap. , T-Treap
.

2.4 T-Treap
T-Treap .
.
[8]. T-Treap,
,
. , T-Treap
, ,
.
T-Treap.
, . [8]
T-Treap O(log (N/X)), X , N .

, 2006
http://rain.ifmo.ru/cat/

11

2.5
T-Treap . [8]
,
. , ,
T-Treap,
.

1. . C++: . .
.: , 1997. 304 .: .
2. Jeff Erickson. Randomized treaps // University of Illinois at Urbana-Champaign. CS373
lecture notes. 2002.
3. Dominique A. Heger. A Disquisition on The Performance Behaviour of Binary Search Tree
Data Structures // Cepis Upgrade Journal. Vol. 5. October 2004. 5, p. 67-74.
4. Jim Moiani, Michael Crocker. DVD Library System // University of Notre Dame. CSE 331
data structures. 2003.
5. Hugh E. Williams, Justin Zobel, Steffen Heinz. Self-adjusting trees in practice for large text
collections // Software: Practice and Experience. Vol. 31. August 2001. 10, p. 925-939.
6. Kenny Wong, Hausi A.Muller. An Efficient Implementation of Fortunes Plane-Sweep
Algorithm for Voronoi Diagrams // Technical Report DCS-182-IR. 1991, p. 8-9.
7. Albrecht Schmidt, Christian S. Jensen. Efficient Management of Short-Lived Data // A
TIMECENTER Technical Report. 2005.
8. Joshua P. MacDonald, Ben Y. Zhao. T-treap and Cache Performance of Indexing Data
Structures // University of California, Berkeley. CS252 course projects. 1999.

9. Randomized binary search trees.


10. .

, 2006
http://rain.ifmo.ru/cat/

12