You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
AvlTree: insert is O(n) because height/balanceFactor are recomputed recursively (README claims O(log n)) #2235
BinaryTreeNode.height, leftHeight, rightHeight and balanceFactor (lines 25–55) are recursive getters with no caching, and AvlTree.balance() evaluates them on every ancestor. Counting calls to the height getter per insert:
tree size n
500
1,000
2,000
4,000
height calls / insert
2,384
4,390
8,249
15,822
That grows linearly with n, so building a tree is O(n²). Fix: store height on the node and update it on attach and rotation. (Independent of the correctness bugs in #325 and #485.)
Activity