red-black-tree

Red-Black tree: Split/Concatenate in log(n) time

我的未来我决定 提交于 2021-02-19 07:38:59
问题 According to Ron Wein your able to do split and concatenation of red-black tree's in O(log(n)) time. See his artikle: Efficient Implementation of Red-Black Trees with Split and Catenate Operations However I'm still not convinced that the running time of split really is true. The idea is that split uses worst-case log(n) concatenatations. These concat's is done fast as we can find the node, p, by remembering the p, from last concatenate. The problem is that concatenation starts the fix-up

Red-Black tree: Split/Concatenate in log(n) time

安稳与你 提交于 2021-02-19 07:38:30
问题 According to Ron Wein your able to do split and concatenation of red-black tree's in O(log(n)) time. See his artikle: Efficient Implementation of Red-Black Trees with Split and Catenate Operations However I'm still not convinced that the running time of split really is true. The idea is that split uses worst-case log(n) concatenatations. These concat's is done fast as we can find the node, p, by remembering the p, from last concatenate. The problem is that concatenation starts the fix-up

Benefit of a sentinel node in a red black tree?

半城伤御伤魂 提交于 2021-02-19 04:27:06
问题 I created a doubly-linked list, and the benefits of a sentinel node were clear - no null checks or special cases at list boundaries. Now I'm writing a red black tree, and trying to figure out if there is any benefit to such a concept. My implementation is based on the last two functions in this article (top down insertion/deletion). The author uses a "dummy tree root" or "head" to avoid special cases at the root for his insertion/deletion algorithms. The author's head node is scoped to the

What is the formula for the minimum number of nodes in a red-black tree of height h?

一曲冷凌霜 提交于 2021-02-16 20:12:07
问题 I have read that it is log(n+1) <= h <= 2*log(n+1) where log is in base 2. However, when trying this out on a few known minimum heights, it does not always work out. So far I know that: For for h = 1, minimum # of nodes = 2. For h = 2, minimum nodes = 4. For h = 3, minimum nodes = 10. However these were done purely by tracing it out using the rules for red-black trees. Should I be taking note of the black-height when trying to find this or is my approach/calculations just completely wrong?

What is the formula for the minimum number of nodes in a red-black tree of height h?

守給你的承諾、 提交于 2021-02-16 20:11:28
问题 I have read that it is log(n+1) <= h <= 2*log(n+1) where log is in base 2. However, when trying this out on a few known minimum heights, it does not always work out. So far I know that: For for h = 1, minimum # of nodes = 2. For h = 2, minimum nodes = 4. For h = 3, minimum nodes = 10. However these were done purely by tracing it out using the rules for red-black trees. Should I be taking note of the black-height when trying to find this or is my approach/calculations just completely wrong?

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

為{幸葍}努か 提交于 2021-02-05 12:27:21
问题 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 the lowest key.The program stops working and gives the C4716 warning . the keys are int array[] = { 50, 26, 45, 34, 23, 78, 84, 93, 14, 16, 100, 57, 62}; int Tree::findsmallest() { return findsmallestprivate(root); } int Tree::findsmallestprivate

deleteMin Left Leaning read black tree need more explanation

我是研究僧i 提交于 2020-06-17 13:08:47
问题 I'm reading Left Leaning Red Black Tree in algorithms 4th edition, by Robert Sedgewick. I spent several days trying to understand the deleteMin as a warmup to understanding delete and this is my final question in my head about deleteMin. public void deleteMin() { root = deleteMin(root); root.color = BLACK; } private Node deleteMin(Node h) { if (h.left == null) return null; if (!isRed(h.left) && !isRed(h.left.left)) h = moveRedLeft(h); h.left = deleteMin(h.left); return fixUp(h); } when h.left

deleteMin Left Leaning read black tree need more explanation

烈酒焚心 提交于 2020-06-17 13:07:32
问题 I'm reading Left Leaning Red Black Tree in algorithms 4th edition, by Robert Sedgewick. I spent several days trying to understand the deleteMin as a warmup to understanding delete and this is my final question in my head about deleteMin. public void deleteMin() { root = deleteMin(root); root.color = BLACK; } private Node deleteMin(Node h) { if (h.left == null) return null; if (!isRed(h.left) && !isRed(h.left.left)) h = moveRedLeft(h); h.left = deleteMin(h.left); return fixUp(h); } when h.left

Why red-black tree based implementation for java TreeMap?

房东的猫 提交于 2020-01-31 03:40:06
问题 The third paragraph of wikipedia's article on AVL trees says: "Because AVL trees are more rigidly balanced, they are faster than red-black trees for lookup-intensive applications." So, shouldn't TreeMap be implemented using AVL trees instead of red-black trees(as there will be more look up intensive applictions for a hashing based data structure ) ? 回答1: Red-Black trees are more general purpose. They do relatively well on add, remove, and look-up but AVL trees have faster look-ups at the cost

Red-black tree access by ordinal index

坚强是说给别人听的谎言 提交于 2020-01-23 11:53:15
问题 I have a red-black tree (binary tree, all the leaves are within 2 levels). I can navigate through nodes: to left, right or parent. I know the entire count of nodes. I have to find the N-th smallest element in a tree. Is there any way to do this faster than in O(n)? Any ideas of optimizing access by index? 回答1: In each node X you should store, how many nodes are in subtree with X as a root. count(LEAF) = 1 count(NODE) = count(NODE->LEFT) + count(NODE->RIGHT) + 1 During each insert/delete you