0% found this document useful (0 votes)
15 views12 pages

DS Chapter 2

The document provides an overview of string processing, including definitions, operations, and algorithms for manipulating strings. It covers various string operations such as substring, indexing, concatenation, and length, as well as word processing techniques like insertion, deletion, and replacement. Additionally, it includes algorithms for deleting and replacing patterns in text, along with explanations of different structures for storing strings.
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)
15 views12 pages

DS Chapter 2

The document provides an overview of string processing, including definitions, operations, and algorithms for manipulating strings. It covers various string operations such as substring, indexing, concatenation, and length, as well as word processing techniques like insertion, deletion, and replacement. Additionally, it includes algorithms for deleting and replacing patterns in text, along with explanations of different structures for storing strings.
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
You are on page 1/ 12

Chapter-2

String Processing

Aifa Faruque
Lecturer,CSE,NMDC
 What is String?
Strings are considered a data type in general and are typically represented as
arrays of bytes (or words) that store a sequence of characters. Strings are
defined as an array of characters.
 Different Type of strings operation

 SUBSTRING(string,position,length)

 INDEXING(text,pattern)

 CONCATENATION

 LENGTH(string)
 Different Word Processing

 Insertion:INSERT(text,position,string)

 Deletion: DELETE(text,position,length)

 Replacement: REPLACE(text,pattern1,pattern2)
 Different Type of Structure for stored strings

1.Fixed Length Structure

2.Variable length with fixed maximum

3.Linked Structure
 Write an algorithm that deletes every occurrences of a pattern ‘P’ in a text
‘T’.
Algorithm ( Delete)
A text T and pattern P are in memory. This algorithm deletes every occurrence of P in T.
1. K:= INDEX( T,P).
2. While ( k ≠ 0)
(a) [Delete P from T]
T=DELETE ( T, INDEX(T,P), LENGTH (P) )
(b) [Update index]
K= INDEX (T,P)
[End of Loop]
3. Write: T.

Exit.
 Write an algorithm that replace every occurrence of P
in T by Q.
Algorithm ( REPLACE)
A text T and pattern P are in memory. This algorithm replace every
occurrence of P in T by Q.
1. K:= INDEX( T,P).
2. While ( k ≠ 0)
(a) T=REPLACE ( T, P,Q )
(b) K= INDEX (T,P)
[End of Loop]
3. Write: T.

Exit.
 Pattern searching

Pattern searching is an algorithm that involves searching for patterns such


as strings, words, images, etc.
1. First or Slow Pattern Matching
2. Second or Fast Pattern Matching
1. What is string and substring
2. Describe the following string operation with example
3. Explain different word processing operations.
4. Find the result of following operations:
SUBSTRING(‘TO BE OR NOT TO BE’,4,7)
INDEX(T, ‘THE’),
LENGTH(‘COMPUTER’)=8
INSERT(‘ABCDEFG’, 3, ‘XYZ’)=’ABXYZCDEFG’
DELETE(‘ABCDEFG’, 4,2)=’ABCFG’
REPLACE(‘XABYABZ’, ‘AB’, ‘C’)=’XCYABZ’
5. Find the result of following operations:
Let S=” HIS FATHER IS THE PROFESSOR’”
SUBSTRING(S,11,5)
INDEX(S, ‘ESS’),
INSERT(‘ABAABB’, 3, ‘BC’)
DELETE(S, 14,4)
REPLACE(S, ‘IS’, ‘ER’)
6.Find the result of following operations:
a. SUBSTRING(‘AnannyaGalib’,5,7)
b. INDEX(‘AlifAny’.’lifa’)
c. INSERT(‘RifatJoarder’,6,’Mysha’)
d. REPLACE(‘NityKajol’,’tyk’,’ly’)
e. LENGTH(‘Rasel Raha’)
7. A text T and a pattern P are in memory. Write an algorithm to deletes every occurrence of P in T
8. A text T and a pattern P and Q are in memory. Write an algorithm to replace every occurrence of P in T by Q
9. Explain different types of structures for storing strings./Briefly Explain fixed length,variable length, and linked
storage .
10.Write down FAST or second pattern matching algorithm.
11. Write down First pattern matching algorithm.
12. Find the table and corresponding graph for the pattern P=aaabb using second pattern matching algorithm
13. Given T=(ab)5 and P=abc .Find the number of comparison using First Pattern matching algorithm

You might also like