Questions tagged [avl-tree]

Named after its inventors, Adelson-Velskii and Landis, an AVL tree is a self-balancing binary search tree.

Named after its inventors, Adelson-Velskii and Landis, an AVL tree is a self-balancing binary search tree. They were the first dynamically balanced trees to be proposed.

Like red-black trees, they are not perfectly balanced, but pairs of sub-trees differ in height by at most 1, maintaining an O(logn) search time.

923 questions
14
votes
7 answers

Balancing a Binary Tree (AVL)

Ok, this is another one in the theory realm for the CS guys around. In the 90's I did fairly well in implementing BST's. The only thing I could never get my head around was the intricacy of the algorithm to balance a Binary Tree (AVL). Can you guys…
Gustavo Carreno
  • 9,499
  • 13
  • 45
  • 76
13
votes
5 answers

How to check if my AVL tree implementation is correct?

I have created an AVL tree implementation, but as an AVL tree is quite a complex structure, I need to test it. So the question is - how can I test it? Up to this moment I have the following tests: basic sanity check - checks that for every node…
Graf
  • 1,437
  • 3
  • 17
  • 27
13
votes
4 answers

Finding the minimum and maximum height in a AVL tree, given a number of nodes?

Is there a formula to calculate what the maximum and minimum height for an AVL tree, given a certain number of nodes? For example: Textbook question: What is the maximum/minimum height for an AVL tree of 3 nodes, 5 nodes, and 7 nodes? Textbook…
darkserith
  • 133
  • 1
  • 1
  • 5
12
votes
3 answers

.NET Built-in AVL-Tree?

Is there a built in AVL Tree in the .NET libraries? I searched but didn't find any. If there is, then where? what namespace? If not, is there any good implementation for AVL Trees in C#? If also not! then is there an easy way to get it done? I know…
Tamer Shlash
  • 9,314
  • 5
  • 44
  • 82
12
votes
2 answers

What is the standard binary search tree structure to use in Scala?

What is the standard balanced binary search tree implementation one should use in Scala 2.10.x? I am looking around and it seems that AVLTree was removed and RedBlack is deprecated with a message (Since version 2.10.0) use TreeMap or TreeSet…
jbx
  • 21,365
  • 18
  • 90
  • 144
11
votes
2 answers

Custom index comparator in MongoDB

I'm working with a dataset composed by probabilistic encrypted elements indistinguishable from random samples. This way, sequential encryptions of the same number results in different ciphertexts. However, these still comparable through a special…
Pedro Alves
  • 1,667
  • 4
  • 17
  • 37
11
votes
3 answers

Is kd-tree always balanced?

I have used kd-tree algoritham and make tree. But i found that tree is not balanced so my question is if we used kd-tree algoritham then that tree is always balanced if not then how can we make it balance ?. We can use another algoritham likes…
Logicbomb
  • 531
  • 1
  • 6
  • 20
10
votes
3 answers

Why is avl tree faster for searching than red black tree?

I have read it in a couple of places that avl tree search faster, but not able to understand. As I understand : max height of red-black tree = 2*log(N+1) height of AVL tree = 1.44*logo(N+1) Is it because AVL is shorter?
paseena
  • 4,207
  • 6
  • 32
  • 51
10
votes
2 answers

Handling duplicates keys within an AVL tree

I want to make my avl-tree support duplicate keys but there is a problem with the default behavior of the binary search tree with duplicates that the rotation could make nodes with equal key be on the left and the right of the parent. For example…
Ahmed Kotb
  • 6,269
  • 6
  • 33
  • 52
10
votes
5 answers

How is Wikipedia's example of an unbalanced AVL tree really unbalanced?

The image above is from "Wikipedia's entry on AVL trees" which Wikipedia indicates is unbalanced. How is this tree not balanced already? Here's a quote from the article: The balance factor of a node is the height of its right subtree minus the…
somas1
  • 1,156
  • 1
  • 16
  • 23
10
votes
8 answers

Minimum number of node in AVL tree?

I know the formula of finding minimum number of node in a AVL tree is S(h) = S(h-1) + S(h-2) + 1 However, I don't really get how to use this function, say if we have a AVL height of 6. The answer tells me that Minimum = 7 + 4 + 1 =12. But how do…
user2913922
  • 159
  • 1
  • 2
  • 9
9
votes
1 answer

Why Red Black trees preferred over AVL trees for memory management in Linux?

The vm_area_struct structure used to link various sections of a memory mapped executable file is stored as a red black tree. Now, as far as I know and the post here mentions too Difference between red-black trees and AVL trees AVL trees performs…
rango
  • 311
  • 1
  • 13
9
votes
2 answers

Find the minimum gap between two numbers in an AVL tree

I have a data structures homework, that in addition to the regular AVL tree functions, I have to add a function that returns the minimum gap between any two numbers in the AVL tree (the nodes in the AVL actually represent numbers.) Lets say we have…
TheNotMe
  • 1,048
  • 2
  • 17
  • 33
8
votes
2 answers

Dynamic order statistic: get k-th element in constant time?

So, I'm trying to implement a Data Structure to handle Dynamic Order Statistic. The Data Structure has following operations: add(x): inserts a new element with value x get(k): returns the k-th smallest element: k = ceiling(n/a), where n = amount of…
G.M
  • 530
  • 4
  • 20
8
votes
2 answers

AVL tree balance

I have implemented an AVL tree, but I have a problem. Suppose I have following tree: And after adding another node: Now I must rotate node5 to left: But after rotation, it is still unbalanced. Where am I making a mistake?
MRB
  • 3,752
  • 4
  • 30
  • 44
1
2
3
61 62