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

Perfect Balanced Binary Search Tree

I have an theoretical question about Balanced BST. I would like to build Perfect Balanced Tree that has 2^k - 1 nodes, from a regular unbalanced BST. The easiest solution I can think of is to use a sorted Array/Linked list and recursively divide the…
OlejkaKL
  • 521
  • 1
  • 9
  • 23
7
votes
5 answers

Choosing a Data structure for very large data

I have x (millions) positive integers, where their values can be as big as allowed (+2,147,483,647). Assuming they are unique, what is the best way to store them for a lookup intensive program. So far i thought of using a binary AVL tree or a hash…
Carlos
  • 5,405
  • 21
  • 68
  • 114
7
votes
2 answers

What does the AVL stand for in AVL tree?

An AVL tree is the same as a self-balancing binary search tree. What does AVL stand for? Does it have to do with the name of the inventor?
Jing Ma
  • 183
  • 2
  • 12
7
votes
2 answers

More than one rotation needed to balance an AVL Tree?

My best guess is that one rotation is always enough to balance an AVL tree when you insert or delete ONE element from an already balanced AVL tree. Is one rotation always enough? An example will help where more than one rotations are needed. PS: I…
kBisla
  • 590
  • 2
  • 8
  • 23
7
votes
4 answers

Binary search tree over AVL tree

As far as I know the time complexity between AVL trees and Binary Search Trees are the same in average case, with AVLs beating BSTs in worst case scenarios. This gives me a hint that AVLs are always superior than BSTs in every possible way to…
6
votes
5 answers

How to implement insertion for AVL tree without parent pointer?

I saw some articles about the implementation of AVL's rebalance() function. After each insertion, we should check the insertion Node's ancestors for balance. So I think, in order to check ancestors' balance, I got to know the insertion Node's…
Alcott
  • 17,905
  • 32
  • 116
  • 173
6
votes
2 answers

Height difference between leaves in an AVL tree

What is the maximum difference between any two leaves in an AVL tree? If I take an example, my tree becomes unbalanced, if the height difference is more than 2(for any two leaves), but the answer is the difference can be any value. I really don't…
6
votes
2 answers

weight-unbalanced AVL tree

Believing the wikipedia article: http://en.wikipedia.org/wiki/AVL_tree AVL trees are height-balanced, but in general not weight-balanced nor μ-balanced;[4] that is, sibling nodes can have hugely differing numbers of descendants. But, as an AVL…
azerty
  • 698
  • 7
  • 28
6
votes
1 answer

A sequence that forms the same AVL and splay trees?

Is there such a sequence of numbers (1-7, all numbers used, only once each), that would form equal AVL and splay tree?
6
votes
2 answers

What is the minimum sized AVL tree where a deletion causes 2 rotations?

It is well known that deletion from an AVL tree may cause several nodes to eventually be unbalanced. My question is, what is the minimum sized AVL tree such that 2 rotations are required (I'm assuming a left-right or right-left rotation is 1…
Greg C
  • 61
  • 1
  • 3
6
votes
1 answer

AVL Trees: How to do index access?

I noticed on the AVL Tree Wikipedia page the following comment: "If each node additionally records the size of its subtree (including itself and its descendants), then the nodes can be retrieved by index in O(log n) time as well." I've googled and…
5
votes
1 answer

How to generate an AVL tree as lopsided as possible?

I saw this in some paper and someone argued that there can be at most log(n) times rotation when we delete a node of an AVL tree. I believe we can achieve this by generating an AVL tree as lopsided as possible. The problem is how to do this. This…
Yuming Cao
  • 935
  • 1
  • 10
  • 22
5
votes
1 answer

Preference between an AVL tree and a 2-3 tree

can someone tell me if using an AVL is preferred over using a 2-3 tree or vice-versa and why so? Thx
Melvic
  • 51
  • 1
  • 4
5
votes
1 answer

AVL tree dictionary

So far I've been drawing up a plan of attack to see how I could go about doing this and this is what I have: bool isEmpty() const - returns true if empty, false if not int getSize() - returns how many words are stored in the dictionary void insert…
user814447
5
votes
2 answers

Merging 2 DIFFERENT AVL trees

Assume that I have two AVL trees and that I know their respective sizes. However, I don't know if there are repeated nodes, or any other information. What would be the most efficient way to merge them in a new AVL tree? The original trees can be…
Josep
  • 12,926
  • 2
  • 42
  • 45
1 2
3
61 62