red-black-tree

Red Black Tree deletion algorithm

北城以北 提交于 2019-12-03 15:04:27
问题 From "Introduction to Algorithms 2nd edition" I got this deletion algorithm: /* RB-DELETE(T, z) 1 if left[z] = nil[T] or right[z] = nil[T] 2 then y ← z 3 else y ← TREE-SUCCESSOR(z) 4 if left[y] ≠ nil[T] 5 then x ← left[y] 6 else x ← right[y] 7 p[x] ← p[y] 8 if p[y] = nil[T] 9 then root[T] ← x 10 else if y = left[p[y]] 11 then left[p[y]] ← x 12 else right[p[y]] ← x 13 if y != z 14 then key[z] ← key[y] 15 copy y's satellite data into z 16 if color[y] = BLACK 17 then RB-DELETE-FIXUP(T, x) 18

Using STL's Internal Implementation of Red-Black Tree

给你一囗甜甜゛ 提交于 2019-12-03 12:59:44
I understand that my STL (that comes with g++ 4.x.x) uses red-black trees to implement containers such as the map. Is it possible to use the STL's internal red-black tree directly. If so, how? If not, why not - why does STL not expose the red-black tree? Surprisingly, I cannot find an answer using google. Edit: I'm investigating using the red-black tree as a solution to the extra allocator constructor call on insertion. See this question . My STL uses red-black trees for map implementation. Actually - the answer is very simple, and independent of your version of gcc. You can download the stl

Is kd-tree always balanced?

扶醉桌前 提交于 2019-12-03 12:35:05
I have used kd-tree algoritham and make tree. But i found that tree is not balanced so my question is if we used kd-tree algoritham then that tree is always balanced if not then how can we make it balance ?. We can use another algoritham likes AVL or Red-Black for balancing kd tree ? I have some sample data for that i used kd-tree algoritham but that tree is not balanced. (14,31), (15,32), (17,42), (16,44), (18,52), (16,62) This is a fairly broad topic and the questions themselves are kind of general. Hopefully this will give you some useful insights and material to work with: Kd tree is not

In red-black trees is top-down deletion faster and more space efficient than bottom-up deletion?

别等时光非礼了梦想. 提交于 2019-12-03 11:40:25
问题 Per this page http://www.eternallyconfuzzled.com/tuts/datastructures/jsw_tut_rbtree.aspx "Top-down deletion" is an implementation of a red-black tree node removal that pro-actively balances a tree by pushing a red node down through the tree so that the leaf node which is being removed is guaranteed to be red. Since the leaf node is guaranteed to be red, you don't have to worry about re-balancing the tree, because deleting a red leaf node doesn't violate any rules and you don't have to perform

Interval tree algorithm that supports merging of intervals with no overlap

好久不见. 提交于 2019-12-03 07:13:55
问题 I'm looking for an interval tree algorithm similar to the red-black interval tree in CLR but that supports merging of intervals by default so that there are never any overlapping intervals. In other words if you had a tree containing two intervals [2,3] and [5,6] and you added the interval [4,4], the result would be a tree containing just one interval [2,6]. Thanks Update: the use case I'm considering is calculating transitive closure. Interval sets are used to store the successor sets

Hash tables v self-balancing search trees

喜你入骨 提交于 2019-12-03 05:18:07
I am curious to know what is the reasoning that could overweighs towards using a self-balancing tree technique to store items than using a hash table. I see that hash tables cannot maintain the insertion-order, but I could always use a linked list on top to store the insertion-order sequence. I see that for small number of values, there is an added cost of of the hash-function, but I could always save the hash-function together with the key for faster lookups. I understand that hash tables are difficult to implement than the straight-forward implementation of a red-black tree, but in a

Concatenating red-black trees

纵饮孤独 提交于 2019-12-03 03:47:36
问题 The OCaml standard library has a wonderful Set implementation that uses a very efficient divide-and-conquer algorithm to compute the union of two sets. I believe it takes whole subtrees (not just single elements) from one set and inserts them into the other set, rebalancing when necessary. I'm wondering if this requires the height information that is kept in the AVL tree that OCaml uses or if this is also possible with red-black trees. For example, is it possible to concatenate a pair of red

In red-black trees is top-down deletion faster and more space efficient than bottom-up deletion?

∥☆過路亽.° 提交于 2019-12-03 02:09:25
Per this page http://www.eternallyconfuzzled.com/tuts/datastructures/jsw_tut_rbtree.aspx "Top-down deletion" is an implementation of a red-black tree node removal that pro-actively balances a tree by pushing a red node down through the tree so that the leaf node which is being removed is guaranteed to be red. Since the leaf node is guaranteed to be red, you don't have to worry about re-balancing the tree, because deleting a red leaf node doesn't violate any rules and you don't have to perform any additional operations to re-balance and restore red-black'ness. "Bottom-up deletion" involves

Applications of red-black trees

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-03 01:41:35
问题 What are the applications of red-black (RB) trees? Is there any application where only RB Trees can be used and no other data structures? 回答1: A red-black tree is a particular implementation of a self-balancing binary search tree, and today it seems to be the most popular choice of implementation. Binary search trees are used to implement finite maps, where you store a set of keys with associated values. You can also implement sets by only using the keys and not storing any values. Balancing

When to choose RB tree, B-Tree or AVL tree?

喜夏-厌秋 提交于 2019-12-03 01:30:49
问题 As a programmer when should I consider using a RB tree, B- tree or an AVL tree? What are the key points that needs to be considered before deciding on the choice? Can someone please explain with a scenario for each tree structure why it is chosen over others with reference to the key points? 回答1: Take this with a pinch of salt: B-tree when you're managing more than thousands of items and you're paging them from a disk or some slow storage medium. RB tree when you're doing fairly frequent