How to update the size of an AVL tree efficiently I can do p
How to update the size of an AVL tree efficiently?
I can do
private int size(AVLTreeNode<E> node) {
if (node == null) {
return 0;
}
node.size = size(AVLTreeNode<E> node.left) + size(AVLTreeNode<E> node.right) + 1;
return node.size
}
but when dealing with 20,000 + things in the tree this takes hundreds of seconds.
Solution
Answer :
You can update the size of AVL tree by using loops like :
for(x=0;x<node.size;x++)
{
return node.size
}
Put full code into this loop remove return from my code , also remove this line form perimeters x<bla bla to 20000 . This will keep assigning values to your bla bla node until value of x become 20000 .
