String matching

The naive brute force approach: It is very simple to code but there are little things to look for (as least I have to) with respect to optimization. The outer loop runs for text, the inner loop runs for pattern with one more condition - **i+ len(pattern) <= len(text)**. int bruteForce (text, pattern) for (i =0; i < len(text); i++): for (j = 0; j < len(pattern) && **i+ len(pattern) <= len(text)**; j++): //instead of i+j < len(text) if text[i+j] ! [Read More]