Binary Tree length

Instead of counting the nodes in a binary tree each time to get the length of the tree, Can i just have a length private Data that i can increment or decrement each time i insert or delete nodes respectively?
How many times are you going to ask for the size?
I mean maintain that variable will be more costly than one call to the function.

Thinking on list. You don't have a size variable because of the splice function. Does your tree implement something similar?
Last edited on
Topic archived. No new replies allowed.