Reputation: 2865
Can there exist a balanced binary tree that is not a balanced binary search tree? If so, what would the time complexity be to search a node in such a tree.
My understanding is this:
So, essentially, can I create a binary tree that is height-balanced but not ordered. Would the search time of this tree be O|V+E| or will it be better?
Upvotes: 1
Views: 586
Reputation: 385849
Searching an unordered binary tree requires visiting every node, so it's O(N) whether it's balanced
50
__/ \__
/ \
25 26
/ \ / \
49 46 48 47
or not
50
__/ \__
/ \
25 26
/ \
49 46
/ \
5 6
There's really no point in balancing an unordered tree.
Upvotes: 5