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
- i-spi
- spi+1
- n-i
- 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
Post a Comment