java - Time complexity of a method that checks a sublist in a linked list -


i need write method public int sublist (charlist list) gets list , returns how many times list exist.

for example:

my list a b c d b g e

parameter list ita b return 2.

my list b b b b

parameter list b b return 3.

the method should efficient possible.

currently problem don't know mean when efficient possible, if loop through list n times, , everytime find same character loop on both list , go o(n^2)? there better way make o(n) or below?

this in effective searching string in string, o(n) complexity

http://en.wikipedia.org/wiki/knuth%e2%80%93morris%e2%80%93pratt_algorithm

and find first occurrence can keep looking next occurrence in remaining list it's still o(n) find occurrence


Comments

Popular posts from this blog

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -

php - Magento - Deleted Base url key -

android - How to disable Button if EditText is empty ? -