Is there any search algorithm with time complexity O(1)?
Search Algorithm = Finding an element x from n elements.
Is there any search algorithm with time complexity O(1)?
Search Algorithm = Finding an element x from n elements.
Although I would be surprised if a search algorithm that was deterministically O(1) existed, the good news is that you can get lookup that is arbitrarily close to 100% accurate with O(1) add and lookup operations using a bloom filter. (http://en.wikipedia.org/wiki/Bloom_filter)
Similarly, a variety of techniques exist for those sets with finite sizes (http://en.wikipedia.org/wiki/Perfect_hash_function) although if those set sizes are very large problems arise in practice
However, to the general case, the answer is, to the best of my knowledge, no. And certainly not in any practical applications.
Yes, create a huge array, so that each possible value has one slot. Storing values and looking up values has time complexity O(1).
If the initialisation time is counted also, then it's absolutely impossible to make an O(1) search algorithm. Searching an array without preprocessing can never be better than O(n), and there is no way to preprocess n items in O(1).
O(n) time. I don't know whether this time counts as part of search time, considering how vague the question is.O(1) algorithm is completely out of question.