Fastest search algorithm for unsorted array.

Which is the fastest search algorithm for unsorted array?

If the array is not sorted then you have to search for the element by iteration ,linear search . There is no better way than O(n).Although if you’re searching multiple times, it would be better if you sort ( O(nlogn)) it and then use binary search to make the following searches fast in O(log(n)).

1 Like

It depends upon your question! If the size of an array element is upto 10e6 and if the queries on array elements are more then it would be better to use Hashing rather than linear search or Binary search.

Otherwise of size would go upto 10e18 then it you have to must use Binary search!!

Or if you are a C++ programmer then you can use Map<> or unordered_map<> STL Container wisely that also use Hashing technique with log(N) complexity in Map<> or may be constant average time complexity in unordered_map<>(Depends upon implementation or uses!

To know more these container of STL Click on this LINK

//