Explain the concept of strings in TOC?

Data Structure AlgorithmsComputer ScienceComputers

A string over an alphabet is a finite sequence of letters from the alphabet.

Examples

  • toc, money, c, and adedwxq are strings over the alphabet ∑ = {a, b, c, . . . , z}.

  • 84029 is a string over the alphabet ∑ = {0, 1, 2, . . . , 9}.

Empty String

The empty string or null string, denoted by ∧, is the string consisting of no letters, no matter what type of language we are considering.

String concatenation

Given two strings w1 and w2, we define the concatenation of w1 and w2 to be the string as w1w2.

Examples

  • If w1 = pq and w2 = r, then w1w2 = pqr.

  • If w1 = acc and w2 = ac, then w1w2 = accac and w2w1 = acacc.

  • If w1 = ∧ and w2 = cd, then w1w2 = cd.

  • If w1 = aa and w2 = ∧, then w1w2 = aa.

  • If w1 = ∧ and w2 = ∧, then w1w2 = ∧; because ∧∧ = ∧.

For any string w, we can define wn for n ≥ 0 inductively as follows −

w0 = ∧;

wn+1 = wnw for any n ≥ 0.

Example

If w = man, then w

0 = ∧, w

1 =mam, w

2 = mammam, w

3 = mammammam,

and so on.

Substring

Given a string s, substring of s is any part of the string s means w is a substring of s, if there exist strings x and y (either or both possibly null) such that s = xwy.

Examples

Take the string 472828. Then ∧, 282, 4, and 472828 are all substrings of 472828.

48 is not a substring of 472828.

raja
Published on 16-Jun-2021 12:55:12
Advertisements