If a problem of size N can be broken into subproblems, a method to solve the problem can be implemented by writing and calling methods for each of the subproblems.
If the subproblems are the same as the original problem, but just of smaller size M, then instead of writing different methods for the subproblems, the same method can be use. That is, the method for the original problem can call itself to solve the subproblems. That is, the method can be recursive.
The "problems" for the BSTSet are put, get, and delete. Can these methods be recursive? Why should they be?
The reason they can be recursive is because of the recursive nature of the binary tree itself:
A binary search tree is either:
- empty, or
- a left subtree, a root, a right subtree
For example, to put a key into a non-empty tree, reduces to a subproblem: put the key into the appropriate subtree. So the subproblem is the same as the original problem. Put a key an a binary search tree.