|
1 | 1 | # Optimisation-of-Pattern-Matching
|
2 | 2 |
|
| 3 | +Visit : [Documentation](https://drive.google.com/file/d/1AzBEZd2I72Sz0WjuPOL8ixdJeXt7eOcb/view?usp=sharing) |
| 4 | + |
3 | 5 | I have chosen this theme to ensure the correctness of these algorithms and
|
4 | 6 | to learn deep mathematics behind these algorithms. I am desirous of
|
5 | 7 | learning how the text searching in text editors work, how spell errors are
|
6 | 8 | checked, etc. I will be analyzing the time and space complexities of the
|
7 | 9 | algorithms used in these practical cases and also implement them for my
|
8 | 10 | own satisfaction.
|
| 11 | + |
| 12 | + |
| 13 | +# Knuth Morris Pratt (K.M.P.) String matching Algorithm: |
| 14 | +This algorithm is the most important algorithm for solving the problem of |
| 15 | +string matching. It solves this problem in linear time and space complexity. |
| 16 | +This algorithm improves the basic naive algorithm by not just going to the |
| 17 | +next window blindly and redoing the same work. It skips a few windows |
| 18 | +selectively and chooses the next window to check for the pattern by the |
| 19 | +concept of Longest Proper Prefixes and Suffixes (L.P.S.) This involves |
| 20 | +greedy and dynamic programming, programming paradigms. This |
| 21 | +algorithm cleverly uses the properties of the longest proper prefix of a |
| 22 | +string which is also a proper suffix for choosing the next window after a |
| 23 | +deviation is detected in |
| 24 | +the current processing window. |
| 25 | + |
| 26 | +# Z Algorithm : |
| 27 | +It is used to find the pattern as a substring in a string in O(n). KMP |
| 28 | +Algorithm also does the same task at the same time complexity but Z |
| 29 | +algorithm is quite more intuitive and easy to understand. It is commonly |
| 30 | +applied in many applications like finding a phrase in a pdf or a virtual |
| 31 | +dictionary. To accomplish this task a preprocessing stage occurs where we |
| 32 | +trade space for time. We create a Z Array where Z[i] represents the longest |
| 33 | +length of a substring starting at Z[i] which is also the prefix. To accomplish |
| 34 | +this is the main aim to understand this algorithm. Rest follows quite easily |
| 35 | +as we will see in this project. This approach also follows Dynamic |
| 36 | +Programming as we are reusing the previously calculated results. |
| 37 | + |
| 38 | +# Karp-Rabin Algorithm : |
| 39 | +This algorithm is entirely different from the ones discussed. This algorithm |
| 40 | +works on the concept of role hashing, which calculates the hash of one |
| 41 | +window from the previous window in the order of constant time. Ideally or |
| 42 | +theoretically, this hash function is collision-free as it works like a new |
| 43 | +number system having 256 digits and a number can be represented only |
| 44 | +in one way in a particular number system. But practically, a few collisions |
| 45 | +may occur by applying a modulus on the hash value for preventing |
| 46 | +arithmetic and space overflows. This method uses the hash of the |
| 47 | +windows as the primary filter for detecting patterns thus reducing the need |
| 48 | +of checking every window, unlike the naive algorithm. |
0 commit comments