Given a binary search tree (BST). Find the maximum depth of the binary search tree iteratively.
I know the method using queue [level order traversal] but time complexity is O(N) as we need to visit the whole tree.
But it doesn’t use the information whether the tree is a BST or binary tree.
Does the algorithm remain the same for the BST or it can be improved using the fact that the given tree is BST?
I don’t think the fact that a tree is a BST or not changes anything to it, you still have to in the worst case visit all nodes, which makes it O(N). I guess in the best case you’d only have to do O(log(N)), but that’s the best possible case, where you just go down the depth of the tree, and visit no other nodes.