What does this article introduce?
What is the effect of using a stretching tree;
The definition of a stretching tree;
The description of the concrete implementation process of the extensional tree ADT;
Code implementation.
The effect of using a stretch tree (splay trees):
When using the stretch tree, the worst run time for any operation on the stretch tree is O (N), but it guarantees that the maximum time for a continuous M operation is O (m㏒n), so that the amortization time for each operation of the stretch tree can be calculated as O (㏒n).
Second, the definition of stretching tree:
For a binary lookup tree operation, each access node is placed on the root by a rotation operation. Such a binary search tree is called a stretch tree.
Iii. description of the extensional tree ADT:
1. The node definition of the extension tree is consistent with the method defined by the two lookup tree nodes, which is not mentioned here;
2. Compared to the two search tree, the stretch tree ADT is just a rotation operation. Here's the spin that we call the unfold (splaying). Set node x as the Access node, we move node x to the root node by a series of operations on Node X.
3. Node x rotation Condition:
⑴ node x is the root node: do nothing;
The parent node of ⑵ node x is the root node:
The right sub-tree of the left subtree of the root node =x;
Right sub-tree of x = root node;
⑶ node x has a parent node (P), a grandparent node (G), and there are (class two) four scenarios to consider:
Ⅰ, ("one" glyph) p is the left son of G, X is the left son of P;
Ⅱ, ("one" glyph) p is the right son of G, X is the right son of P;
Ⅲ, ("the" glyph) p is the left son of G, X is the right son of P;
Ⅳ, ("the" glyph) p is the right son of G, X is the left son of P;
4. Deletion of nodes:
Because every access to node x needs to move x to the root node, lazy deletion is inappropriate here, and it needs to be removed directly here. When the delete operation, the first need to access node X, node x is moved to the root node, at this time the cost of deleting x is relatively small. When deleting node x, ① Access x causes node x to be moved to the root node, delete node x and get left and right two subtrees trees (TL, TR); ② accesses the minimum node Y on the right subtree TR (the node must have no left son), moves y to the root of the right subtree, and ③ leaves the left son of Y as the left dial hand tree TL
Four, the core code implementation:
1. Stretching the tree to achieve
Ⅰ, ("one" glyph) p is the left son of G, X is the left son of P;
Operation:
The right son of =p, the left son of G;
P's right son =g;
P's left son =x's right son;
X's right son =p;
One glyph (left left) static Position Zigzigll (Position g) {Position p,x; p=g->left;x=p->left; g->left=p->right; p->right=g; p->left=x->right; x->right=p; return x;}
Ⅱ, ("one" glyph) p is the right son of G, X is the right son of P;
Operation:
G's right son =p's left son;
P's left son =g;
P's right son =x's left son;
X's left son =p;
One glyph (right-right) static Position Zigzigrr (Position g) {Position p,x; p=g->right;x=p->right; g->right=p->left; p->left=g; p->right=x->left; x->left=p; return x;}
Ⅲ, ("the" glyph) p is the left son of G, X is the right son of P;
Operation:
The right son of =x, the left son of G;
X's right son =g;
P's right son =x's left son;
X's left son =p;
One glyph (left and right) static Position ZIGZIGLR (Position g) {Position p,x; p=g->left;x=p->right; g->left=x->right; x->right=g; p->right=x->left; x->left=p; return x;}
Ⅳ, ("the" glyph) p is the right son of G, X is the left son of P;
Operation:
G's right son =x's left son;
X's left son =g;
P's left son =x's right son;
X's right son =p;
One glyph (right left) static Position Zigzigrl (Position g) {Position p,x; p=g->right;x=p->left; g->right=x->left; x->left=g; p->left=x->right; x->right=p; return x;}
3. Implementation of the delete operation of the stretching tree
Delete the node void Delete (const ElementType X,const Stree St) {if (null==st) printf ("The tree is empty tree \ n"); else{position Temp=find (x,st); Position root=findmin (temp->right); root->left=temp->left; Free (temp); Temp=null; return; }}
The tree's stretching tree