What is the difference between tree depth and height?

后端 未结 7 1578
[愿得一人]
[愿得一人] 2020-11-28 00:14

This is a simple question from algorithms theory.
The difference between them is that in one case you count number of nodes and in other number of edges on the shortest

7条回答
  •  时光取名叫无心
    2020-11-28 00:33

    I learned that depth and height are properties of a node:

    • The depth of a node is the number of edges from the node to the tree's root node.
      A root node will have a depth of 0.

    • The height of a node is the number of edges on the longest path from the node to a leaf.
      A leaf node will have a height of 0.

    Properties of a tree:

    • The height of a tree would be the height of its root node,
      or equivalently, the depth of its deepest node.

    • The diameter (or width) of a tree is the number of nodes on the longest path between any two leaf nodes. The tree below has a diameter of 6 nodes.

    A tree, with height and depth of each node

提交回复
热议问题