Binary search Tree

Source: Internet
Author: User

Binary search Tree

Defined:

Binary search tree is organized by a binary tree. The keywords in binary search are always stored in a way that satisfies the nature of binary tree search.

Set X is a node in a two-fork tree. If Y is a node in the X left dial hand tree, then Y.key <= X.key.

If Y is a node in the X right subtree, then Y.key >= X.key.

Analysis of the algorithm:

If we choose the middle order to traverse the entire binary tree. For example

6

5 7

2 5 8

Such a binary tree, (the middle line itself imagines).

Inorder-tree-walk

1 if x! = NULL

2 Inorder-tree-walk (x, left)

3 Print X.key;

4 Inorder-tree-walk (x, right)

Very simple we can get the results of the sequence traversal of the tree: 2 5 5 6 7 8


The time to traverse a two-fork search tree with n nodes is: Θ (n)

Prove:

Use T (n) to indicate the time required, since the middle order requires access to all n nodes of the tree, so there is t (n) =ω (n), as long as the t (n) = O (n) is shown below.

For an empty tree, you need to consume a very small constant time C, for a constant,c>0; has t (0) = C;

n > 0, if there are k nodes on the left subtree of x, then there are n-k-1 on the right subtree;

For t (n) there is t (n) <= t (k) + t (n-k-1) +d; D >0;

Use substitution method: T (N) <= (c+d) n +c; It can be concluded that T (n) = O (n);


















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.