Questions tagged [red-black-tree]

A red-black tree is a type of self-balancing binary search tree, a data structure used in computing science, typically used to implement associative arrays.

From Wikipedia, Red–black tree:

A red-black tree is a special type of binary tree, used in computer science to organize pieces of comparable data, such as text fragments or numbers.

The leaf nodes of red-black trees do not contain data. These leaves need not be explicit in computer memory — a null child pointer can encode the fact that this child is a leaf — but it simplifies some algorithms for operating on red-black trees if the leaves really are explicit nodes. To save memory, sometimes a single sentinel node performs the role of all leaf nodes; all references from internal nodes to leaf nodes then point to the sentinel node.

Red-black trees, like all binary search trees, allow efficient in-order traversal in the fashion, Left-Root-Right, of their elements. The search-time results from the traversal from root to leaf, and therefore a balanced tree, having the least possible tree height, results in O(log n) search time.

588 questions
-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

how many bits per node

This question comes from an exercise of Algorithm 4. I paste it here as follows: 3.3.19 With 1 bit per node for color, we can represent 2-, 3-, and 4-nodes. How many bits per node would we need to represent 5-, 6-, 7-, and 8-nodes with a binary…
Harveybegood
  • 43
  • 1
  • 4
-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…
-1
votes
1 answer

To store million keys of million length which will be better red black tree or radix tree?

I want to store multiple keys(String) of million length with their objects associated with it. Such that I have to insert in the data structure(rbtree or radix tree) very frequently and have to search quite a low number of time as compared to…
-1
votes
1 answer

Red-black trees, relation between black and red nodes

One of the questions from my homework was to find exact lower bound of (#black nodes)/(#red nodes) in rb-tree. the bound must be not asymptotic. Any suggestions? Your help would be very appreciated.
taypen
  • 13
  • 4
-1
votes
1 answer

Isn't a Red-Black tree better than Binary Search Tree

Just as the title says, with account to scalability, it seems like Red-Black Tree is always better to choose as your data structure. Purely looking at the time complexity, it's either the same or always better. Why would you even ever need to use a…
jimmyhuang0904
  • 181
  • 3
  • 10
-1
votes
2 answers

how to increase all keys values who's bigger or equal to K by D in red-black tree in O(lgn)

im learning algorithms atm and i have a question how can i increase all keys values who's bigger or equal to K by D in red-black tree in O(lgn) Assume the red-black tree has n nodes called S INCREASE-FROM(S,K,D)
-1
votes
1 answer

Red-Black tree implementation in Python simply colours all leaves red, why is this?

I've got code to implement a red-black tree in python. However, when I run my code, it seems all it does is insert the values as if it were a regular BST, then colours all of the internal vertices red. This is a practise assignment for homework, but…
-1
votes
1 answer

Java program to calculate how many red nodes are in a Red-Black Tree

I'm building a program to determine how many red nodes are in a red black tree. I have already implemented a RED BLACK BST which builds the tree after reading a text input. I'm stuck on how to count the number of red nodes? I know the red nodes can…
user3408536
  • 26
  • 1
  • 7
-1
votes
1 answer

RedBlack and AVL tree c++

I want to understand implementation of red black and AVL trees using C++. I checked some websites about them but most of them are complex and difficult to understand. Could you suggest me some resources please?
Tuğcan Demir
  • 113
  • 3
  • 11
-1
votes
1 answer

Red black tree comparison function

I have implemented a red black tree in C. In the C++ map it is possible to provide a custom comparison which only performs the operation value1 < value2. This operation returns true or false but how is the tree implemented without a comparison…
Gustavo
  • 153
  • 12
-1
votes
2 answers

Void Pointers in Red Black Tree

There are two integers x and 7 which are randomly generated integers. The program uses a red black tree member fucntion insert to insert new values into the tree. I'm not understand the arguments of the insert function, more specifically the use of…
Daniel R
  • 103
  • 1
  • 5
-1
votes
1 answer

Red black tree removal - why isn't this correct?

If I want to delete the 64 node from this Red Black Tree, I do the following: https://i.stack.imgur.com/hAFy9.jpg However, the visualization applet I'm using comes to this as result: https://i.stack.imgur.com/3vFaS.jpg Now I assume that they color…
user3125591
  • 113
  • 5
  • 13
-1
votes
1 answer

Red-Black Tree implementation

This is my implementation of a red-black tree class with a nested class of Position,Node,Binary Search Tree,RBI and so on: #include using namespace std; template class RBTree : public…
-1
votes
1 answer

Treemap - Binary Search Tree - Java

How can we insert some nodes into a binary search tree using the TreeMap that implements a Red-Black tree class. Then use the entrySet method to get back a Set version of the TreeMap through which we can Iterate over, and get ALL of the data.
user3023320
  • 11
  • 1
  • 4