简体   繁体   中英

Binary search tree search operation

我想知道二叉搜索树必须是什么才能有效地搜索它。

In order to efficiently search a binary search tree, the tree must be balanced . That is, the left and right subtrees of each node have approximately the same number of children. When a binary search tree is perfectly balanced, searching it is an O(log n) operation. A degenerate tree, on the other hand, has all of the nodes on the right (or left) subtree. Searching that is like searching a linked list: O(n).

See the Wikipedia article, Binary search tree , for more information.

The tree needs to be self-balancing, which means that the height of the tree is minimized while keeping the binary search tree properties. Search for AVL tree or self-balancing tree for more info. Binary search performed on an AVL tree results in an O(logn) runtime, whereas binary search on a normal BST results in an O(n) runtime.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM