Algorithm Crash (vi) Five classic search binary sort tree

Source: Internet
Author: User
Tags sort

Do you feel that the tree in the data structure of the big line, what areas should be stained with a touch.

Take us a few days ago to learn the sort used to the heap and today said "binary sorting tree", so Extreme said, master of the tree you are cattle.

Today we'll talk about the last "binary sort Tree" in the "Five Classics" search.

1. Concept:

<1> is actually very simple, if the root node has a Zoozi tree, then all nodes of the left subtree are smaller than the root node.

If the root node has a right subtree, all nodes of the right subtree are larger than the root node.

The <2> diagram is a "binary sort Tree", which is then compared against the concept of a comparison.

2. Actual operation:

We all know that a thing to operate, nothing more than to check and change, then we will talk about the basic operation.

<1> Insert: I believe that the concept of "sorted tree" is clear, then the principle of insertion is very simple.

Let's say we insert a 20 into this tree.

First: 20 compared with 50, found that 20 is the youngest, the last resort, to be summed up to 50 of the left subtree to compare.

Then: 20 compared with 30, found that 20 or the youngest.

Then: 20 compared to 10, found himself the eldest, and then inserted into the 10 right subtree.

Finally: The effect rendering diagram is as follows:

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.