树的深度和高度有什么区别? [英] What is the difference between tree depth and height?

查看:20
本文介绍了树的深度和高度有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个来自算法理论的简单问题.
它们之间的区别在于,在一种情况下,您计算根节点和具体节点之间最短路径上的节点数和其他边数.
哪个是哪个?

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 that depth and height are properties of a node:

  • 节点的深度是从节点到树根节点的边数.
    根节点的深度为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.

树的属性:

  • 树的高度将是其根节点的高度,
    或等效地,其最深节点的深度.

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

树的直径(或宽度)是任意两个叶节点之间最长路径上节点的数量.下面的树的直径为 6 个节点.

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.

这篇关于树的深度和高度有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆