Elaborate on the process to achieve a balanced tree Splay

Preface:

Author splay written mainly by https://www.luogu.org/blog/tiger0132/slay-notes impact of this article, so the code to achieve the basic repeat, this is mainly to make it clear that article did not elaborate on where


Splay, also known as stretch tree is a balanced tree (konjac I will only write one kind QWQ)

Speaking before the balance of the tree, you must first understand what is a binary search tree

Binary search tree, also known as binary search tree is a data structure complexity of query optimization numbers, he left to meet the strict node is less than the root node and right node is greater than the root

So every time to find a specific value, as long as it continues to compare the size of the current node, choose to go left or right son son go, we will be able to find the number to be found, the next figure is a standard binary search tree: (drawing random drawing, ugly QWQ)

It is a good example of the figure, and why? Because it happens to be a complete binary tree, that is, you query any number of complexity can be stable in O (log n) level

But really every time that right? :

The figure is the Fengyun search tree on the order of insertion of reasons devolved into a chain, in the worst case a digital query actually reached O (n) level, which is obviously not what we can accept

(to be continue)

Guess you like

Origin www.cnblogs.com/Takarada-Rikka/p/11318905.html