Is there a way to design an iterator over a binary search tree with the following properties?
1. Elements are visited in ascending order (i.e. an in-order traversal)
2. next() and hasNext() queries run in O(1) time.
3. Memory usage is O(1)
I feel O(1) memory is impossible since this is recursive (though all recursions can convert to iteration), with a stack data structure of size H := height of tree.
Similarly, hasNext() need to work through the stack of size H, so O(1) run time impossible
Morris may meet the requirement.