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
2 answers

How to find max value(not key) in an AVL tree?

I build a simple AVL tree as following, each node has key and value. Now I want to implement a method that could return the key of node which has the largest value. For example, if I have a tree like: (7,1) / \ …
simon s
  • 135
  • 1
  • 4
  • 15
3
votes
1 answer

Algorithm for the special case of rank tree

I'm trying to create some rank tree based on AVL tree with special requirements, lets assume that I have AVL tree with nodes, each node has 2 fields: id, priority my AVL tree is sorted by id, also I have a function: foo(currentId, delta) which…
rookie
  • 7,723
  • 15
  • 49
  • 59
3
votes
2 answers

AVL Tree Non-Recursive

I'm learning AVL Tree and got TLE in recursive code. My tutor suggests to iterative solution. I searched and found a solution which saves parent node in child. I wonder this one could get problem in memory, doesn't it? And is there another way to…
Hâm Zon
  • 105
  • 1
  • 2
  • 8
3
votes
1 answer

Access values in boxed nested struct

I am fairly new to Rust and want to implement an AVL-Tree. I am using the following enum to represent my tree: enum AvlTree { Leaf, Node { left: Box>, right: Box>, value: T } } When…
lschuermann
  • 862
  • 1
  • 7
  • 17
3
votes
4 answers

Are AVL trees always a subset of red black trees?

I am searching for a proof that all AVL trees can be colored like a red-black tree? Can anyone give the proof?
user53756
3
votes
1 answer

what is the difference between WAVL (weak AVL) and Red Black Tree?

what is the difference between WAVL (weak AVL) and Red Black Tree? is there a specific reason to use WAVL over RB?
nadavs
  • 57
  • 6
3
votes
2 answers

Is there any red black tree or avl tree implementation in c++ standard library?

Just like multiset is a Binary Search Tree implementation in STL, is there any RB tree or AVL tree implementation available?
aroma
  • 1,370
  • 1
  • 15
  • 30
3
votes
2 answers

An alternative to two AVL trees

I currently have data that I need sorted in two different ways, from a time and space complexity PoV, is there any alternative to maintaining two trees, one sorted by date and one by ID number? I need to be able to return lists in order of data, and…
Harrison W.
  • 197
  • 11
3
votes
4 answers

Is it possible combining symmetric code pieces?

I was implementing avl trees for my school projects and found myself writing almost same code twice for symmetric situations. For example, this function performs rotation of two nodes to balance the tree. If clause handles the case in which lower…
saga
  • 1,933
  • 2
  • 17
  • 44
3
votes
1 answer

AVL Tree - Highest number of nodes between LST and RST

I have an AVL Tree, n nodes in it, what's the maximum difference of nodes that can be from left sub root tree and right sub root tree? So I'm not quite sure but first of all let's fill all the right sub tree with nodes, so we have n/2 + 1 nodes…
Ilan Aizelman WS
  • 1,630
  • 2
  • 21
  • 44
3
votes
1 answer

Finding minimal element not presenting in a given AVL tree

Given an AVL Tree that stores a set G of n different natural numbers. In each node stored the number of nodes in the sub-tree rooted at that node. How can we find the minimal m that is not in G and greater than a given p in time complexity of O(log…
Xtreme Joe
  • 115
  • 6
3
votes
2 answers

Inheritance and AVL/BST Trees

Is there any way to use the same insert function for both Bst and Avl tree? The problem is that Bst and Avl have different Node types, but I don't want to make the Bst Node a general case(with height and Node* parent inside, which makes no sense…
tjbrn
  • 375
  • 1
  • 4
  • 17
3
votes
1 answer

What is the downside to using an AVL tree?

It seems to me like an AVL tree is always more efficient than an BST. So why do people still use BST? Is there a costs incurred in an AVL implementation?
sgmm
  • 580
  • 2
  • 7
  • 13
3
votes
3 answers

Why would one use a heap over a self balancing binary search tree?

What are the uses of heaps? Whatever a heap can do can also be done by a self-balancing binary search tree like an AVL tree. The most common use of heap is to find the minimum (or maximum) element in O(1) time (which is always the root). This…
3
votes
2 answers

Finding the neighbours of a segment (Bentley-Ottmann algorithm )

I'm implementing the Bentley-Ottmann algorithm to find the set of segment intersection points, unfortunately I didn't understand some things. For example : how can I get the neighbours of the segment Sj in the image. I'm using a balanced binary…