The tenth day of learning data structure (b) (including some of the guidelines have not learned something)

Guidelines have not learned something: For the bst in sequence, after the non-recursive? ?

As for why this avl tree rotation is logN this fact, I do not know.

 

 

Look here: the underlying storage structure avl tree is not to say: not bst tree, but that the same way: a storage root and size, reason: remove it and add operations and general bst not the same.

It took a long time, and finally to the wording avl tree somehow, learn the technical details:

 

 

 

 

Thinking course to learn:

1.Math this library is built, the direct use Math on it, do not take what library import

2. For the Node, the need to add height to this field, this is to look in the end is how much height, higher up, the higher the root.

3.height represents the level and height, the higher up, the height is high. This purpose is introduced node: go to a depth difference between the detected left and right subtrees is greater than 1, i.e. whether the equilibrium condition. If greater than 1, then it is identified as unbalanced.

 4.

 

 

 This is to determine whether the binary search tree of a function, that is, after preorder see if from small to large.

If the non-small to large order, then it is not a binary search tree.

5. For a recursive tree or the like, it is necessary to figure out what the function is defined, what you need to get the value returned by this function is?

Returns: the height of the root? Or the height of the sub-rooted tree.

 

6. For special cases, the distinction between themselves about, sometimes, and exports are the same meaning, different and sometimes export, and export to distinguish.

public int getHeight (Node node) // height of the definition, return to the root node of the tree height
// key: return must be clear that the current node, or that the return is based on the height of the tree is the root node of
{
IF ( node == null) // in fact, let me see here, except to say: as a special case, in fact, exports are one of the special circumstances and the feeling of
return 0; // empty tree height is not
the else
{
return Math.max (getHeight ( node.left), getHeight (node.right)) +. 1;
}
}

7. No matter what container bottom have written some of the add remove the like.

8. The concept of balance factor: the height of the left subtree right subtree minus the height. . key: to say that the height minus the right subtree of the left subtree

That is left to subtract the right, to tell you: left and right subtrees differ by 1 and above.

9.

 

 

 balanced about it: identify the function of this position is more able to know how to write.

Positioning function: In node is balanced tree rooted

That is to say:  If the tree is empty, then balanced. If the current is balanced (on the concept of balance factor used here), then go to see the sub-tree is not balanced

If the current is not balanced, then the direct return is wrong.

10.

 

 

 D-meaning

First, figure out: Meaning or so biased (LL)

   

 

 

 First, find out meaning LL, RR meaning of, say in front of the two lines. When it reaches the end, add the two subtrees

For the other two, it also finds its complement structure. Figure F and G 2 are as would be the complement

For left-handed, right-handed meaning it is: For the root node , the handedness.

In fact, it is a concept and corresponding to the LL RR. (L mean counter-clockwise, right-handed means clockwise)

 

 

 This means that:

Remember: T1 T2 In this position, it must be level 1, although grow shorter. But height is determined by the number of its sub-tree by tree by the child's height determined, not by in the location.

But if x and y may fall: Reason: If t1 and t2 is empty is empty, then y then dropped.

If T3 T4 is required is not empty, then x will actually decrease with y decline it?

In fact, less likely.

 

In other words: After the rotation, remember to adjust the height, the height adjustment is very important.

Changing the rotation point of fact subtree pointer changes, x and y.

11.

 

 

 Remember, for the words here, just call, do not do other things.

The reason: For changing the height, we need to add the spot to change after completion. Therefore, to achieve change in the height of its inherent function calls

Rather than that outside calls this interface to do something.

12.

 

 

 Add logic which, in fact this is empty, both a special case, but also export conditions

After adding over its subtree , for this node to change its height

That change in the height of this thing is very important.

13. For the rotation of the timing logic selection:

 

 

 

key: mean: for greater than 1, or less than -1, then to a point where the imbalance described.

So if that is left is less than or equal to 0 ( remember the equal is ok ), which is equal to zero

 

 

 

 

Only you need to know the root imbalance condition is reached, and know imbalance respective directions are the same direction (the same direction can be considered equal to 0) can be.

 

 

 Said here: the need to know  the direction of the root of the subtree is the reverse direction, the reverse must be must be less than 0

 

You can fine chemicals.

When should I choose to rotate knew.

 

 

 The bottom of the first rotation, get answers, and then further on.

 

 

 

 

Double rotation, we need to be rotated to the bottom, and then the upper rotation.

 

 

 

 

 

 First save returnNode then if size-- definitely here to write.

In remove the interface outside do not write size-- reasons: remove the interface will only call it, I do not do other things.

size-- it, because not even around for the next empty, then also find the smallest node, its sub-tree is empty.

 

 

 Because on the outside, then it's returnNode need to see if returnNode is empty, the direct return 

Then there are changes in the height of this thing, but also on the outside to change the logic after remove the height.

Then if the outside is the logic in the rotation.

 

In other words: For field newly added node, the various operations it will affect how this new field, we need to consider

For increased recursive, recursive delete. After the corresponding portions of its child nodes have been processed for this node also needs to be change in height and other operations.

Change the child node    or the node to be noted, recursive return , required for the height of the node, also processed.

After processing the current sub-processes

 

That is for recursive results are returned, how to change the height of this matter, the recursive nature of changes in the height of the returned results. It is through: after completing treatment to resolve a child node to solve the current node.

And:        introduction returnNode first save the current results it is worth learning.

 

avl tree has been finished, and inside I was wrong logic also been revised.

 

 

 

 

 For avl tree to realize map, achieve set Needless to say, in fact, call functions only. Avl as to take a structure of the underlying storage.

 

 

In fact, that is here set and map the logical add just not the same. Add only key, is set to add key and value is the map

Avl tree object introduced: in order not to be degraded into linear form occurs, prevent the worst case have logN

Guess you like

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