# string matching vs integer matching

How different are string matching and integer matching in terms of time complexity?

I'm asking this especially in relation to Rabin Karp algorithm. Why is it faster to compute hash code for every substring and check for equality of hashcode with the hashcode of the given string than the naive method of just checking if amy of the substrings match with the given string?

• What is integer matching? – Yuval Filmus Mar 10 '14 at 19:30
• I don't know the exact terms to be used, by integer matching I meant checking equality of two integers. – Nitin Labhishetty Mar 11 '14 at 6:05

In asymptotic complexity terms: checking equality of (fixed-precision) integers takes $O(1)$ time, checking equality of strings takes $O(n)$, where $n$ denotes the length of each string.