avl-tree

The best way to calculate the height in a binary search tree? (balancing an AVL-tree)

末鹿安然 提交于 2019-11-28 15:10:47
I'm looking for the best way to calculate a nodes balance in an AVL-tree . I thought I had it working, but after some heavy inserting/updating I can see that it's not working correct (at all). This is kind of a two-part question, the first part would be how to calculate the height of a sub-tree, I know the definition "The height of a node is the length of the longest downward path to a leaf from that node." and I understand it, but I fail at implementing it. And to confuse me further this quote can be found on wikipedia on tree-heights "Conventionally, the value -1 corresponds to a subtree

Difference between red-black trees and AVL trees

 ̄綄美尐妖づ 提交于 2019-11-28 02:56:47
Can someone please explain what the main differences between these two data structures are? I've been trying to find a source online that highlights the differences/similarities, but I haven't found anything too informative. In what cases would one be preferred over the other? What practical situations make one "better" to use than the other? AVL trees maintain a more rigid balance than red-black trees. The path from the root to the deepest leaf in an AVL tree is at most ~1.44 lg(n+2), while in red black trees it's at most ~2 lg (n+1). As a result, lookup in an AVL tree is typically faster,

Concatenating/Merging/Joining two AVL trees

时光怂恿深爱的人放手 提交于 2019-11-27 10:00:41
问题 Assume that I have two AVL trees and that each element from the first tree is smaller then any element from the second tree. What is the most efficient way to concatenate them into one single AVL tree? I've searched everywhere but haven't found anything useful. 回答1: Assuming you may destroy the input trees: remove the rightmost element for the left tree, and use it to construct a new root node, whose left child is the left tree, and whose right child is the right tree: O(log n) determine and

Difference between red-black trees and AVL trees

…衆ロ難τιáo~ 提交于 2019-11-27 09:10:39
问题 Can someone please explain what the main differences between these two data structures are? I've been trying to find a source online that highlights the differences/similarities, but I haven't found anything too informative. In what cases would one be preferred over the other? What practical situations make one "better" to use than the other? 回答1: AVL trees maintain a more rigid balance than red-black trees. The path from the root to the deepest leaf in an AVL tree is at most ~1.44 lg(n+2),

The best way to calculate the height in a binary search tree? (balancing an AVL-tree)

梦想的初衷 提交于 2019-11-27 09:02:02
问题 I'm looking for the best way to calculate a nodes balance in an AVL-tree. I thought I had it working, but after some heavy inserting/updating I can see that it's not working correct (at all). This is kind of a two-part question, the first part would be how to calculate the height of a sub-tree, I know the definition "The height of a node is the length of the longest downward path to a leaf from that node." and I understand it, but I fail at implementing it. And to confuse me further this