Questions tagged [tree-balancing]

In the context of data structures, tree balancing refers to reorganizing the nodes in a binary search tree to ensure that the height of the tree is not too large.

76 questions
0
votes
0 answers

AVL Trees: How to properly rebalance?

I'm writing an AVL Tree class and my professor has included some tests for our code. I have passed all the tests except three, and the three tests I'm failing seem to indicate that when elements are added to or removed from the tree, the tree…
Riana
  • 27
  • 2
0
votes
1 answer

Does a Red-Black Tree modify the left-to-right order of its leaves when it re-balances itself?

In other words, If you were to read the values of the leaves in a red black tree from left-to-right immediately after an insertion, would that order remain the same after performing balancing operations on the tree?
0
votes
1 answer

AVL tree perfect balancing issue

I am wondering if there is fundamental issue for AVL tree re-balancing. According to several tutorials, for AVL insertion, maximum 2 rotates it can be balanced. However, it may depend what is called as balanced. Follow link to see the…
Lino
  • 3
  • 1
0
votes
1 answer

Sorted Singly Linked List to BST Java

I currently have a sorted Linked List, and with a void return method, I need to recursively construct a balanced binary search tree from the list (which is referred to as the second parameter). And as parameters I can have only the LL Head, the root…
0
votes
0 answers

Balancing AVL tree height/balance factor error

Alright so there is a lot of code here, but I thought it was best in case something wasn't immediately evident in my logic. My issue starts with the height, and my calculated balancing factor. I have looked up a countless amount of AVL-tree…
0
votes
1 answer

Can an unsorted binary tree be balanced using a distance-function?

I´ve got the following theoretical problem: I have an amount n of cuboids in 3-dimensional space. They are aligned to the coordinate-system, so that one cuboid can be described via a point (x,y,z) and dimensions (dimX,dimY,dimZ). I want to organize…
0
votes
1 answer

Calculating balance factor for an AVL tree with variable limits - possible?

I have been playing with code to implement insert into an AVL balanced binary tree which will be used in a largish project. I selected AVL instead of red black and other balancing methods because of its simplicity as I need to have confidence that…
user3572725
  • 1
  • 1
  • 2
0
votes
1 answer

Calculating AVL tree node balance from it's children nodes' balances

Say I have an AVL tree such that it's nodes store their own balance factor as a single integer. How can I calculate the balance factor of a node N if I know the balance factor of both it's left and right child. Note that I DO NOT have the rHeight…
irfanka
  • 129
  • 1
  • 12
0
votes
1 answer

When is the optimal time to balance a BST?

I have a BST and 2 queues that feed into it. In order for insertion and deletion to be in the shortest time possible I need to balance my tree every so often. For this I use the DSW algorithm. I have all this implemented and it all works great. My…
Dee
  • 741
  • 1
  • 15
  • 32
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,503
  • 3
  • 18
  • 35
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

Red-Black Tree - Rotation Method Implementation - C++

I am implementing a Red-Black tree in c++, but I am having trouble with my rotation methods. The insert method works just fine without any balancing, but as soon as I try to rotate, my tree loses information. My guess is that I'm not setting…
jordan
  • 6,382
  • 8
  • 38
  • 72
-1
votes
2 answers

How can I fix my array so I don't have an IndexOutOfBoundsException?

For a HW assignment, I was tasked to add a bunch of methods into a BinarySearchTree class. Two methods I have are balance and InsertTree (I think it should've been named InsertNode). The authors from the textbook provided pseudo code of what the…
GGz
  • 3
  • 5
-1
votes
1 answer

How would I balance a degenerate tree? C++ Data Structure

I am currently learning data structure using C++. I understand how you would balance binary search tree as you insert new nodes. However, what if you already have a degenerate tree(single linklist), and want to balance that without creating a new…
-1
votes
2 answers

What are the two subtrees for C that makes it unbalanced?

In the tree: A / \ B C <-- Difference = 2 / / D E / G What are the two subtrees for node C that make it unbalanced??