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.