Basic-Python-Programs icon indicating copy to clipboard operation
Basic-Python-Programs copied to clipboard

Create Rabin_Karp.py

Open Udit19-pixel opened this issue 1 year ago • 0 comments

Created a Python file to implement the Rabin-Karp algorithm for searching a pattern in a given text.

Explanation to the algorithm : -

  • The Rabin Karp algorithm is a string search algorithm that uses hashing to find the given pattern in the text.
  • This algorithm computes the hash value of the pattern for that iteration and for each substring, compares that hash value with the subsequent pattern.
  • If the hash value matches, the algorithm performs a string comparison, otherwise that window is not entertained further.
  • The average time complexity of this algorithm is O(m+n) where n is the text length and m is the pattern length, whereas the worst case time complexity is O(mn).

Udit19-pixel avatar May 27 '24 18:05 Udit19-pixel