Set builder form for representing strings

1.1k Views Asked by At

Is there a way to represent strings or palindromes using set notation?

For representing palindrome using set notation, I arrived at this notation $$S=\{ab^{n}c:N\; |\; n \geq 1 \land n \leq 3\}$$

I want to represent a set of palindromes with length 3.Please help me out with this.

1

There are 1 best solutions below

3
On BEST ANSWER

A word $w$ has length $3$ if and only if $w=abc$ for some symbols $a,b,c$. To be a palindrome, we must also have $a=c$. We can summarize this by saying that for $w$ to be a palindrome of length 3, it must have the form $w=aba$. The set of such palindromes over some alphabet $\Sigma$ is therefore

$$\{w \mid \exists a,b \in \Sigma. w = aba \}$$

which we usually abbreviate to $$\{aba \mid a,b\in \Sigma\}.$$

Your suggestion, $\{ab^nc \mid n\ge 1\land n\le 3\}$, does not seem to represent the set of palindromes of length 3, for several reasons: if $n=3$, then $ab^nc$ has length $5$, not length $3$; if $a\ne c$ then $abc$ is not a palindrome; etc.