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

Problems with rotations when converting a BST (no recursion) to AVL

I'm working on a university project (Data structures) this weekend and I have to code an AVL tree in C++. I thought that it wouldn't be difficult to code a BST first and then convert it into an AVL. Probably I was wrong... I have two classes, class…
syfantid
  • 366
  • 5
  • 20
0
votes
1 answer

C++ AVLtree deletion method

I'm really stuck on how to implement an deletion method for an avltree in C++. I'm not really sure where to begin. I have methods to find a node, and rotation methods, and insertion working but just really unsure on how to start this deletion…
Student
  • 195
  • 1
  • 12
0
votes
1 answer

C++ AVLtree insertion method

So the problem I'm having is the insert method for an AVLtree. My avltree stores city objects, and I use the names of the cities to decide where they should go. My City .cpp class: #include "City.h" #include using namespace std; …
Student
  • 195
  • 1
  • 12
0
votes
2 answers

Find kth min node in AVL tree

I now have built a AVL tree, Here is a function to find kth min node in AVL tree (k started from 0) Code: int kthMin(int k) { int input=k+1; int count=0; return KthElement(root,count,input); } int KthElement( IAVLTreeNode * root, int…
user2840454
  • 89
  • 1
  • 3
  • 12
0
votes
2 answers

C++ Segmentation error(core dumped)

So the problem I'm having is a segmentation error. I'm trying to implement an AVLtree, and I believe that this part of my code is the problem, but I can't pinpoint what I've done wrong. Part of my AVLtree class: Node* AVLtree::findNode(string…
Student
  • 195
  • 1
  • 12
0
votes
1 answer

Insert method of AVL tree?

I am posting you the code for using an AVL tree that I developed. The method for insert, avlinsert method is listed below. I developed this code on paper and it's not tested but I hope this will work. The main problem I want to discuss is the…
Zia ur Rahman
  • 1,411
  • 4
  • 26
  • 43
0
votes
2 answers

Calculating the balance factor of a node in avl tree

I want to calculate the balance factor of a node in avl tree without using any recursive procedure. How can i do that? Please tell me method or provide C++ code snippet.
Zia ur Rahman
  • 1,411
  • 4
  • 26
  • 43
0
votes
4 answers

Balancing the tree

How to balance this tree structure 13 / \ 8 18 / \ 14 19 …
Syed Mehmood Ali
  • 157
  • 1
  • 2
  • 4
0
votes
1 answer

AVL Right Rotate

I'm trying to understand the following piece of code for AVL trees, but am having some difficulty. I know that if the tree is left heavy, it will do a right rotation. Same goes if it's right heavy, it will do a left rotation. Appreciate if someone…
Kuan E.
  • 373
  • 1
  • 3
  • 15
0
votes
1 answer

AVL Tree Implementation for Java

Ok I'm trying to start my assignment but I have no clue where to start first of all and how the end output would even look like. It's an Algorithm class so he doesn't show us codes or anything that may help coding in Java. We also never dealed with…
user2318083
  • 567
  • 1
  • 8
  • 27
0
votes
1 answer

AVL tree rotation and red-black tree color flips

As we all know, the insertion and deletion all require O(log n). AVL tree require O(log n), because it need O(log n) to insert and O(log n) to rotation for balance. RB tree require O(log n), because it need O(log n) to insert, In INTRODUCTION TO…
Aleeee
  • 1,913
  • 6
  • 17
  • 27
0
votes
2 answers

AVL Tree Deletion and restructuring

I have seen that when a node is deleted from an AVL tree it may require restructuring multiple no times in contrast to inserting which requires only once. Can anyone give me an example of such a case of deletion? Also, I have implemented an AVL Tree…
zed111
  • 200
  • 5
  • 15
0
votes
1 answer

C++ : Confused in dealing with multiple classes

This is the first time i m trying to handle multiple classes in a c++ program and the experience has been really terrible because i have spent many tens of hours just staring at the code and trying to figure out whats wrong. Also, my actual code…
Akash Rupela
  • 159
  • 10
0
votes
1 answer

Please help me understand LR rotation in AVL tree

Today I was studying AVL trees in Data Structures but got stuck in understanding LR and RL rotations. LL and RR rotations are quite intuitive and so easy to remember, but it seems to me that LR and RL rotation do not follow common sense, so I am…
Mistu4u
  • 5,132
  • 15
  • 53
  • 91
0
votes
1 answer

How to rebalance AVL tree after leaf deletion?

Here is how I think it should be done (after reading p. 652 of D.S. Malik's "Data Structures using C++" 2nd). We traverse the path leading to the deleted leaf starting from its parent. For every node P along this path we do what is presented below.…
cpp
  • 3,743
  • 3
  • 24
  • 38