Answer the question
In order to leave comments, you need to log in
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
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.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question