

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


Suppose we are looking for pattern “GCT”Suppose we are looking for pattern “GCT” In the text “ACTGCTGATGG”In the text “ACTGCTGATGG”
We have,We have, TextText - - ACTGCTGATGGACTGCTGATGG PatternPattern –– GCT maps to p = 423GCT maps to p = 423
We match the textWe match the text 1234234134412342341344
.. .423.. .423 Match after 3 shiftsMatch after 3 shifts
Processing Time :Processing Time : Time to compute P[ 1… m] = O( m )Time to compute P[ 1… m] = O( m )
Matching TimeMatching Time Time to compute sub string valuesTime to compute sub string values Ts = O( nTs = O( n –– m + 1)m + 1)
Total matching time = O( (nTotal matching time = O( (n--m+1) m )m+1) m ) Because each substring has m digits …Because each substring has m digits … So matching m digits each time for nSo matching m digits each time for n--m+1 substrings ..m+1 substrings ..
So, what do we have here …So, what do we have here …
Finding a good hashing functionFinding a good hashing function
could be a pain. 2 strings could hashcould be a pain. 2 strings could hash to the same value.to the same value.
So, we provide an additional check ifSo, we provide an additional check if
the hash matches. As you will see inthe hash matches. As you will see in the algorithm , the overhead is notthe algorithm , the overhead is not much.much.
But, we still need a good hashingBut, we still need a good hashing
functionfunction