"Introduction to Algorithms" chapter 12th, Binary search tree

Source: Internet
Author: User

Binary search tree supports many dynamic collection operations, which can be used as a dictionary or as a priority queue.

The time cost of the basic operation of the binary search tree is proportional to the height of the tree, log n level. The expected height of a randomly constructed two-fork search tree is log n.

Each node contains information: Key, satellite data, parent, left child, right child.

12.1 Two Fork Search tree definition:

Left dial hand tree is less than node, right subtree is greater than node.

All keys can be output recursively using the middle order traversal, and the traversal time is O (n)

12.2 Query Binary search tree

The most common operation: Find a specific key,

Additional operations: Successors, precursors, maximums, minimums, all O (h), H is the height of the two-fork search tree.

Find default starts from the root node.

A successor refers to an element that is only larger than its predecessor, which refers only to the element that is smaller than it.

12.3 Inserting and deleting

Inserting elements is simple, and finding the right location is OK.

Deleting elements is difficult,

If you don't have children, you can simply delete them.

If there is only one child, it is OK to connect the children with the father.

If there are two children, first remove its successor,

12.4 randomly constructed two-fork lookup tree

To construct a two-fork search tree: Always insert elements,

The desired height is logn.

Expected complexity of NLOGN

"Introduction to Algorithms" chapter 12th, Binary search tree

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.