Académique Documents
Professionnel Documents
Culture Documents
Definition:
binary search tree
For any node, the heights of left subtree and
right subtree differ at most 1.
(if differ at most k, called BH(k) tree).
AVL Tree
Insertion:
As normal binary search tree insertion
Reconstruct tree by rotation if some nodes become unbalanced
Deletion:
as normal binary search tree deletion
The node deleted will be either a leaf or have just one subtree (this is true for all
binary search tree deletion)
if the deleted node has one subtree, then that subtree contains only one node
Traverse up the tree from the deleted node checking the balance of each node,
balance the node by rotation if unbalanced
Theorem:
An insertion into an AVL tree requires at most one rotation to rebalance a tree. A
deletion may require log(N) rotations to rebalance the tree.
B-Tree
Similar to Red-Black tree or others, balanced search
tree
Different from other balanced search tree, nodes
may have many children. So mainly used for Disk
I/O.
A node x with n[x] keys
An example of B Tree
Copyright The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Copyright The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
B-tree of degree t
Definition:
Root must have 1 key
Internal node has at least t-1 keys but at most
2t-1 keys, i.e. has at least t but at most 2t
children.
Theorem: hlogt(n+1)/2
Insertion and deletions:
More complicate but still log (n)
Split and merge operation.
Copyright The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
2-3-4 Tree
A B-tree of degree t=2.
So every node has 2,3,4 children.
Recursive definition
B+-Tree:
real application data nodes are leaves, internal nodes are keys through
which the search can be traced to real data.
Treap
Consider as Tree + Heap
-organize the tree as binary search tree by keys
Assign random chosen priorities to nodes, adjust the tree to obey minheap order property
i.e. Assume that all keys are distinct, so do priorities, for any node u,
if v is a left child of u, key[v]<key[u]
if v is a right child of u, key[v]>key[u]
If v is a child of u, priority[v]>priority[u]
Splay tree
(See the end of amortized analysis)
Member(i,S)
Insert(i,S)
Delete(i,S)
Merge(S,S)
Split(i,S)
All based on
splay(i,S), reorganize tree so that i to be root if iS, otherwise, the
new root is either max{k S |k<i} or min{k S |k>i}
Lemma:
Each operation splay(x,S) requires no more
than 3((S)-(x))+1 credits to perform the
operation and maintain the credit invariant.
Theorem:
A sequence of m operations involving n inserts
takes time O(mlog(n)).