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

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

问题描述

您好,我对树的深度和直径之间的差异有点困惑.很抱歉,如果它已经问过了,但我找不到它.

Hi Im little confused with the difference between the depth and the diameter of a tree.Sorry if Its already asked but I couldn't find it.

推荐答案

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

      一棵树的直径(或宽度)是任意两个叶节点之间最长路径上的节点个数.下面的树的直径为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.

      顺便说一句,我以非常好的方式看到了树的直径(或宽度):想象你的树是按钮(或圆盘)和(等长)字符串的真实对象.拾取任何节点/按钮,并在空中悬吊树.现在挂得最低的按钮距离您所握持的节点最远.现在,按住最低按钮,然后放开其他按钮.现在挂得最低的按钮是离您所握持的节点最远的节点.直径是您持有的节点与最低的节点之间的节点数.

      By the way, I've seen tree diameter (or width) been demonstrated in a very nice way: imagine your tree is a real object of buttons (or discs) and (equal length) strings. Pick any node/button and hold the tree by it in the air. The button that now hangs lowest is farthest away from the node you're holding. Now hold that lowest button and let go of the other. The button that now hangs lowest is is the node that is farthest away from the one you're holding. The diameter is the number of nodes between the one you're holding and the lowest one.

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

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