Amazon interview question

Write a function to search for a string within another string. Analyze it's complexity, and propose optimizations.

Interview Answers

Anonymous

19 Jan 2011

Represent the string in Suffix Tree and u can find the pattern in O(m) time.

2

Anonymous

5 Feb 2011

Use Boyer-moore algorithm.

1

Anonymous

23 Feb 2011

@jimmy thanks http://www.movsd.com/bm.htm

Anonymous

13 Mar 2011

I wonder if you had to code BM algorithm during the interview. That would be... hard...

Anonymous

11 Dec 2011

Use Robin-karp or KMP algorithm