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

AVL Balanced Tree - print last 10 nodes

I've got a BST AVL, in Java, that I need to prove is balanced by printing the last ten nodes. My hack-y solution was, knowing the number of nodes, to get the values from the last 10 nodes of an in-order traversal. It's working not as intended. The…
Volvox
  • 611
  • 2
  • 7
  • 19
0
votes
2 answers

Inserting strings into an AVL tree in C++?

I understand how an AVL tree works with integers.. but I'm having a hard time figuring out a way to insert strings into one instead. How would the strings be compared? I've thought of just using the ASCII total value and sorting that way.. but in…
Heather Wilson
  • 153
  • 2
  • 4
  • 13
0
votes
1 answer

generating key for AVL tree

I have a large system using AVL trees for fast searching of IP addresses: struct avl_node { struct avl_node *left; struct avl_node *right; ... void *info; /* point to nhlfe_entry describing nexthop */ } struct nhlfe_entry { u_int32_t…
Mark
  • 6,052
  • 8
  • 61
  • 129
-1
votes
1 answer

What to do when the AVL tree is unbalanced on the right node but there are 2 children?

I'm learning about AVL trees in class. Then I try to create one tree and then delete the nodes. But I don't know what method to choose to balance the tree correctly. Ex. 22,13,19,20,50,18,33,49 Then subtract 20. This is my tree with 20 removed, but…
Eris
  • 1
  • 3
-1
votes
1 answer

how does a pointer becomes of adress 0xabababababababab or 0xfeeefeeefeeefeee?

Im working on a data structures assignmnet and something very strange is happening , my structure contains of 4 avl trees , in the destructor of the structre I delete the 4 trees using delete (the trees are allocated with new in the constructor) , a…
-1
votes
1 answer

Can I count the number of nodes under given node in AVL tree and balanced binary trees in O(logn) time?

My purpose is to first locate(search) a certain node in the tree(AVL or balanced binary tree), and then count the number of nodes which are under it. The whole operation works in O(logn) times. Is it achievable?
-1
votes
1 answer

AVL Tree as a class in C++. Insertion problem

So I'm trying to implement AVL-tree as a class. And my insertion function doesn't work as expected. Basically every time I try to insert an element it just iterates over if (x == nullptr) return new node(key); line and that's it. So it creates node…
primadonna
  • 142
  • 4
  • 12
-1
votes
1 answer

Job Interview Question Using Trees Part 2

Continuing this question: Job Interview Question Using Trees, What data to save? Now, I am looking for an algorithm that does the following: IsWorstSince(d1,d2): check wither d2 is the day with most new infected people since d1. Return: false if…
user14826913
-1
votes
1 answer

I am making an AVL tree program and I am getting errors with my left and right variables

I pulled this code from a previous program of mine where I was using AVL Trees without using a struct. I think the problem is how I am using the struct when using getLeft() and getRight(). #ifndef BINARYTREE_H #define BINARYTREE_H #include…
user13306768
-1
votes
1 answer

Finding Minimum Nodes in AVL Tree without recursive call?

Can we find generalized formula to count minimum number of nodes in AVL tree without recursive relation formula as when we have to found number of minimum nodes in AVL tree with height 1000 then it will fail because it takes very long time to solve…
-1
votes
1 answer

How to find the kth leaf in an avl tree

i want to solve this by adding a leaf field to my avl tree node to represent leafs below node the leaf field would tell how many leaves are below each node (n->leaves =n->left->leaves + n->right->leaves ) and modify during inserting and deletion.…
-1
votes
1 answer

avl tree help dictionary implementation

i am currently learning c and algorithms. I have implemented a mock up dictionary as a tree and would like to take my course work a bit further and use an avl tree. #include #include #include #define…
learner123
  • 961
  • 1
  • 10
  • 16
-1
votes
1 answer

Printing an ALV tree in a readable format

what are the possible ways to print an AVL tree data? it is possible to do that with ANTLR to visualize the data in every node so that way i can also verify the balancing? thanks!
Hadi
  • 29
  • 7
-1
votes
1 answer

Rotation of a tree so it becomes an AVL tree

Who can help me to rotate the following tree so it becomes an AVL tree? Previous steps were these
Davide
  • 1,931
  • 2
  • 19
  • 39
-1
votes
1 answer

Is it possible to have an AVL tree sorted by two properties

I am implementing my own data structure for storing objects, these objects have an ID and also a date attached. The operations I must implement require me to sometimes return say an array in date order, or find an object by its ID. How can I…
Harrison W.
  • 197
  • 11