Knuth Morris Pratt algorithm comparison -


i have been studying exams when came across problem, guys please

for alignment of pattern p , text t, suppose mismatch occurs @ p[i+1] , t[k] during execution of kmp algorithm how many times t[k] come comparison in total during execution of kmp algorithm (spi non-optimized)

the possible solutions came across are

  1. i-spi
  2. spi+1
  3. n-i
  4. n-spi

but of them fail on scenarios,

there no single answer cases.

still can give upper bound on number of comparisons , found if symbols in p same. try , compute that.

if not enough try using property: kmp compare t[k] against p[spi] , against p[spspi+1] , on until 1 of 2 options happens:

  • the given letter matches t[k]
  • the value of given sp 0

the 2 above may happen in many different ways depending on p , t , impossible give closed formula.


Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -