Detailed binary search tree (BST)

Detailed binary search tree (BST)

Benpian essay briefly explain data structures - binary search tree ( \ (Binary \, \, the Sort \, \, Tree, BST \) ) term, (hereinafter the "binary search tree" each with \ ( BST \) instead of).

The concept BST

First of all, \ (BST \) is a binary tree.

Which is defined, all of the left subtree root strictly less than the root node, right subtree than or equal to the root node, and the left and right subtrees are \ (the BST \) .

Well understood, very clear very simple definition.

As can be seen, this is a data structure defined by recursively, so it is natural to use a recursive many operations.

BST function

We can see that this binary search tree is to order a number of columns in the manner of a tree arrangement up and said plainly, is an ordered sequence to a tree in the manner of existence. This sequence becomes a tree, to help us to find a certain value, insertions and deletions in this sequence.

I learn \ (BST \) when smoke a lot of bold ideas in here together to say, let the reader laughed.

For example, I was wondering if the look of a certain value, then the complexity of seemingly dichotomous also log look like?

\ (BST \) than it strong, because it also supports insertion and deletion, complexity is \ (log \) level.

I am thinking about again, find and delete it, looks like a linked list can be?

\ (BST \) than it is as strong as it's complexity is \ (log \) level, but the list is \ (O (n) \) is.

Above all, remember \ (BST \) form and function, a word, a useful would be finished (not ......

BST's operations

Contribute

We first think about the process of BST's achievements:

For a set of data is concerned, we have to build BST, then, by definition directly recursive construction, and the root sentenced size, big right away, a little left to go until an empty position, is its location, and insert into it.

But then there will be a few questions.

First, if a set of monotone data hit, BST chain becomes instantly.

This time we either rotate with the balance of BST trees to maintain the balance of BST, either with randomized algorithms to data upset.

If there is to disrupt the data also ignorant circle cute little can go here:

Random array upset

Secondly, because the shape of the tree is unknown, so we open how much space is also unknown.

So we need to be dynamic open point .

Explanation and analysis of the dynamic tube open point will be on the new blog in the future, but also comrades will not self-Oh!

Add elements

Adding elements as in Comparative miss, that is, from the top to find the recursive layers, can be found in the corresponding position inserted into the opinions.

Removing elements

Delete element operation is relatively really want, which is above the layers to find, find this element will be deleted from it. (Emm ... have to be spray-Bo)

Written on the back

BST is actually a pre-balanced tree of knowledge, (this is because the konjac balanced tree come to learn learn BST), because the principle of balanced tree is for the shortcomings we have just mentioned BST: the forms and spatial uncertainty, optimization . The method makes use of BST has been rotated a balanced tree, so will a lot of convenience to our operations related to the tree.

Finally, I wish you all AK IOI!

Guess you like

Origin www.cnblogs.com/fusiwei/p/12628328.html