[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Search Algorithm



On Mon, 2004-11-15 at 10:25 -0800, Sergio Basurto Juarez wrote:
> First of all, I want to leave clear that I know that
> the question that I am asking for, does not have to do
> with this list, but I dare to ask this question here
> because I am sure that here are a lot of good
> programming and scientisitics guys and may be one of
> you can help me.
> 
> I am programming a function to search in an array, I
> know there is the binarysearch algorithm, an other
> good methods to search, but I want something that does
> not take to long.

If the data points are ordered, a binary search is pretty darned
fast.  And a simple algorithm, too.  Unless you need to wring the
last nanosecond of speed from your app, a good, simple algorithm
is better than a slightly better complicated algorithm.

For an array of 8240 elements, you'd need a max of (dredging up 
college class...) log2(16384) ( = 14) memory accesses.

-- 
-----------------------------------------------------------------
Ron Johnson, Jr.
Jefferson, LA USA
PGP Key ID 8834C06B

The purpose of the military isn't to pay your college tuition or
give you a little extra income; it's to "kill people and break
things".
Surprisingly, not everyone understands that.

Attachment: signature.asc
Description: This is a digitally signed message part


Reply to: