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

C# Most efficient data structure to insert and to remove lower half

Imagine I have a big sorted list of integers (>1000 items). I need to be able to do two operations on this list: remove the lower half and fill the list again to its original size by inserting random integers. Because I do these operations about a…
Safron
  • 802
  • 1
  • 11
  • 23
5
votes
2 answers

Paged binary trees vs. AVL trees and/or B-trees

How are paged binary trees different from AVL trees and/or B-trees?
neuromancer
  • 53,769
  • 78
  • 166
  • 223
5
votes
1 answer

Container with fast inserts and index?

I am looking for a C++ container class that is indexed like an std::vector, but has fast insertions, deletions and indexing. For example, a vector interface implemented with an underlying balancing tree would have O(logN) insertions/deletions and…
Max
  • 3,384
  • 2
  • 27
  • 26
5
votes
2 answers

How is insertion and deletion more faster in red black tree than AVL tree?

I would like to understand the difference bit better, but haven't found a source that can break it down to my level. I am aware that both trees require at most 2 rotations per insertion. Then how is insertion faster in red-black trees? And how…
user2626445
  • 1,031
  • 12
  • 27
5
votes
2 answers

How can I correctly display my AVL Tree in LaTex? A solo left-child hangs straight down

The below code almost works perfectly, however the child of 9, 7, hangs straight down instead of as a left-child. How can I correct this? \usepackage{tikz} \usepackage{xytree} \begin{tikzpicture}[level/.style={sibling distance=60mm/#1}] \node…
cb.
  • 290
  • 1
  • 5
  • 14
5
votes
2 answers

AVL TREE in c++

I have a problem with this very simple block of code. please give me your advice . (My this problem is solved, and in solving this problem the person having id stakx really helped me, the only problem was that i was using stack< treeNode >, when i…
Zia ur Rahman
  • 1,411
  • 4
  • 26
  • 43
5
votes
1 answer

Balancing an AVL Tree haskell

I am creating an AVL Tree in Haskell but I am unsure of how to balance the tree. I can add elements in but they aren't balanced. like using the addList method I add in [4,2,1,3,6,8] adds it in as: The layout for: Root 4 (Root 2 (Root 1 Empty Empty)…
Macken101
  • 63
  • 2
  • 8
5
votes
2 answers

Implement balanced factor with only 1 extra bit per node

In the book Introduction To Algorithms - A Creative Approach, Question 4.18: The AVL algorithms that were presented in Section 4.3.4 require balanced factors with three possible values: 1, 0, or -1. To represent three values we need 2 bits. Suggest…
Guocheng
  • 543
  • 3
  • 15
5
votes
1 answer

Prove maximum number of rotations for two trees to become equal

In the book Introduction To Algorithms - A Creative Approach, Question 4.24: Let T1, and T2 be two arbitrary trees, each having n nodes. Prove that it is sufficient to apply at most 2n rotations to T1, so that it becomes equal to T2. For binary…
Guocheng
  • 543
  • 3
  • 15
5
votes
1 answer

Why does the AVL tree in Map of OCaml use balance factor (height diff) 2 instead of 1?

According to AVL tree wiki The balance factor is calculated as follows: balanceFactor = height(left-subtree) - height(right-subtree). For each node checked, if the balance factor remains −1, 0, or +1 then no rotations are necessary. However, in…
Jackson Tale
  • 25,428
  • 34
  • 149
  • 271
5
votes
1 answer

Why does this AVL tree implementation pack bits into pointers in 64-bit but not 32-bit implementations?

In this AVL tree implementation from Solaris, struct avl_node is defined in an obvious way if compiling for 32-bit library. But for 64-library a pointer to node's parent is packed into "avl_pcb". And it looks like only 61 bits of a ponter are…
user933161
5
votes
1 answer

Deletion in AVL Tree

As you know how avl should be balanced after deletion of a node, I'll get to point. For starting, Im considering deleting a node with no children. For Example a Tree: 10 / \ 5 17 / \ / \ 2 9 12 20 \ …
InamTaj
  • 276
  • 2
  • 7
  • 15
5
votes
3 answers

Remove from AVL tree example code

I am looking into AVL trees and can not seem to find a reference code about removal (either by Googling or from a couple of textbooks I have handy). I am not sure why is this, but do you know of any reference/example of deletion of AVL in java? (I…
Cratylus
  • 52,998
  • 69
  • 209
  • 339
4
votes
1 answer

Rust - double mutable borrow in 'while let' statement

Sorry if this is a dumb question, I'm relatively new with Rust and just can't crack this double mutable borrowing error. I'm trying to create an AVL tree method that finds an appropriate position into which a new node can be inserted. I don't…
Skelectric
  • 43
  • 4
4
votes
1 answer

AVL Tree rebalancing algorithm: how to decide between Zig-Zig and Zig-Zag cases?

I'm trying to implement an AVL tree as a practice. For both insertion and deletion operations, my implementation does the normal BST insertion and deletion first, and then walks up the parent chain to check and fix any unbalanced subtrees. However,…
dw218192
  • 117
  • 1
  • 5