树的深度和高度之间的区别是什么?深度、高度、区别

2023-09-11 01:53:15 作者:悲哀寸步不离

这是从算法理论的一个简单的问题。它们之间的区别是,在一种情况下算上节点和在根和混凝土节点之间的最短路径上的边缘的其它数数。哪个是哪个?

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 path between root and concrete node. Which is which?

推荐答案

我了解到它作为一个的节点的具有深度和高度:

I learned it as a node having a depth and height:

在深度节点是从节点到树的根节点边的数量。一个根节点将有0的深度。

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.

在高节点是边缘上的 的从节点到叶。叶节点将有多少的高度为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.