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

Rebuilding a BST into AVL

How will you rebuild a given BST into AVL which contains exactly the same keys? The algorithm running time should be O(n) and its allowed to use O(n) additional space. Any ideas? The whole pseudo-code is not necessary, any idea or suggestion would…
0
votes
1 answer

Map implementation using AVL tree

I am trying to implement a simple Map using an AVL tree as an underlying structure. I implemented the Map using a binary search tree as the underlying structure, but I am having trouble picturing how to check and balance the tree if necessary. When…
adub3
  • 141
  • 3
  • 9
0
votes
2 answers

Reuse comparison function

I have builded a binary tree using an AVL and then data is packed in an array typedef struct { void **data; int count; } t_table; The comparison function looks like: int cmp(const void *pa, const void *pb) { int a = *(int *)pa; int…
David Ranieri
  • 39,972
  • 7
  • 52
  • 94
0
votes
1 answer

C : Cannot access memory error, when finding recursively an AVL tree height

So i tried to implement an AVL tree in C. I use recursion for the insertions, and while i get some good results for small number of items, i get a "cannot access memory at..." at big input as shown below. Before i post the code. The problem seems to…
Alek Sobczyk
  • 813
  • 1
  • 7
  • 6
0
votes
1 answer

Storing hierarchical structure of a company

I have to maintain a the employee structure of a company. Each employee has associated with it a unique name (no two with the same name) and a level (integer). the level denotes where the person stands in the hierarchy. Level 1 = highest (only 1…
Saket Mehta
  • 2,438
  • 2
  • 23
  • 28
0
votes
1 answer

what is the Balance factor in AVL tree

I'm making presentation for AVL tree, can't understand what is the balance factor. please give me the link or any thing that I can understand graphically how height of an AVL tree's height effect
0
votes
1 answer

Searching a node with balance factor of -2 in an AVL tree

I know how to search a node with a particular key into an AVL tree . But I want to know how to search in an AVL tree with a balance factor of -2 Here is the code that I have tried. void searchForUnrequiredBalanceFactor(avlnode *n , avlnode *r) { …
Subbu
  • 2,063
  • 4
  • 29
  • 42
0
votes
1 answer

Printing an array of nodes

Is it possible to print an array of nodes? I need to display the AVL tree as it is being built, but whenever I run this code, the program crashes. Any alternative ways around this? int k = 0; t = NULL; node* nodearray[32]; for( j =…
user1816546
  • 313
  • 4
  • 15
0
votes
3 answers

Implementing an AVL tree using a List

So I have implemented an Binary search tree using a parameterized List i.e. List tree = new List<>(); The tree works fine. The node itself doesn't know anything about its parent or children. This is because I calculate the locations based on…
Taf Munyurwa
  • 1,444
  • 2
  • 16
  • 22
0
votes
1 answer

AVL Tree implementation with nodes or without nodes

We have a class project to implement an AVL tree. Here are two very general implementations: template class AVLTree { int key; int height; int BF; T data; AVLTree* father, leftSon, rightSon; . . . } A friend told me I really…
dlvhdr
  • 482
  • 4
  • 19
0
votes
1 answer

AVL Tree: solving a StackOverflowError

Basically, I am implementing an AVL tree by reading a set of integers from a text file and then populate the tree by using the add() method. Also, the program is supposed to print in order the set of integers. As I run the program, a…
0
votes
3 answers

Binary Search Tree Insert Function In C

For future viewers of this question who might need help in this type of problem: I fixed it by combining the 2 functions (InsertNode() and InTree()) I'm not sure if this is bad practice and I'll get back to you guys with if it actually really does…
0
votes
2 answers

Why does this method cause an Infinite Recursive call?

I'm struggling to understand why this class is not functioning. It was part of an assignment for a course on Data Structures(EDIT: The deadline for the assignment has passed, I just want to figure it out...). The node is part of an AVL tree built…
0
votes
1 answer

Using an AVL tree in java

I have the AVLNode and AVLTree classes, i have the methods to remove and insert nodes and i have a print method. I want to use these methods to create a AVL tree. On input i want to write "Add x" and "Remove x". I wrote this but when i print…
10001a
  • 53
  • 1
  • 6
0
votes
2 answers

Passing a AVLTree between forms

There is another question that is very similar to mine however after reading it i still cannot get it to work. I have two forms , MainForm and SecondForm and a few other classes, i need an instance of my AVLtree and be able to access it through my…