Questions tagged [red-black-tree-insertion]
31 questions
0
votes
1 answer
Why do I have a red child from a red node in my Red Black Tree?
in my Red Black Tree I have red child from red node, what was wrong in my code?
The struct for RBTree:
num COLOR { RED, BLACK };
// struct RBT
typedef struct treeRBTnode {
int key;
enum COLOR color;
struct…

Mich
- 1
- 1
0
votes
1 answer
Why we need fix color when a black node of Red Black Tree has two children both red?
I'm learning about how to implement Red Black Tree in Java, i have consulted the source code from Sanfoundry: https://www.sanfoundry.com/java-program-implement-red-black-tree/
But i can't understand the function to insert node
The code is…

Arthur
- 3
- 2
0
votes
0 answers
C++ Building RB Tree, nilNode not black
I am working on building a Red-Black tree as a school project I am done with the code and all but for some reason when I run the programs test cases I get false on the nilNode being black and I cant figure out why that is.
Program Code
#ifndef…

Abdulrahman Sakah
- 31
- 4
0
votes
3 answers
On Red Black Tree rotation, is the black height of all nodes preserved?
I was asked this question in an exam, but I'm not really convinced with the answer from the teacher, and I would like to ask what do you think about it.
A rotation on a red-black tree...
preserves the black height of all nodes.
preserves in-order…

Marcelo
- 1
- 1
0
votes
0 answers
Red-Black tree help C
I'm a novice and i'm trying to create a rb tree in C.I've managed to make the code below from CLRS's introduction to algorithms and data structures pseudocode.The problem is no matter how many times i run it,the program crashes if it trys to use one…

AlexandrosS
- 77
- 7
0
votes
0 answers
Segmentation Fault when Passing Node Pointer to Function
I am implementing Red-Black Trees and I cannot seem to debug a segmentation fault that occurs when calling the fixup() function. The backtrace from gdb is provided below. The functions can be seen below the backtrace. Is it incorrect to pass a…
0
votes
1 answer
BST and RBT insersion worse case
The insertion complexity of RBT and BST are O(logn).
I've implemented both of them in Java and give them a lot of numbers and measured the time in seconds to analyze the performance.The numbers I have plotted seem to show that it is O(n). Can anyone…

pouria.vzr
- 65
- 1
- 8
0
votes
2 answers
Unusual Java implementation of red/black tree node insertion
I'm writing a program for class in Java regarding red/black trees. I've got a good understanding of how they usually work, and am supposed to use a recursive insertion method. What I would typically use is below, to match my professor's Node…

2rtmar
- 123
- 1
- 1
- 6
0
votes
1 answer
red-black tree invalid conversion
I am having trouble getting past the initialization of the red black tree. Whenever I compile I get the following error.
redBlackTree.h:81:28: error: invalid conversion from ‘long int’ to ‘nodeColor’ [-fpermissive]
nodeType *x = new…

gamer1996
- 5
- 3
0
votes
2 answers
red black tree insertion
I inserted node 36 in the red black tree and the following red black tree resulted:
my problem is that how to handle double red in this special case? is it case 2 or 3?

HMdeveloper
- 2,772
- 9
- 45
- 74
-1
votes
1 answer
Null Exception When Balancing Red-Black Tree After Insertion
I'm attempting to write a function to balance a red-black tree after inserting nodes into it, but I'm getting a null pointer exception. On line 156, when I assign temp to node.parent.parent.right, temp is null, meaning node.parent.parent.right is…

Lucky_13
- 1
-1
votes
1 answer
What makes this Red/Black tree left heavy and is it correct?
So I was messing around with a Red/Black Tree visualiser (https://www.cs.usfca.edu/~galles/visualization/RedBlack.html), and came across the following tree
(inserted in the order of 10, 40, 25, 35, 30, 45). I understand an AVL tree cannot have a…

M.M.
- 19
- 2
-1
votes
1 answer
Insert elements into a red/black tree that just require color changes and no rotations?
How can I find a sequence of elements that, if inserted into a red/black tree, would be balanced purely by changing colors rather than performing rotations?

Kasra
- 1
-1
votes
1 answer
What does private in the scope of the return value of a function definition/implementation mean (c++)?
So I'm looking over some code I found in relation to a project I'm working on for school and I found a function implementation that has private before the return value and I was hoping someone could explain its purpose and use to me. I haven't been…

hapless_automaton
- 31
- 7
-1
votes
1 answer
What if uncle is black and parent is black when inserting a node to red black tree?
I know there are two cases which uncle is black in red black trees when inserting a new node. But in all the cases parent is red. if parent is black there is no violation. what shall I do in such situation in a red black tree?

Lakindu Akash
- 964
- 1
- 11
- 28