public static void main(String args[]){
        RabinKarpSearch rks = new RabinKarpSearch();
        System.out.println(rks.patternSearch("TusharRoy".toCharArray(), "sharRoy".toCharArray()));
        System.out.println(rks.patternSearch("TusharRoy".toCharArray(), "Roy".toCharArray()));
        System.out.println(rks.patternSearch("TusharRoy".toCharArray(), "shas".toCharArray()));
        System.out.println(rks.patternSearch("TusharRoy".toCharArray(), "usha".toCharArray()));
        System.out.println(rks.patternSearch("TusharRoy".toCharArray(), "Tus".toCharArray()));
    }
Date 09/25/2014
@author Tushar Roy

Rabin Karp algorith for substring matching.

Time complexity in worst case O(n^2)(depends on hash function)
Space complexity O(1)

References
https://en.wikipedia.org/wiki/Rabin%E2%80%93Karp_algorithm
src/com/interview/string/RabinKarpSearch.java