heyimShivam / Algorithm

C++ algorithm in one place, This is dedicated repository for maintaining data structures and algorithm code. This repository will be helpful for students preparing for internships or campus placements. Topics
10 stars 70 forks source link

Rabin Karp Algorithm #169

Closed Shaina-08 closed 1 year ago

Shaina-08 commented 1 year ago

Initially calculate the hash value of the pattern. Start iterating from the starting of the string: Calculate the hash value of the current substring having length m. If the hash value of the current substring and the pattern are same check if the substring is same as the pattern. If they are same, store the starting index as a valid answer. Otherwise, continue for the next substrings. Return the starting indices as the required answer.