Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Pattern matching decides whether there is an occurrences of a pattern P (implemented as an array of characters over a given alphabet) in a text

Pattern matching decides whether there is an occurrences of a pattern P (implemented as an array of characters over a given alphabet) in a text (or string) T, also implemented as an array of characters over the same alphabet. The nave pattern-matching algorithm consecutively compares the pattern with a given location in the text, checking all characters from the left to the right. In pseudo-code, the algorithm runs like this:

function patternmatch ( character text[1 ... n]

, character pattern[1 ... m])

{

for ( integer i = 0; i < m n; i++ ) {

integer j = 1;

while (j < m and pattern[j+1] == text[i+j+1] )

{

j = j+1;

}

if( j == m) return true;

}

return false; //at end of text, no occurrence found

}

Assume that the length m of the pattern is much smaller than the length n of the text.

Prove that the algorithm patternmatch has a best run time of O(n), provided that the pattern is not in the text. (Otherwise, finding the pattern a in the text abcdefg takes O(1) operations.) (4 pts)

Prove that this algorithm has worst run time of O(n2). Hint: You can use strings of type aaaab. (6 pts)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data Access Patterns Database Interactions In Object Oriented Applications

Authors: Clifton Nock

1st Edition

0321555627, 978-0321555625

More Books

Students also viewed these Databases questions

Question

How do Dimensional Database Models differ from Relational Models?

Answered: 1 week ago

Question

What type of processing do Relational Databases support?

Answered: 1 week ago

Question

Describe several aggregation operators.

Answered: 1 week ago