The tenth day of learning data structure

The following analysis of the code, purpose of the analysis is to know when to rotate it, what operation to achieve rotation

The second purpose is: to know this after rotation, also how to traverse it?

 

I think the second point to understand a little about the purpose, even if it is rotated, its node is still satisfy the nature of binary search tree, but it is more balanced.

So for finding binary search tree and other operations is unchanged.

 

First began to read through the code and then write.

 

 

The first is on the node, you need to add a height field, it represents the height is.

And is a key stored on the node and value. The purpose is more flexible, so that key and value are separated, key is how much, how much is this value.

 

 

Whether the binary search tree, which is to make after order traversal, after walking inside look at the array elements are not in ascending order of arrangement.

If that is in ascending order of arrangement it is a binary search tree.

 

 Here that is a function: function is balanced.

If the tree is empty, so that this is a balance of the tree.

 

 Get the balance factor function: the height of the left subtree right subtree minus balanced factors, namely the height of the left as the right balance by subtracting the height of a factor.

The reason: unity here that it is the right of the left cut, then the time is balanced, then, is the absolute value, so do not be afraid of this.

 

 Here that is:

For right rotation, certainly under LL situation requires the right rotation.

So right rotation: No matter what the rotation, we need each field node to node have to be considered.

So height fields need to be updated.

 

 

 For leftRotate this function definition is also to know that the root node after rotation!

 

 That is the analysis for the current factor, also left for the factor analysis.

 

 Delete bst when three conditions have to remember to delete nodes.

 

 For avl tree, when to rotate: When adding or deleting time needs to be rotated.

This isBST no place in which to use, but if you know that: the significance isBST: taught me: how to determine after a tree is not a binary search tree, fancy preorder traversal of this tree is not in order of size arrangement.

But the fact is not related to: the tree, and if speaking a traversal of a tree is not sure of it, at least two traversal methods, right?

The following chapter of their own to achieve avl tree.

Guess you like

Origin www.cnblogs.com/startFrom0/p/12639818.html