简体   繁体   中英

AVL Tree vs Balanced Tree

AVL tree is a well known internal memory data structure whereas Balanced tree is known external memory data structure. 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.

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.


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:

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).

But, while BTrees can be a type of balanced tree, it's again only one type.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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