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:
- Binary Tree: any node has two maximum leaf nodes. Searching in a binary tree, using DFS or BFS is O|V+E|
- Binary Search Tree: A BST is a tree of ordered nodes. Searching in a binary search tree, using DFS is O|log n|
- Balanced Tree(assuming height-balanced): Maximum number of levels below the root is kept to the minimum. Does being balanced have any effect to the time complexity of search?
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?
n = root; while (n) { if (n.value == target) return n; n = n.value < target ? n.left : n.right; } return NULL;
. No need for a stack (DFS) or queue (BFS) for backtracking since there's no backtracking. – ikegami