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.

842 questions
88
votes
4 answers

When to choose RB tree, B-Tree or AVL tree?

As a programmer when should I consider using a RB tree, B- tree or an AVL tree? What are the key points that needs to be considered before deciding on the choice? Can someone please explain with a scenario for each tree structure why it is chosen…
Palladin
  • 983
  • 1
  • 7
  • 10
82
votes
9 answers

Difference between red-black trees and AVL trees

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…
Bob John
  • 3,504
  • 14
  • 35
  • 55
75
votes
1 answer

Statistical performance of purely functional maps and sets

Given a data structure specification such as a purely functional map with known complexity bounds, one has to pick between several implementations. There is some folklore on how to pick the right one, for example Red-Black trees are considered to be…
65
votes
9 answers

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

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…
thr
  • 18,022
  • 19
  • 89
  • 129
49
votes
2 answers

Difference between AVL trees and splay trees

I am studying about various trees, and came across AVL trees and splay trees. I want to know What is difference between AVL trees and splay trees? On what basis do we select these tress? What are positive's and negative's of these trees? What are…
venkysmarty
  • 10,013
  • 19
  • 87
  • 165
45
votes
10 answers

AVL tree vs. B-tree

How is an AVL tree different from a B-tree?
neuromancer
  • 47,047
  • 74
  • 161
  • 217
31
votes
4 answers

Concatenating/Merging/Joining two AVL trees

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…
liviucmg
  • 1,290
  • 2
  • 17
  • 25
30
votes
1 answer

How do you know where to perform rotations in an AVL tree?

So I'm self teaching AVL trees and I understand the basic idea behind it, but I just want to make sure my intuition of actually implementing it is valid: I'll examine it with the left rotation- So, the following situation is simple: 8 /…
Skorpius
  • 1,943
  • 2
  • 20
  • 29
24
votes
6 answers

Are AVL Trees Evil?

I was reading the article from Steve Yegge about singletons. In it he mentions his teacher told him AVL Trees were evil. Is it just that red and black trees are a better solution?
Chap
  • 2,700
  • 23
  • 31
21
votes
3 answers

How to generate maximally unbalanced AVL trees

I have written a C language library of AVL trees as general purpose sorted containers. For testing purposes, I would like to have a way to fill a tree so that it is maximally unbalanced, i.e., so that it has the maximum height for the number of…
Walter Tross
  • 10,629
  • 2
  • 31
  • 59
20
votes
4 answers

balancing an AVL tree (C++)

I'm having the hardest time trying to figure out how to balance an AVL tree for my class. I've got it inserting with this: Node* Tree::insert(int d) { cout << "base insert\t" << d << endl; if (head == NULL) return (head = new…
gregghz
  • 3,725
  • 6
  • 38
  • 65
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
  • 8,809
  • 13
  • 42
  • 72
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
13
votes
3 answers

Why red-black tree based implementation for java TreeMap?

The third paragraph of wikipedia's article on AVL trees says: "Because AVL trees are more rigidly balanced, they are faster than red-black trees for lookup-intensive applications." So, shouldn't TreeMap be implemented using AVL trees instead of…
Nikunj Banka
  • 10,091
  • 15
  • 68
  • 105
13
votes
1 answer

Computational Complexity of TreeSet methods in Java

Is the computational complexity of TreeSet methods in Java, same as that of an AVLTree? Specifically, I want to know the computational complexity of the following methods: 1.add 2.remove 3.first 4.last 5. floor 6. higher Java Doc for method…
user1628340
  • 711
  • 4
  • 11
  • 25
1
2 3
56 57