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

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

问题描述

根据Wikipedia

According to Wikipedia,

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

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天全站免登陆