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.

79 questions
0
votes
1 answer

C++ balanced tree / call order in recursive function

I'm writing an implementation of a CART tree at the moment, which is binary tree used in machine learning. It is trained recursively as sketched in the following code: struct Node { Node * parent; Node * left; Node * right; }; void…
davidhigh
  • 14,652
  • 2
  • 44
  • 75
0
votes
1 answer

How to create the bottom up splay tree from the following sequence

This is the sequence 20,10,5,30,40,57,3,2,4,35,25,18,22,27 I've tried it by making every new inserted node as the root but it's not working. Can anybody give me step by step explanation?
0
votes
1 answer

logic check of a function to find if a tree is balanced or unbalanced

I am reading the Coding book and one of the questions asks to write a function that checks if a binary tree height is balanced or not. For example, if a tree's right subtree has a height of 4 (meaning its depth is 4) and the left subtree has a depth…
ArmenB
  • 2,125
  • 3
  • 23
  • 47
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
  • 3
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
  • 14
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…
Ree
  • 863
  • 2
  • 18
  • 38
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,743
  • 3
  • 24
  • 38
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
  • 9,570
  • 9
  • 43
  • 78