Non-binary tree height

后端 未结 4 963
盖世英雄少女心
盖世英雄少女心 2021-01-14 11:21

Is there a way to find the height of a tree which is not necessarily binary? There are many algorithms for the height of a binary tree but none of them will work for a non-b

4条回答
  •  独厮守ぢ
    2021-01-14 11:51

    The definition is the same for any tree. The height of a tree is the height of any of its children (plus one). So if you have three children you check all three of them and take the greatest + 1 as your height, recursively.

提交回复
热议问题