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
4
votes
3 answers

AVL trees balancing

Given an AVL tree below: 23 / \ 19 35 / \ / \ 8 20 27 40 / 38 / 36 Is it ok to just do a single rotation at 40, to the right? Making it…
Mark
  • 621
  • 1
  • 10
  • 24
4
votes
1 answer

How to improve the efficiency of the function that finds the number of items in a range from AVL tree?

I'm writing a function that finds out the total number of items in a AVL tree by range. For example, the arguments that passed in is "ab" and "au", then I need to find out how many items they are in an AVL tree is in that range. Currently my way of…
4
votes
1 answer

Use the 'typename' keyword to treat nontype as a type in dependent context

I am getting this error in my AVL tree class as described in the title for this part of my code: template std::unique_ptr::TreeNode> AVL::rightRotate(std::unique_ptr& y) { std::unique_ptr x =…
user9366862
4
votes
1 answer

how to rebalance a random binary search tree

Here is the situation: There's a balanced binary search tree which may be access by tens of threads. So when I need to insert or delete a node, I don't want to lock the whole tree due to the concurrency. as time goes it becomes not balanced again.…
4
votes
2 answers

"Rotating" to get AVL Tree

Why is the process of balancing to get an AVL tree called rotation? (While you are at it, what's single & double rotation?) Every textbook of mine blatantly uses that word without any explanation.
user191776
4
votes
3 answers

AVL tree delete Item in C

As I try to delete some items from my AVL tree, I'm losing as result some other items. You can see this from the example in the picture. What is wrong with my code? #include #include typedef struct Tree{ int key; …
Qas
  • 332
  • 4
  • 12
4
votes
2 answers

AVL Tree Balancing

I am working on an assignment that asks me to implement an AVL tree. I'm pretty sure I have the rotation methods correct, but I'm having trouble figuring out when to use them. For example, the explanation in the book says that I should climb up the…
Will M
  • 2,135
  • 4
  • 22
  • 32
4
votes
1 answer

Complexity of balancing an unbalanced/partially balanced BST?

In an AVL tree, it takes a constant number of single and double rotations every time we rebalance on insertion and deletion since we only have to check the path from point of insertion or deletion to the root. If we had an unbalanced tree, we would…
ask
  • 2,160
  • 7
  • 31
  • 42
4
votes
4 answers

Boost Intrusive/binary search trees

I'm looking for a binary search tree for a Voronoi tessellation algorithm (Fortune's algorithm; a darned non-trivial task in itself, methinks), so of course, I thought I'd have a look at Boost. Boost has the Intrusive header file, which seems to…
Kristian D'Amato
  • 3,996
  • 9
  • 45
  • 69
4
votes
1 answer

Solving the recurrence relation for number of nodes in an AVL tree?

Suppose that we have this recurrence relation, which comes up in the analysis of AVL trees: F1 = 1 F2 = 2 Fn = Fn - 1 + Fn - 2 + 1 (where n ≥ 3) How would you solve this recurrence to get a closed-form for F(n)? This number is used to get the…
4
votes
1 answer

Get median from AVL tree?

If you have an AVL tree, what's the best way to get the median from it? The median would be defined as the element with index ceil(n/2) (index starts with 1) in the sorted list. So if the list was 1 3 5 7 8 the median is 5. If the list was 1 3 5 7…
omega
  • 40,311
  • 81
  • 251
  • 474
4
votes
2 answers

Balancing AVL Trees

I am having trouble balancing AVL Trees. I have searched high and low for steps to how to balance them and I just can't get anything useful. I know there are 4 kinds: Single Left Rotation Single Right Rotation Double Left-Right Rotation Double…
4
votes
1 answer

What is the Ruby equivalent of Java's TreeSet (self balancing binary tree)?

I want to use a self balancing binary tree to play around with some algorithms, but I'm having difficulty finding the Ruby equivalent of Java's TreeSet (or C#'s SortedSet). I have found web code…
Foolish Chap
  • 765
  • 1
  • 5
  • 19
4
votes
3 answers

AVL tree rotation in Java

I want to implement the Java AVL tree and to rotate the tree left and right. I am not getting this. Can anybody by looking at the code below tell me how can I possibly rotate the tree left and right and then use fix up with those two functions to…
user1832681
  • 45
  • 1
  • 1
  • 6
4
votes
1 answer

python AVL tree insertion

I have written a python code to implement. While writing the code I referred completely to the pseudo code I had. To test the class I created I wrote a little test code "app.py". It takes the number of nodes from the user and randomly generates an…
user1689822
  • 43
  • 1
  • 5