-1

My purpose is to first locate(search) a certain node in the tree(AVL or balanced binary tree), and then count the number of nodes which are under it. The whole operation works in O(logn) times. Is it achievable?

  • 2
    When asking a question, it is suggestable to add any code implementation you have already made, result analysis, error logs, etc.. Thanks. – Marco Tizzano Apr 29 '21 at 14:18

1 Answers1

0

Yes it is, for that you need an implementation of AVL that keeps for each node the number of nodes that it has in its sub-tree. Now, you only need to locate the desired node, and then look in its 'size' field to know how many nodes are in its sub-tree.

e.ad
  • 380
  • 2
  • 10