Professional Documents
Culture Documents
AVL:-
AVL tree is a BST where at each node (including the root node) the left sub
sub-tree and the right sub-tree do not differ in height by more than one.
|h L -h R | <= 1
Right Rotation:-
avltree * rotate-right (avltree * t) {
avltree * temp;
temp= t Æ left;
t Æ left = temp Æ right;
temp Æ right = t;
return temp;
}
• Height of a height-balanced (AVL) Tree is guaranteed to be
O(log n) n being the no. of nodes.
• The insertion/deletion step takes at most O(log n) time.
• Each rebalancing step, i.e., rotation (possibly double rotation )
and updation of BF takes a constant amount of time.
• The rebalancing may go up to the root. Thus, there can be at
most O(log n) rebalancing steps.
• Thus the overall complexity of insertion/deletion is O(log n).
2,3 B-tree:-
typedef struct nt {
T k1, k2;
int binary;
struct nt * p1,* p2,* p3;
}23treenode;
B-tree:-
1.Each node ( except possibly the root node ) contains at most d records and at
least d/2records.
2.The root node can have at most d records and as few as one record.
3.An internal node containing k records (1 <= k <= d)
with key values k 1 to k k , have pointers to k+1 subintervals of keys stored in
sub-trees.
4.A leaf node has empty sub-tree sub tree below it. All leaf nodes are at the same
level.