I have two questions regarding binary search trees, both about empty trees.
I think you're mixing together apples and oranges:
null
is a value in some programming languages, and it is related upon the concrete representation of your implementation of the data structureNow, a tree is an ordered set: nothing more, nothing less. A set can be empty, of course! This means that, in your implementation, something similar to:
MyTree tree = null
represent an empty tree? Well, it depends upon your model.
You can think, for ex., that an empty subtree should be represented by a node without value and with the references to the leafs nullified: in that model, a null
pointer is meaningless from a logical perspective. But this is only one approach! The sentinel-based approach is a joy to program with, but it's memory expansive: you can then model empty nodes with just null. In that case, a null
pointer can be an empty tree.