Introduction to the course competition for garlic--two-fork search tree Process

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.