Re: Hashed stringlist or binary searchtree or ????
From: Jens Gruschel (nospam_at_pegtop.net)
Date: 10/09/03
- Next message: Ian Kirk: "Re: simple question"
- Previous message: Matthias Czarnetzki: "Re: procedural variables and methods"
- In reply to: Thomas Mueller: "Re: Hashed stringlist or binary searchtree or ????"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Thu, 9 Oct 2003 14:35:52 +0200
> If you have got a good hash function (that is, one that is fast and
produces
> a good distribution over the target values for the strings you want to
> store) this will always be much faster than a binary tree. But the hash
> function is the key so chose it wisely.
"Much faster"? Well "much" is very relative. It's faster, yes (except for
some special cases), but using trees is fast enough for most problems. Of
course you can measure the time for 1 million searches in 1 billion items,
but I doubt you will notice a difference in speed for every-day
applications. Even sorted lists and binary searching is quite fast - log2(1
billion) is about 30, and 30 comparisons take... well.. how many GHz have
you got?
I agree that probably nothing else is as fast as a hash table (and I use
them often), but for some problems other solutions are better, it really
depends. Hash tables for example need a capacity of about twice the items
you want to store to work efficient (and it shoud be a prime number). Most
implementations take care of this, so that's not a problem (and good
implementations only need a few bytes for empty items). But if you know how
hash tables / trees / lists etc work internally (and I really think every
programmer should know it), it's much easier for you to decide what to
choose. And as Thomas said, there are even different ways to build a hash
code, and different ways for probing (linear, quadratic etc), so some hash
tables might be better for your problem than others.
Jens
- Next message: Ian Kirk: "Re: simple question"
- Previous message: Matthias Czarnetzki: "Re: procedural variables and methods"
- In reply to: Thomas Mueller: "Re: Hashed stringlist or binary searchtree or ????"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|