只有一个节点的树的高度 [英] Height of a tree with only one node

查看:22
本文介绍了只有一个节点的树的高度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据维基百科,

树的高度是从根到树的路径的长度树中最深的节点.一棵只有一个节点的(有根的)树(root) 的高度为零(或一).

The height of a tree is the length of the path from the root to the deepest node in the tree. A (rooted) tree with only one node (the root) has a height of zero (or one).

我不明白 - 它是零还是一(或两者)?

I dont get it - is it zero or one (or both)?

推荐答案

这只是您对二叉树高度的递归描述所做的假设.您可以考虑仅由高度为 0 或高度为 1 的节点组成的树.

It just an assuption you make for the recursive description of the height of a binary tree. You can consider a tree composed by just a node either with 0 height or with 1 height.

如果你真的想以某种方式考虑它,你可以这样想

If you really want to think about it somehow you can think that

  • 如果您将高度视为边数,则为 0(因此单个节点没有任何边,因此为 0)
  • 如果将高度视为节点数,则为 1(因此单个节点计为 1)

这只是为了描述最小树有多少高度,那么无论如何,无论何时添加降序节点,您都会添加相关边,因此它会相应增加.

This is just to describe how much height the smallest tree has, then in any case whenever you add a descending node you will add also a related edge so it will increase accordingly.

在维基百科提供的示例中:

In the example provided in wikipedia:

这棵树的高度可以是 4(节点)或 3(边).这取决于您是按边数还是按节点数.

This tree can have height 4 (nodes) or 3 (edges). It depends if you are counting it by edges or by nodes.

这篇关于只有一个节点的树的高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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