Implementation of left.
Splay trees are self-adjusting binary search trees i.e., they adjust their nodes after accessing them. So, after searching, inserting or deleting a node, the tree will get adjusted. Splay trees put the most recently accessed items near the root based on the principle of locality;"rule" which states that 10% of the data is accessed 90% of Estimated Reading Time: 3 mins.35 Splay Trees Splay trees are Binary_Search_Trees on which ``splaying'' operations are performed.
A node in a Binary_Search_Tree is"splayed" when it is moved to the root of the tree by one or more"rotations". Whenever a node is accessed (Find, Insert, Remove, etc.), it is splayed, thereby making it the root.
As we can see, the right child of the 15 is NULL, so we attach node 17 at the right part of the 15 as shown below, and this operation is known as a join operation.
伸展树(Splay Tree)是一种二叉排序树,它能在O(log n)内完成插入、查找和删除操作。它由Daniel Sleator和Robert Tarjan创造。它的优势在于不需要记录用于平衡树的冗余信息。在伸展树上的一般操作都基于伸展操作。.splay_tree_remove (splay_tree sp, splay_tree_key key) { splay_tree_splay (sp, key); if (sp-> root && (sp-> comp) (sp-> root-> key, key) == 0) { splay_tree_node left, right; left = sp-> root-> left; right = sp-> root-> right; / Delete the root node itself.
/ if (sp-> delete_value) (sp-> delete_value) (sp-> root-> value); All splay tree operations run in O(log n) time on average, where n is the number of entries in the tree. Any single operation can take Theta(n) time in the worst case. Search Operation The search operation in Splay tree does the standard BST search, in addition to search, it Estimated Reading Time: 4 mins.A Splay tree is a self-adjusting binary search tree invented by Sleator and Tarjan. Unlike an AVL tree (or a Red-Black tree), the structure of the splay tree changes even after the search operation.
Every time we search an item x or insert x, it moves x to the root of the tree so that the next access of x Estimated Reading Time: 8 mins.void update(int x) { tree[x].size=tree[tree[x].ch[0]].size+tree[tree[x].ch[1]].size+1;//记得加上自身的那一个,这一点和线段树不一样 tree[x].ma=max(max(tree[tree[x].ch[0]].ma,tree[tree[x].ch[1]].ma),tree[x].key);//这里可以特判一下,防止x的儿子是哨兵或者0,影响.