Z algorithm (Linear time pattern searching Algorithm)
This algorithm finds all occurrences of a pattern in a text in linear time. Let length of text be n and of pattern be m, then total time taken is O(m + n) with linear space complexity.

The algorithm runs in linear time because we never compare character less than R and with matching we increase R by one so there are at most T comparisons. In mismatch case, mismatch happen only once for each i (because of which R stops), that’s another at most T comparison making overall linear complexity.
Install
npm install z-algorithm --save or yarn install z-algorithm
Running the tests
you need to install jest
npm test or yarn test
Usage
; let result = z;
Examples
; let result = z; // result = [0] let result = z; // result = [1,2] let result = z; // result = [3,7]
Author
kerim selmi karimation
License
This project is licensed under the MIT License