树:节点的深度与高度定义

(考虑深度时,把树看作液体,节点越往下越深;考虑高度时,把树当作建筑,从最深的子孙-地基数上来。节点和兄弟,深度一定相同,高度不一定相同。)

origin:https://stackoverflow.com/a/2603707/2098804

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

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注