Are empty Binary Search Trees valid?

前端 未结 7 1277
挽巷
挽巷 2021-01-12 12:48

I have two questions regarding binary search trees, both about empty trees.

  1. Is an empty tree (null) valid?
  2. Is a root node without children valid?
7条回答
  •  囚心锁ツ
    2021-01-12 13:26

    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.

提交回复
热议问题