[BST] Binary Search Tree

Source: Internet
Author: User

A binary search tree is also called a binary sorting tree. It has the following properties:

The root node value is greater than the value of all nodes in the left subtree and less than the value of all nodes in the right subtree.

Therefore, the central order traversal of the binary sorting tree is an incremental ordered sequence.

In the caseAlgorithmAccording to its nature. For example, determine whether a given int-type array is the result of the post-order traversal of a binary sorting tree. If the result of the post-order traversal is ABC, A <C <B. Therefore, starting from the root node (the last node, find all consecutive values greater than the root node as its right subtree, and then forward until the first element of the array. If they are smaller than the root node, use them as the left subtree, then, the left and right Subtrees are recursion using the same method. If there is a value greater than the root node in the forward direction, instead of the result of post-sequential traversal of the Binary Search Tree, return false directly. The time complexity is about O (nlogn ).

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.