string - Confused regarding pre-processed table in KMP -
Looking at the KMP algorithm, and confused about a specific row in KMP that calculates the suffix-prefix table of the numbers.
Define the variable: An integer, position 2 (In the current situation, we do computing in t Are) an integer, CNG ??? 0 (Zero-based index in the W of the next character of the current candidate sub-group) (First few values have been set but different from the suggestion from the algorithm) T [0] One ???? -1, t [1] a ???? 0 When the position is less than the length of W, we do: (first case: the object is turned on) W [pause -1] = w [cnd], cd c cnd + 1, t [pause] a ???? CNG, POS one ???? Position + 1 (second case: this is not, but we can come back) Otherwise, if CD & gt; 0, CDAD Do T [Cnd] (Third Case: We have run away from the candidates. Note CND = 0) Otherwise, T [Pause] 0, Position POS + 1 above from Wikipedia Straight away I'm a bit confused if cnd> 0 why cnd: = T [cnd] , should not reset it back to 0, as if we are starting again?
Obviously, T [0] = -1 and therefore Cnd to set t [cnd = 0] = -1 next to iterations w [cnd = -1] will be read and the string Is outside For at least this reason, you need a special treatment for cnd> 0 vs cnd == 0 . For the actual reason we compare 0 from cnd is that T [cnd] us w [] Should be given to the location where there is a partial string match on the left of w [cnd] . T [0] , however, can not be used for this purpose because there is nothing on the left side of w [0] . Why to set the CD: = T [Cnd], should not reset the CDD back to 0, as if we are starting again?
If you restart the position 0 after partial matching, you return to the nive algorithm. There is a rewind status in T [] , as you can see from the sample tables with w [] and T [] Not always right below 0. So, instead of going back to the position of 0, you sometimes go to other positions and keep on matching with it. And this is what makes the algorithm more scalable.
Comments
Post a Comment