0% found this document useful (0 votes)
40 views19 pages

4 Sublinear Pattern Search

The document discusses the design and implementation of a sublinear pattern search algorithm to efficiently find a keyword in a given text. It outlines an inefficient approach for searching the keyword 'SENTENCE' and explores the challenges of matching characters in the text. The applications of this algorithm include text editors, pattern matching, and keyword searching.

Uploaded by

clanguage9999
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
40 views19 pages

4 Sublinear Pattern Search

The document discusses the design and implementation of a sublinear pattern search algorithm to efficiently find a keyword in a given text. It outlines an inefficient approach for searching the keyword 'SENTENCE' and explores the challenges of matching characters in the text. The applications of this algorithm include text editors, pattern matching, and keyword searching.

Uploaded by

clanguage9999
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd

PRASAD V.

POTLURI SIDDHARTHA

INSTITUTE OF TECHNOLOGY

PROBLEM SOLVING
TECHNIQUES
By

B. Vinay Kumar
Assistant Professor
Dept. of CSE
PVPSIT, Kanuru.
Algorithm 4 PVPSIT (Autonomous)

SUBLINEAR PATTERN SEARCH


• Problem
• Design and implement an algorithm that will efficiently search a given text
for a particular keyword or pattern and record the number of times the
keyword or pattern is found.
• Algorithm development
• (inefficient approach)
• In looking for the keyword SENTENCE in the text

Problem Solving Techniques B. Vinay Kumar Friday, June 27, 2025


PVPSIT (Autonomous)

• One approach that we can take may proceed as follows.


• Test if the first character in the word matches the first character in the text
(e.g. compare S and T).
• If they do not match, compare the first character in the word with the second
character in the text (e.g. compare S and H) and so on.
• When the first character in the word matches the current character in text
(e.g. S of SENTENCE matches S of SLOW) we then compare the second
character in the word with the next character in the text (in this case E with L)
and so on.
• “is there a better way of implementing a text searching algorithm?”

Problem Solving Techniques B. Vinay Kumar Friday, June 27, 2025


PVPSIT (Autonomous)

Problem Solving Techniques B. Vinay Kumar Friday, June 27, 2025


PVPSIT (Autonomous)

• If SENTENCE were to end at character position 16 then the 16th text


character would need to be an E.
• Instead we find an R which again is not in the word SENTENCE.
• This means that the next place that the word SENTENCE could end is
at text position 24.

Problem Solving Techniques B. Vinay Kumar Friday, June 27, 2025


PVPSIT (Autonomous)

• At text position 24 we encounter a T.


• This is not an E so SENTENCE cannot end at position 24.
• The question is where is the next possible position that the word
SENTENCE could end?
• This case is the case where T is encountered in the word SENTENCE.
• It is possible that T just encountered in the text may belong to the text
as follows:
Problem Solving Techniques B. Vinay Kumar Friday, June 27, 2025
PVPSIT (Autonomous)

• To check out if the T at position 24 really does belong to the word


SENTENCE we could again look at the position where the last
character of the word would be expected (in this case character 28).
• At position 28 we encounter a K instead of an E.
• From this we can conclude that the T at position 24 did not really
belong to the word SENTENCE.

Problem Solving Techniques B. Vinay Kumar Friday, June 27, 2025


PVPSIT (Autonomous)

Problem Solving Techniques B. Vinay Kumar Friday, June 27, 2025


PVPSIT (Autonomous)

Problem Solving Techniques B. Vinay Kumar Friday, June 27, 2025


PVPSIT (Autonomous)

Problem Solving Techniques B. Vinay Kumar Friday, June 27, 2025


PVPSIT (Autonomous)

Problem Solving Techniques B. Vinay Kumar Friday, June 27, 2025


PVPSIT (Autonomous)

Problem Solving Techniques B. Vinay Kumar Friday, June 27, 2025


PVPSIT (Autonomous)

Problem Solving Techniques B. Vinay Kumar Friday, June 27, 2025


PVPSIT (Autonomous)

Problem Solving Techniques B. Vinay Kumar Friday, June 27, 2025


PVPSIT (Autonomous)

Problem Solving Techniques B. Vinay Kumar Friday, June 27, 2025


PVPSIT (Autonomous)

Problem Solving Techniques B. Vinay Kumar Friday, June 27, 2025


PVPSIT (Autonomous)

Problem Solving Techniques B. Vinay Kumar Friday, June 27, 2025


PVPSIT (Autonomous)

Problem Solving Techniques B. Vinay Kumar Friday, June 27, 2025


PVPSIT (Autonomous)

• Applications
• Text editors, pattern matching, keyword searching.

Problem Solving Techniques B. Vinay Kumar Friday, June 27, 2025

You might also like