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
3
votes
1 answer

AVL Tree Rotation Efficiency

What is the Big O efficiency of the AVL tree rotation specifically? For example when inserting: - O(logN) to search for the position - O(1) to insert - ? for balancing (if it needs to be re-balanced) I thought it would be O(logN) but I found a site…
GJHix
  • 522
  • 10
  • 18
3
votes
1 answer

Printing in ascending order (sorting) from AVL trees

I need to define a main function that reads integers and prints them back in ascending order. For example, if the input contains 12 4 19 6 the program should output 4 6 12 19 I need…
Thatdude1
  • 905
  • 5
  • 18
  • 31
3
votes
1 answer

Given a balanced BST. a min, max, and value, how can you find the largest Xor within min and max?

Basically you have a BST filled with values. eg. 1-16 a min,max and value (10,15,3) and you need to find the maximum xor value between the values in the BST and the given value that are within min and max of the tree. I'm wondering if there is a…
iamdro
  • 41
  • 4
3
votes
2 answers

When is an AVL tree better than a hash table?

More specifically, are there any operations that can be performed more efficiently if using an AVL tree rather than a hash table?
Matt
  • 11,157
  • 26
  • 81
  • 110
3
votes
2 answers

Multiple AVL Trees From Sorted List?

I'm working on an AVL tree assignment and I have a quick question about their definition - we're given a sorted list, and we have to generate an AVL tree from it in O(n) time. I've completed this (thanks to other help from StackOverflow!), but my…
Jake
  • 3,142
  • 4
  • 30
  • 48
3
votes
2 answers

The least node that is greater than or equal to a given value in AVL

I am trying to implement a function in C that will find the smallest int that is greater than or equal to a given int in an AVL. For example: if I have an AVL tree consisting of 1,2,3,4,5,6,7 and I put in 6, it should return 6. if I have an AVL…
3
votes
1 answer

Comparison about balanced binary search trees

I've read some Q&As about self-balancing binary trees, but I'm not quite familiar with all of them. The first one of them I got to know is AVL, the second is Red-Black tree. There are something I don't quite understand: according to some books and…
Alcott
  • 17,905
  • 32
  • 116
  • 173
3
votes
3 answers

Binary Tree Rotation

I'm working on implementing an AVL Search tree. So far I've finished the coding part and I've started testing it for bugs. I found out that my node rotation methods are bugged and for god's sake I can't understand what's the problem. The algorithm…
Mihai Bişog
  • 998
  • 9
  • 24
3
votes
2 answers

Which of the following are avl trees?

In the attached picture there are two Binary search trees. When I saw this question I thought that first tree is not balanced so it's not an avl tree and as second one is balanced it's obviously an avl tree. But here the problem is when I saw the…
SaiNaveen
  • 51
  • 1
  • 6
3
votes
1 answer

Delete all entries with a given value in AVL Tree

I am implementing an AVL Tree of the following type AVLTree,V> basically every node of the Tree is a Key-Value Node, at the moment i am struggling with a method that deletes all the V values. This is what i have: private void…
DRE
  • 263
  • 8
  • 35
3
votes
2 answers

How would you go about implementing a balanced tree with lazy deletions?

More specifically, an AVL tree. Is it possible? I'd like to do it, but I'm thinking the undeleted nodes may be problematic to manage with the rotations. I have one that works normally, but I'd like to use this one with lazy deletion for something…
prinny
3
votes
5 answers

Balanced tree with constant-time successor and predecessor given node pointers?

I was asked this question, which I personally find hard: Create a data structure that can: Insert elements, Remove elements, Search Elements, In time O(log n) In addition, It should have the following two functions which work in time…
spano
  • 370
  • 1
  • 14
3
votes
4 answers

Implementing an AVL tree in JAVA

I want to implement an AVL Tree in Java, here is what I have so far: public class AVLNode { private int size; /** The size of the tree. */ private int height; /** The height of the tree. */ private Object key;/** The key of the current…
k-man
  • 1,121
  • 5
  • 17
  • 26
3
votes
3 answers

AVL Tree in ML- Rotate left, Warning: match nonexhaustive

I am implementing an AVL tree in SML: Here are my datatypes: datatype 'a AVLTree = Nil | Br of ((int*('a))*('a AVLTree)*('a AVLTree)); datatype Balance = RR | LR | LL | RL; exception NotFound; exception NullValue I am now writing the function…
genericname
  • 167
  • 3
  • 11
3
votes
1 answer

AVL Tree Deletion Rules

For an AVL tree, when deleting a node from the tree that requires restructuring, the book i am reading states that there are certain rules to following to select which nodes to restructure. An example is as such: 44 / \ 17 62 …
jkli123
  • 31
  • 1
  • 2