I have two questions regarding binary search trees, both about empty trees.
Is an empty tree (null) valid?
There is no tree if it is empty. Hence the question of validity doesn't arise.
Is a root node without children valid?
Yes. That is a tee with only one element in it.
A binary tree can be defined recursively as:
A single node with either no children, or with two children -
each of which is a binary tree.
Yes both conditions are true. For a binary tree, each node can have zero, one, or two children. If a tree has only a root node and no other node then it is called a NULL tree.
Exactly what an empty tree is of course depends on your implementation, as does the meaning of the word "valid", but in general I would say "yes" to both questions. The empty tree represents the case where the set of entities you are intersted in is empty, and the single node the case where the set contains one entity.
Yes, and yes.
A single node with no children is certainly valid and according to Binary Tree Structure:
A (mutable) binary tree, BiTree, can be in an empty state or a non-empty state:
- When it is empty, it contains no data.
- When it is not empty, it contains a data object called the root element, and 2 distinct BiTree objects called the left subtree and the right subtree.
For completeness, this Wikipedia entry is a pretty useful summary of terminology and the like.