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

Extending classes and instantiation

Let's suppose we have a RedBlack-Tree implementation which consists of 2 classes: Tree - holds the pointer to the Node *root of the tree and defines all operations over the tree (Insert, Delete, etc) Node - a data storage, which holds pointers to…
zerkms
  • 249,484
  • 69
  • 436
  • 539
-1
votes
1 answer

Sorted Array to 2-4+ Tree in Linear Time

I need help with the following question: Describe an algorithm that given a sorted array of size n builds a 2-4+ tree that contains the same keys as the array. The algorithm should run in time O(n). I already know how to build a red black tree from…
Robert777
  • 801
  • 3
  • 12
  • 24
-2
votes
2 answers

Maximum height of a node in a red-black tree

If we have a node in a red-black tree with a black height of 3, what is the maximum height allowed for the node?
-2
votes
1 answer

How many red nodes does a red-black-tree with black height bh(t) have(at most)?

How many red nodes does a red-black-tree with black height bh(t) have(at most)? bh(t) = It is the number of black nodes on any simple path A red black tree in our lecture is a binary search tree with All node have 2 children(except leaf nodes) Evry…
ChoRisk
  • 5
  • 2
-2
votes
1 answer

What structure is underlying Java TreeSet?

Java TreeSet is a red-black tree self balancing structure. But what is the structure to store the data? Array or linked list?
arminvanbuuren
  • 957
  • 1
  • 9
  • 16
-2
votes
1 answer

seach for a specific node in an RB-tree

Suppose I have a RB-tree consisting of numbers which correspond to people's age; and suppose each node also have a gender (female or male). My question is, how to get a specific number from that tree using OS-SELECT and rank value? Specific number…
thinwater
  • 11
  • 2
-2
votes
1 answer

Segmentation Fault in a Simple Red-Black Tree

I'm trying to build a simple red-black tree in C. Unfortunately, I have encountered a segmentation fault that I'm not sure how to fix. I've included the code below and marked to line where the fault is occurring. #include #include…
M. Lloyd
  • 1
  • 1
-2
votes
2 answers

warning C4715: not all control paths return a value c++

i made two functions, one to find and return smallest key in a red - black tree and the other one returns a pointer to a particular node with that node's key as input.These functions work fine with all nodes except the nodes with the highest key and…
T-man
  • 3
  • 1
  • 3
-2
votes
2 answers

Where should I put "public static void main(String[] args)" in this program?

I have a program that is supposed to allow me to create an RB Tree, but when I run it, I get the following error: run: Error: Main method not found in class mainrbt.MainRBT, please define the main method as: public static void main(String[]…
user3274463
  • 53
  • 1
  • 4
  • 12
-2
votes
1 answer

Maximum number of red nodes in red black tree

In a red-black tree with n nodes, what is the maximum number of red nodes (assuming the root is black)? Is it O(n)?
marc_
  • 105
  • 1
  • 7
-2
votes
1 answer

Red Black Trees complexities

I was studying Red Black trees and I was wondering what is the time complexity for assigning black heights for each node when we do a process like insert ?
user3085336
  • 13
  • 1
  • 1
  • 3
-3
votes
1 answer

Red Black tree deletion behaviour

I have a red black tree as follows: 8B / \ 4R 10B / \ / \ 2B 6B 9B 11B / \ / \ 1B 3B 5B 7B I want to delete 10. what will happen ?
adam
  • 37
  • 5
-3
votes
1 answer

Not getting correct coloring of Red Black Tree nodes

I have finally figured out how to successfully insert items into my red black tree without getting any segmentation faults, however, my coloring of my nodes are off. I am trying to insert the following values into the tree in the following order: 4…
Zack Sloan
  • 101
  • 3
  • 13
-3
votes
1 answer

Internal storage of a std::map as a red-black tree

In this map example: std::map m; for (int i = 0; i < 1000; i++) m[2*i] = i; for (i = 0; i < 1000; i++) // just an example of filling a map m[2*i + 1] = i; how to know how the internal "red-black tree" will look like? Which…
Basj
  • 41,386
  • 99
  • 383
  • 673
-3
votes
1 answer

Percentage of red nodes in a red-black tree

How would I go about finding the percentage of red nodes in a red-black tree? I'm familiar with the properties of a red-black tree, but just can't seem to wrap my head around how to approach this. One idea I have is simply traversing the tree after…
1 2 3
39
40