What is the definition for the height of a tree?

前端 未结 7 459
南旧
南旧 2020-12-09 16:43

I can\'t seem to find a definitive answer for this, I\'m trying to do some elementary proofs on heaps but here\'s what\'s throwing me off a little bit:

Is an empt

7条回答
  •  一向
    一向 (楼主)
    2020-12-09 17:40

    If your tree is a recursively defined data structure which may be either empty or a node with a left and right subtree (for example search trees, or your heap), then the natural definition is to assign 0 to the empty tree and 1 + the height of the highest subtree to a nonempty tree.

    If your tree is a graph then the natural definition is the longest path from the root to a leaf, so a root-only tree has depth 0. You normally wouldn't even consider empty trees in this case.

提交回复
热议问题