红黑树 [英] Red-Black Trees

查看:141
本文介绍了红黑树的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我见过二进制树和几本书我最近读提到的二进制搜索,但我还是在我的研究在计算机科学一开始,我还没有采取真的处理类算法和数据结构中的一个严重的方式

I've seen binary trees and binary searching mentioned in several books I've read lately, but as I'm still at the beginning of my studies in Computer Science, I've yet to take a class that's really dealt with algorithms and data structures in a serious way.

我身边的典型来源(维基百科,谷歌)和用处和执行(尤其是)最描述检查红黑树已经脱落一样密集,不易理解。我敢肯定的人提供必要的背景,它非常有意义,但目前它读起来就像一门外语差不多。

I've checked around the typical sources (Wikipedia, Google) and most descriptions of the usefulness and implementation of (in particular) Red-Black trees have come off as dense and difficult to understand. I'm sure for someone with the necessary background, it makes perfect sense, but at the moment it reads like a foreign language almost.

那么是什么让二叉树有用的一些常见的任务,你会发现自己做,而编程?除此之外,它的树你preFER使用(请附上一个样本实现),为什么?

So what makes binary trees useful in some of the common tasks you find yourself doing while programming? Beyond that, which trees do you prefer to use (please include a sample implementation) and why?

推荐答案

红黑色大树底下好创建均衡的树。与二叉搜索树的主要问题是,你可以让他们不均衡很容易。想象一下,你的第一个号码是15。在那之后的所有的数字越来越小比15.你将有一个树,这是非常沉重的左侧,并没有任何在右侧。

Red Black trees are good for creating well-balanced trees. The major problem with binary search trees is that you can make them unbalanced very easily. Imagine your first number is a 15. Then all the numbers after that are increasingly smaller than 15. You'll have a tree that is very heavy on the left side and has nothing on the right side.

红黑色的树木解决,迫使你的树要当你插入或删除平衡。它完成这通过一系列的祖先节点和子节点之间旋转。该算法实际上是pretty的直白,虽然这是一个有点长。我建议拿起CLRS(Cormen,Lieserson,维斯特和Stein)教科书,算法导论和RB树读书了。

Red Black trees solve that by forcing your tree to be balanced whenever you insert or delete. It accomplishes this through a series of rotations between ancestor nodes and child nodes. The algorithm is actually pretty straightforward, although it is a bit long. I'd suggest picking up the CLRS (Cormen, Lieserson, Rivest and Stein) textbook, "Introduction to Algorithms" and reading up on RB Trees.

的实施也并非真的那么短,所以它可能不是真正的最好的它包括在这里。然而,树用的广泛的为需要访问大量数据的高性能应用程序。它们提供找到的节点,以插入/缺失的一个相对小的开销的一个非常有效的方法。同样,我会建议看CLRS读上他们是如何使用的。

The implementation is also not really so short so it's probably not really best to include it here. Nevertheless, trees are used extensively for high performance apps that need access to lots of data. They provide a very efficient way of finding nodes, with a relatively small overhead of insertion/deletion. Again, I'd suggest looking at CLRS to read up on how they're used.

虽然BSTS没有明确地使用 - 使用一般树的一个例​​子是在几乎每一个现代RDBMS。同样的,你的文件系统几乎可以肯定psented作为某种树形结构的重新$ P $和文件也同样索引的方式。树木供电谷歌。树木功率几乎每一个网站在互联网上。

While BSTs may not be used explicitly - one example of the use of trees in general are in almost every single modern RDBMS. Similarly, your file system is almost certainly represented as some sort of tree structure, and files are likewise indexed that way. Trees power Google. Trees power just about every website on the internet.

这篇关于红黑树的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆