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.
Questions tagged [tree-balancing]
79 questions
0
votes
1 answer
Given the following condition, how can we determine if it is a self balancing BST?
By the definition of a self-balancing BST, the height of the children should = Big-Theta(logn).
How can I check if a BST is self-balancing given the following condition?
No. of nodes in its left subtree and right subtree are no more than 90% of the…
user18235267
0
votes
0 answers
Idris function getting pattern matching error on red black tree implementation
I'm working on a red black tree implementation in Idris. In this implementation, the node, in addition to carrying information about its value and colour, also carries information about its black height (which is the number of black nodes from that…

Oneiros
- 143
- 1
- 13
0
votes
0 answers
Memory errors/leaks when deleting a node in a self balancing binary search tree - how do I free its memory?
I am getting memory leaks specifcally when I am trying to a delete a node (as in when there are only insertion operations, there are no leaks) from my self balancing tree. After my delete and insertion operations are done, I call a function to…

lameprogrammer01
- 95
- 8
0
votes
0 answers
Memory errors while trying balance binary search tree?
I have an insertion function for a BST, which also calls and checks if a node is balanced. If it is not I call rotation function on the node. This is where the problem is -> up till then my program worked fine, however, after adding that function my…

lameprogrammer01
- 95
- 8
0
votes
1 answer
Red black tree deletion unknown behaviour
I entered several numbers to a red black tree. (41; 38; 31;
12; 19; 8) after deleting 8 and 12 (1st screenshot) it got into the type of the second screenshot. I can't understand why that 31 turn into red . Please help me with that ? If you could…

Nipuna C
- 81
- 2
- 7
0
votes
1 answer
Access violation exception while creating AVL tree
I am trying to create an AVL perfectly balanced tree from a vector of elements.
I have started on a small number of elements(8) so that I can check the correctness of the algorithm. My problem appears when printing the values from the TREE, I keep…

Diana G
- 261
- 3
- 15
0
votes
1 answer
How self balancing tree or small height tree structure helps for efficient lists and abstract data structure
I'm reading about AVL tree and there I redirected to self balancing tree there I read that
In computer science, a self-balancing (or height-balanced) binary
search tree is any node-based binary search tree that automatically
keeps its height…

Asif Mushtaq
- 3,658
- 4
- 44
- 80
0
votes
1 answer
Balancing a Binary Search Tree using an ArrayList
For a class assignment I am required to add a method to a provided BinarySearchTree class that will balance the binary search tree by storing the values-in order-in an array, and using those values to construct a new tree. However, when I try to run…

shamstu
- 1
- 1
0
votes
1 answer
How to balance tree with single branch?
If we had, say, nodes of value 10, 9 ... 1 arranged in descending order on a single left branch, how could we perform rotations on the tree to make it a balanced AVL tree? I was thinking of repeating single right rotations, but could someone show…

Y. P
- 9
- 3
0
votes
1 answer
Where does MQL4 / MQL5 implementation of originally C++ AVL Tree Parent node exhibit an issue?
I dont know where I am having an issue, but I am getting a strange error in my AVL implementation, translated into MQL4/MQL5 language.
In failed case, I am getting into either
recursively pointing to same node problem
or
a detached node without…

VyshuRam
- 93
- 1
- 10
0
votes
2 answers
Binary Search Tree balance
I'm working on a BST that will balance nodes according to their hits and their elements, where a hit is an attribute that increases when a node is found using find(), contains() etc.
The root of the tree is the node with the highest number of…

NaughtySloth
- 15
- 1
- 6
0
votes
1 answer
balance AVL tree before or after node deletion?
This exercise asks the student to delete a node from an AVL tree. In this case, this requires some balancing, since the difference between deepest and shallowest depth is > 1. But should the balancing occur before or after the deletion? Or does it…

user6713064
- 27
- 4
0
votes
1 answer
Black depth in Red Black tree? How to know if it is balanced?
I have a midterm on tuesday, and am having trouble understanding red black trees. How do I know the tree is balanced? I know it has something to do with the correct amount of black nodes, and the black depth. But I don't quite understand it. I need…

thatsnifty
- 191
- 4
- 14
0
votes
1 answer
Balanced binary search tree from doubly linkedlist
I am trying to write this function that takes in a doublyLinkedList and constructs a balanced binary search tree in place. The TreeNode.left is equivalent to the previous pointer and TreeNode.right is like the next pointer. I am taking inspiration…

user1028904
- 7,450
- 1
- 16
- 7
0
votes
0 answers
Example Tree is Balance or NOT
I have confusion in checking weather the given Tree is Balance or not. To check the tree is balance or not we calculate the mod(difference of height of left subtree - height of right subtree at each node).
Lets take an example tree in figure. The…

Addee
- 663
- 10
- 21