I
I
iDennis2014-07-05 13:30:29
PHP
iDennis, 2014-07-05 13:30:29

What is the best array search algorithm?

I am writing a program in which it is necessary to search for an element in a sorted array, while there may not be an element, then it is necessary to return the result in the form of 3-4 elements suitable for the search query. Are there any 100% algorithms for this task?
I have my own idea, but I want to see yours too.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
volkhin, 2014-07-05
@iDennis

Finding an element in a sorted array is a binary search.
The search for 3-4 elements is apparently some kind of fuzzy search, in the general case there is nothing better than a linear run through the array. Or clarify what you mean. For example, if this is a prefix match, then again, a binary search will do.

S
Sergey, 2014-07-05
Protko @Fesor

binary search or a variation thereof?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question