The shiftAnd() algorithm performs four bitwise operations in each iteration of the last for loop. The number can be reduced to three if the roles of bits are reversed, as it is done originally by Baeza-Yates and Gonnet (1992); for example, in charactersInP, 0 represents the positions at which a character occurs in the pattern. With this bit role reversal, the assignment
state = ((state << 1) | 1)&charactersInP[T[i]];
can be changed to
state = (state << 1) | charactersInP[T[i]];Write an algorithm shiftOr() by making all the necessary changes in shiftAnd() including the indicated modifications.
We need at least 10 more requests to produce the solution.
0 / 10 have requested this problem solution
The more requests, the faster the answer.