Complexity of a nested binary search tree

Deadly 提交于 2019-12-12 06:10:18

问题


Does anyone know how to calculate the complexity of a nested binary search tree? I have implemented a nested binary search tree to a depth of 3 BSTs.

EDIT: I apologize for the confusion, I had meant that each node of the BST would point to the root node of another BST. The complexity I was asking for was time complexity of search, update, and delete (basic operations). I had assume that since the time complexity of a BST was O(log(n)), the time complexity of a nested BST in terms of search, update, and delete wouldn't differ that much.


回答1:


I'm assuming that by "nested" you mean that each node of a particular tree points to the root of another tree, up to 3 levels deep.

Well a binary search tree is generally going to be O(log n) lookup time. Since you're doing 3 lookups, that's O(log a * log b * log c). Of course that's assuming that they're well balanced and everything. The worst case for a binary search tree is O(n) (think of a tree where it's basically a straight line). Then the worst case time would be O(a * b * c).

And for the record, a b and c are the number of elements in the first tree, second nested tree, and third doubly-nested tree, respectively.



来源:https://stackoverflow.com/questions/5572454/complexity-of-a-nested-binary-search-tree

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!