title: Fastest algorithm to find a string in an array of strings?
body: <p>This question is merely about algorithm.
  In pseudo code is like this:</p>
  
  <pre><code>A = Array of strings; //let's say count(A)  = N
  S = String to find;   //let's say length(S) = M
  
  for (Index=0; Index&lt;count(A); Index++)
    if (A[Index]==S) {
      print "First occurrence at index\x20"+Index;
      break;
    }
  </code></pre>
  
  <p>This for loop requires string comparison N times (or byte comparison N*M times, O(N*M)). This is bad when array A has lots of items, or when string S is too long.</p>
  
  <p>Any better method to find out the first occurrence? Some algorithm at O(K*logK) is OK, but preferable at O(K) or best at O(logK), where K is either N or M.</p>
  
  <p>I don't mind adding in some other structures or doing some data processing before the comparison loop.</p>