in reply to Re^2: Modified Binary Search
in thread Modified Binary Search

That makes an O(log N) algorithm into O(N).

Obviously it does not!

As for any binary search algorithm you have a previous step where you build the array, sorting something, loading it from disk, whatever. This operation is O(N) in the best case and usually O(NlogN) because of the sorting.

Once that array is build you can perform binary searches over it with cost O(logN). In order to amortize the cost of building the array the number of binary searches has to be high (otherwise, there are better algorithms).

The algorithm I have proposed increments the cost of the setup step but does not change its complexity because it already was O(N) at best.

Also, if the number of repeated strings is high, @start would be considerably smaller than @a and so less operations will be performed per binary search. That means that if the number of binary searches to be carried out is high enough, my algorithm will actually be faster than any other one attacking @a directly.