I was recently asked to create a program to find best matches in text fragment. I have successfully written this program but I do have a question about its time complexity.
The time that my program takes: O(m + n + p) First off, I totally don't believe that is the time your program takes.
You are asked to parse a query and find the words in a document. This is a complex cross reference problem because you have characters in multiple words that have to match in exact character sequence with the same sequence randomly placed in the document. Most students make a hash of this and create an N squared process by taking the first word and scanning the document for the occurrences of that word and then doing the same thing with the next and next and next. You need to develop an effective means of cross-referencing the contents of the document and the words or you will create an N^2 process. Offhand, create a dictionary of words in the query, parse the document into words and match them against the dictionary of words to find. That would be mLogn
m = number of words the document
n = number of words in the dictionary you create in an nLogn process.
You were mentioned in an article I wrote because it solves a similar but much more complex word matching problem:
http://www.codeproject.com/Tips/882998/Performance-Solving-WonderWord-Puzzle
Your first respondent was correct while making an assumption that I didn't that you had to find the characters without using breaks, but his O notation, I believe is wrong because they are multiplied, not added together and p is irrelevant.