PROBLEM SOLVING TECHNIQUES
By
Dept. of CSE
PVPSIT, Kanuru.
PRASAD V. POTLURI SIDDHARTHA INSTITUTE OF TECHNOLOGY
B. Vinay Kumar
2025-26
TEXT PROCESSING
AND
PATTERN SEARCHING
UNIT V
PVPSIT (Autonomous)
Problem Solving Techniques
1) KEYWORD SEARCH IN TEXT
2) TEXT LINE EDITING
3) LINEAR PATTERN SEARCH
4) SUBLINEAR PATTERN SEARCH
B. Vinay Kumar
2025-26
Introduction
PVPSIT (Autonomous)
Problem Solving Techniques
THIS IS A SENTENCE OF TEXT
B. Vinay Kumar
2025-26
Algorithm 1
KEYWORD SEARCH IN TEXT
PVPSIT (Autonomous)
Problem Solving Techniques
B. Vinay Kumar
2025-26
Algorithm 1- KEYWORD SEARCH IN TEXT
PVPSIT (Autonomous)
Problem Solving Techniques
B. Vinay Kumar
2025-26
Algorithm 1- KEYWORD SEARCH IN TEXT
PVPSIT (Autonomous)
Problem Solving Techniques
B. Vinay Kumar
2025-26
Algorithm 1- KEYWORD SEARCH IN TEXT
PVPSIT (Autonomous)
Problem Solving Techniques
This algorithm is essentially a String Searching process. It acts like a magnifying glass moving across a sentence, checking if the letters underneath match your target word one by one.
Let’s visualize this using the word "INK" as our target pattern within the text "PINK INK."
Visualizing the Execution
Imagine your target word INK has a pointer i that tracks which letter you are currently looking for.
Scenario 1: The "Partial Match" (The word "PINK")
Algorithm 1- KEYWORD SEARCH IN TEXT
PVPSIT (Autonomous)
Problem Solving Techniques
Scenario 2: The "Total Match" (The word "INK")
Algorithm 1- KEYWORD SEARCH IN TEXT
PVPSIT (Autonomous)
Problem Solving Techniques
B. Vinay Kumar
2025-26
Algorithm 1- KEYWORD SEARCH IN TEXT
PVPSIT (Autonomous)
Problem Solving Techniques
B. Vinay Kumar
2025-26
Algorithm 1- KEYWORD SEARCH IN TEXT
PVPSIT (Autonomous)
Problem Solving Techniques
2025-26
Match corresponds to a full word (word boundaries) rather than a substring
Application
This technique is part of a "Problem Solving Approach in Computing" that involves establishing a search word, maintaining a match count, and managing pointers for a word array to navigate through text, particularly when checking for words that are preceded and followed by non-alphabetic characters.
PVPSIT (Autonomous)
Problem Solving Techniques
B. Vinay Kumar
2025-26
Steps Upon Mismatch
When a mismatch occurs, the following steps must be taken to reset the search:
Initializations
To handle edge cases (such as the first word):
Steps Upon Word-Match
When a full word-match is established, the process is similar to a mismatch, with added tracking:
PVPSIT (Autonomous)
Problem Solving Techniques
j :=1 //search word pointer
while (j <=n and i <= m-n+1) do
if (T[i] = w[j]) then
i := i+1
j := j+1
else
i := i+1
j := 1
if (j>n and T[i] = non-alphabet and T[i-j] = non-alphabet) then
wc:= wc+1
i := i+1
B. Vinay Kumar
2025-26
Pseudocode
PVPSIT (Autonomous)
Problem Solving Techniques
Step 2.1: Initialize word index j :=1
Step 2.2: Repeat Step 2.2.1 till ((j <=n) and (i <= (m-n+1)))
Step 2.2.1: if (T[i] = w[j]) then
i := i+1
j := j+1
else
i := i+1
j := 1
Step 2.3: if (j>m and T[i] = non-alphabet and T[i-j] = non-alphabet) then
wc:= wc+1; i := i+1
B. Vinay Kumar
2025-26
Algorithm
PVPSIT (Autonomous)
Problem Solving Techniques
B. Vinay Kumar
2025-26
PVPSIT (Autonomous)
Problem Solving Techniques
B. Vinay Kumar
2025-26
PVPSIT (Autonomous)
Problem Solving Techniques
(a) While not end-of-line do
(a.1) Read next character;
(a.2) If current text character chr matches ith character in word then
(2.a) Extend partial match i by 1,
B. Vinay Kumar
2025-26
Supplementary problems
PVPSIT (Autonomous)
Problem Solving Techniques
(2.b) If a word-pattern match then
(b.1) Read next character post
(b.2) If preceding and following character not alphabetic then
(2.a) Update match count nmatches
(2.b) break
else
(2’.a) Save current text character as preceding character for match,
(2’.b) Reset word array pointer I to first position;
(b) read past end-of-line
B. Vinay Kumar
2025-26
PVPSIT (Autonomous)
Problem Solving Techniques
while (T[i] != EOF) do
While (j<=n) do
if T[i] == w[j] then
i:= i+1
j:= j+1
else
j:=1 //search word pointer
i:=i+1 // text pointer
while (T[i]!= non-alphabet) do
i:= i+1
i:= i+1
j:=j-1
if j==n && T[i] == non-alphabet then
wc:= wc+1
break
B. Vinay Kumar
2025-26
PVPSIT (Autonomous)
Problem Solving Techniques