lec18-extra - Exact sub-string matching in deterministic...

Info iconThis preview shows pages 1–6. Sign up to view the full content.

View Full Document Right Arrow Icon
Exact sub-string matching in deterministic linear time O(n+m) Prof. Manolis Kellis IMPORTANT NOTE: sub-string matching does not include gaps. Sub-sequence atching which includes gaps is O(n*m) matching, which includes gaps is O(n m) For more information see Dan Guslfied book
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
The exact matching problem puts: Inputs: – a string P , called the pattern longer string called the text a longer string T , called the text • Output: – Find all occurrences, if any, of pattern P in text T ,y , p •E x a m p l e aba P= baab ac abab ad T= 123456789 1 0 1 1 1 2
Background image of page 2
Basic string definitions baab ac abab ad S= 123456789 1 0 1 1 1 2 A string S – Ordered list of characters ritten contiguously from left to write – Written contiguously from left to write •A substring S[i. .j] ll contiguous characters from i to j – all contiguous characters from i to j – Example: S[3. .7] = abaxa refix a substring starting at 1 A prefix is a substring starting at 1 suffix is a substring ending at |S| |S| denotes the number of characters in string S
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
The naïve string-matching algorithm AÏVE STRING MATCHING NAÏVE STRING MATCHING –n length[T] – m length[P] 1 for shift 0 to n do if P[1. .m] == T[shift+1 . . shift+m] en rint “Pattern occurs with shift” shift 2 3 4 O(n) O(m) Running time: then print Pattern occurs with shift shift • Where the test operation in line 4: 5 – Tests each position in turn • If match, continue testing lse: stop ese stop • Running time ~ number of comparisons number of shifts (with one comparison each) + number of successful character comparisons
Background image of page 4
Comparisons made with naïve algorithm orst case running time: Worst case running time: – Test every position =aaaa T=aaaaaaaaaaa b a a b a c a b aba s=0 baab ac ab P aaaa, T aaaaaaaaaaa • Best case running time:
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 6
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 11/11/2011 for the course MATH 180 taught by Professor Byrns during the Spring '11 term at Montgomery College.

Page1 / 21

lec18-extra - Exact sub-string matching in deterministic...

This preview shows document pages 1 - 6. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online