Skip to main content

Timeline for Balanced Binary Tree

Current License: CC BY-SA 3.0

3 events
when toggle format what by license comment
Oct 21, 2016 at 11:55 comment added MrBrushy Good points. I simply proposed a method of returning length, on the assumption that an unbalanced tree is invalid / corrected right away and should not be encountered. But that may not be OP's use-case. About storing the isBalanced status on the Node, I also assumed OP wanted an external solution (maybe Node was not extensible?), otherwise both length() and isBalanced() should be methods of Node, and not of Solution!
Oct 21, 2016 at 10:41 comment added Vogel612 the length method does not work, since you can't retrieve the lenght when the tree is unbalanced. It's crucial to understand how the tree needs to be rotated when it's unbalanced and that is only possible when you know the depths of the relevant subtrees. The BalanceStatus class is an interesting idea, it suffers from a different problem though. It would be much easier to store the balance status inside the tree nodes and propagate it back the insertion recursion stack including performing rotations where necessary ... This would completely eliminate the need for the global variable.
Oct 20, 2016 at 13:19 history answered MrBrushy CC BY-SA 3.0