5-10 the limitations of the binary search tree

Source: Internet
Author: User

Binary finds the performance of the tree. Binary search trees do not perform well in some extreme situations.

We first need to know the following fact: the same data, can correspond to different binary search tree. Look at the following example.

A binary search tree can degenerate into a linked list. At this point the time complexity becomes O (n).

Extreme testing: If the key is sorted and then inserted into the binary search tree, then the height of the binary search tree becomes very high.

Solution: Balance binary tree, use red black tree (red black tree is a kind of balanced binary tree realization, other balanced binary tree implementation also has 2-3 Tree,avl tree,splay tree, balanced binary trees and heap combination: treap). The height difference between the left and right two subtrees trees will not exceed 1.

Trie Use Trie to count the word frequency.

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.