简体   繁体   English

AVL树与平衡树

[英]AVL Tree vs Balanced Tree

AVL tree is a well known internal memory data structure whereas Balanced tree is known external memory data structure. AVL树是众所周知的内部存储器数据结构,而平衡树是已知的外部存储器数据结构。 Why can't we use Balanced trees for internal memory also? 为什么我们也不能将平衡树用于内部存储器?

You very much can have balanced trees in internal memory. 您非常可能在内部存储器中拥有平衡的树。 An AVL tree is simply one type of balanced tree and there are others as well, such as red-black and 2-3-4 trees. AVL树只是平衡树的一种,还有其他一些树,例如红黑树和2-3-4树。

So, I'm not sure where you got the idea balanced trees couldn't exist in internal memory but I'd be rethinking that if I were you. 因此,我不确定您从何而来的想法是内部存储器中不存在平衡树,但如果您是我,我会重新考虑。

And, in fact, you could put an AVL tree on disk as well if you were so inclined. 而且,实际上,如果您愿意,也可以在磁盘上放置AVL树。


I suspect, based on your comments, that what you may be thinking of is a BTree which is like a binary tree but each node can hold more than one value and have more than two children, such as: 根据您的评论,我怀疑您可能在想的是一个BTree,它就像一个二叉树,但是每个节点可以容纳多个值并具有两个以上的子级,例如:

root node -,
           |
           V
 +------+------+------+
 | Val1 | Val2 | val3 |
 +------+------+------+
/       |      |      \
<other nodes down here>

That's different to the more general term 'balanced tree' and they're often used in disk situations as you tend to want to read/write entire blocks/clusters/sectors at a time. 这与更一般的术语“平衡树”不同,它们通常用于磁盘情况,因为您倾向于一次读/写整个块/集群/扇区。

So, if you can fit ten values into a disk block, it's more efficient to use a BTree (whereas memory does not have a concept of block size so it can be preferable to use a simpler algorithm - BTrees have to combine both tree search to find a node and linear/binary search to locate the value in the node). 因此,如果您可以在磁盘块中容纳10个值,则使用BTree会更有效(而内存没有块大小的概念,因此最好使用更简单的算法-BTree必须将两个树搜索结合起来找到一个节点并进行线性/二进制搜索以该节点中定位该值)。

But, while BTrees can be a type of balanced tree, it's again only one type. 但是,尽管B树可以是平衡树,它再一次只有一个类型。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM