Binary search Tree Insert Delete demo address:
Http://www.cs.usfca.edu/~galles/visualization/BST.html
Careful you should find that each node of the binary search tree is larger than the value of the left descendant node, smaller than the right. The middle sequence traversal of binary search tree is to output the whole tree in order from small to large. Isn't it magical ^o^
How do I find an element in a binary search tree? First, starting from the root, if the value of the root is equal, then return to the root, otherwise if the child than the root of the left, if Biggen go to the right child, and then recursively, until the value is found or not found to return empty.
What about the insert operation? The above lookup algorithm is then inserted into the corresponding location when the lookup fails.
The delete operation is more complex and the algorithm is as follows:
If there is no son: delete directly;
If there is only one son: Place the son on the node after deletion;
There are two sons: you need to find the minimum value from the right subtree and delete it, and assign the minimum value to the currently-deleted node. As shown in the following:
There is also a line tree, and a check set.
Introduction to the course competition for garlic--two-fork search tree Process