Another solution is to start with a hash set that is initially empty. When somebody requests a delete, add that value to the hash set. That's O(1).
There are several ways to proceed after that.
- When searching for items, if you encounter a node whose value is in the hash set, mark it as deleted and continue the search. You never remove anything from the tree, but nodes that are marked as deleted are no longer "found." You just return the inorder successor.
- When you find an item that was searched for, check the hash set to see if the item was supposed to be deleted. Delete the item and return its inorder successor.
- When searching the tree, whenever you run across a node whose value is in the hash set, delete the node and continue the search.
Of course, you'd remove the value from the hash set whenever you marked a node as deleted or removed a node from the tree.
All three of those give you O(log n) search, and amortize the cost of deletions as part of the search process.
nis very high but always starts with the sequence 1,2..n, as you commented, it seems you'd be looking for a structure to represent ranges of values rather the values themselves.