【问题标题】:Can I count the number of nodes under given node in AVL tree and balanced binary trees in O(logn) time?我可以在 O(logn) 时间内计算 AVL 树和平衡二叉树中给定节点下的节点数吗?
【发布时间】:2021-04-29 12:55:55
【问题描述】:

我的目的是首先定位(搜索)树(AVL或平衡二叉树)中的某个节点,然后计算它下面的节点数。整个操作在 O(logn) 时间内进行。可以实现吗?

【问题讨论】:

  • 在提出问题时,建议添加您已经完成的任何代码实现、结果分析、错误日志等。谢谢。

标签: data-structures binary-tree avl-tree


【解决方案1】:

是的,因为您需要一个 AVL 实现,为每个节点保留其子树中的节点数。 现在,您只需找到所需的节点,然后查看其“大小”字段即可知道其子树中有多少个节点。

【讨论】:

    猜你喜欢
    • 2020-08-25
    • 1970-01-01
    • 1970-01-01
    • 2021-07-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多