| [reply] |
I recently come across the concept of b-trees. I want to know in which sort of suitations it is applicable. can u state some examples of its usage?
B-Trees are used in databases (homemade and commercial). They are useful any time you have a lot of data you need to keep sorted and quickly accessible. I have always looked at B-Tree's as kind of a Binary Search Tree on steroids.
is there any other way of acheiving the same?
Sure, there are many ways to store sorted items for fast retrieval, some are good ways, some are bad ways. B-Tree's have the benefit of being a well tested and proven data-structure. But Binary Search Tree's are good too, although they can quickly get out of hand if you have a lot of items. Regular perl hashes are good if you don't need your data to be always sorted, and don't mind sorting it when you need it. It's really about what your specific needs are that should drive the choice of implementation.
Is it worth learning?
Well, most B-Tree implemenations are used much like a hash is, so there is not much to learn there. If by this you mean, "is it worth implementing it", then my answer would be, yes. It is always worth learning something new, and a well documented and understood data-structure like a B-Tree is a good place to start.
| [reply] |
Thanks guys for ur replies.
-Lalith
| [reply] |
If you want to keep data that's retrievable by keys in sorted order, try using Tie::Hash::Sorted.
It makes use of Perl's internal hash structures, but keeps the keys sorted. If you don't need the keys sorted, just use regular hashes.
Hashes give you the better access time for storage or retrieval elements than trees or similar structures (such as skip lists), though they do take up more memory. (However, in Perl, this doesn't matter as much since most Perl implementations of trees and similar structures use more memory anyway.)
If it's a matter of keeping the data in a file rather than memory, you could still use a hash but tie it to a DBM file.
Unless you have some very particular or peculiar needs, it's best to stick with Perl's native data structures. You'll have less to worry about in terms of code maintenance, and your code will be cleaner and easier to read.
| [reply] |
Which question does that answer?
| [reply] |