0

I tried finding the total number of values in a 2-3 tree using inorder traversal and instead of printing the values in the node, I tried incrementing the initalised int value everytime there is a value; however, this method didn't seem to work.

Is there a more efficient way to count the total number of values in a 2-3 tree?

Xenotion
  • 13
  • 3
  • This has a simple recursive rule - number of elements of a tree is a number of elements contributed by the root plus the number of elements of each subtree. – Eugene Sh. May 25 '22 at 15:37
  • @EugeneSh. oh I actually got it. I made a function that will count the number of values within a node separately and used the general recurrence for a tree and added the num of val in each node recursively. – Xenotion May 25 '22 at 15:52

0 Answers0