English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

3 answers

Are you meaning searching yahoo! Answers? Your question is hard to understand. try to rephrase it and we'll see what answer we can come up with. Good luck

2006-08-24 19:52:00 · answer #1 · answered by STEPHEEDEE 4 · 0 0

In fact, it usually *doesn't* take "constant" time - "constant time" means it takes the same amount of time no matter *how* many you need to search through - 1, 10, or a million. Most simplistic array searches take what is known as O(n) time - which means the time taken is proportional to the number of entries to search. 20 takes twice as long as 10, and so on.

If you can afford the added overhead of keeping the array sorted, you can probably get it down to O(log n) - which means it's proportional to the logarithm of the number of entries - so if you have 256 times as many entries, it only takes 8 times the time (because log2(256)=8). Hint: Binary search is your friend...

The only way to get an array search down to near-constant time is to use a hashing function, which has hits own limitations - in particular, if your hashing function depends on the variable FOO, it becomes very fast to find the entry that corresponds to FOO - but any *other* access (such as "find entries with a value greater tha 100, for instance) is still slow....

2006-08-24 20:03:39 · answer #2 · answered by Valdis K 6 · 1 0

I guess your question is either wrong or incorrectly worded. Searching in an array does NOT take constant time. If the array is not sorted, it takes time proportional to the length of the array. But, for a sorted array, if you use an algorithm like binary search, the time is proportional to log(length).

2006-08-24 19:55:28 · answer #3 · answered by Happy2Help 2 · 1 0

fedest.com, questions and answers