Ma · Mathematics

How Do You Recursively Define a Set of Strings?

Published By the 9to5Science editorial team

At a glance

  1. 1. Specify the alphabet

    State which symbols may appear in the strings, such as a and b.

  2. 2. Give the base case

    Name the initial string or strings, often including the empty string.

  3. 3. State construction rules

    Explain how to create new strings from strings already in the set.

  4. 4. Require minimality

    Include only strings obtainable by finitely many applications of the rules.

A set of strings cannot be determined from the phrase “recursively defined” alone: you also need its alphabet, starting strings, and construction rules. A recursive definition gives those ingredients so you can generate the set step by step and rule out strings that the rules cannot produce.

The parts of a recursive definition

A recursive definition of a set of strings typically has four parts:

  1. Alphabet: the symbols allowed in the strings, such as {a,b}\{a,b\}.
  2. Basis: one or more strings that belong to the set initially. The empty string, written ε\varepsilon, is a common base case.
  3. Recursive rule: a rule that says how to form new strings from strings already in the set.
  4. Minimality clause: the set contains only the strings obtained from the basis by applying the rules finitely many times.

The last condition matters. Without it, the stated basis and rules merely imply that some strings belong; they do not prevent unrelated strings from being included too.

Worked example: strings with equally many a’s and b’s in order

Consider the set SS defined over the alphabet {a,b}\{a,b\} by:

  • Basis: ε∈S\varepsilon\in S.
  • Rule: If w∈Sw\in S, then awb∈Sawb\in S.
  • Minimality: Nothing belongs to SS unless it can be obtained from ε\varepsilon by finitely many uses of the rule.

Here, awbawb means put an aa at the beginning of ww and a bb at the end. Apply the rule repeatedly:

ε∈S,aεb=ab∈S,a(ab)b=aabb∈S,a(aabb)b=aaabbb∈S.\begin{aligned} \varepsilon &\in S,\\ a\varepsilon b=ab &\in S,\\ a(ab)b=aabb &\in S,\\ a(aabb)b=aaabbb &\in S. \end{aligned}

Thus the first few members are ε\varepsilon, abab, aabbaabb, aaabbbaaabbb, and so on. In set-builder notation, this is

S={anbn:n is an integer and n≥0}.S=\{a^n b^n:n\text{ is an integer and }n\ge 0\}.

The exponent n=0n=0 gives the empty string. Each application of the rule increases the number of aa’s and bb’s by one, so every generated string has all its aa’s before its bb’s and has equal counts of the two symbols. Conversely, any string anbna^n b^n can be generated by applying the rule nn times. The minimality clause means strings such as baba or aabaab are not included.

How to test a proposed string

To decide whether a string belongs to a recursively defined set, work backward from the recursive rule or build it forward from a basis string.

For the example above, a nonempty member must begin with aa and end with bb. Remove those two symbols. If the remaining string is empty or can itself be reduced in the same way, the original string is in SS. For example, removing the outer aa and bb from aabbaabb leaves abab, and removing them again leaves ε\varepsilon. Therefore aabb∈Saabb\in S. But abab∉Sabab\notin S: after removing the first and last symbols, the remainder is baba, which cannot be generated.

Recursive definitions and induction

Recursive definitions naturally support proofs by structural induction. To prove a property holds for every string in the recursively defined set:

  • Check the property for each basis string.
  • Show that every recursive rule preserves the property.

For SS, for example, prove that every string has the same number of aa’s and bb’s. The basis string ε\varepsilon has zero of each. If ww has equally many of each, then awbawb adds one of each, so it still has equal counts. By induction, every string in SS has equal numbers of the two symbols.

Common mistakes

  • Leaving out the alphabet: state the permitted symbols, even if the rules seem to make it obvious.
  • Forgetting the minimality clause: otherwise the definition may not specify exactly which strings are included.
  • Treating a rule as reversible: “If w∈Sw\in S, then awb∈Sawb\in S” allows you to build awbawb from ww; it does not automatically say that every string beginning with aa and ending with bb belongs to SS.
  • Confusing strings with sets: order matters in a string, so abab and baba are different strings.

To define a particular set, write down its base strings and every allowed construction rule. Those details determine the set; the general phrase “recursive definition of a set of strings” does not specify one by itself.

References

  1. Discrete Mathematics and Its Applications — Kenneth H. Rosen
  2. Introduction to the Theory of Computation — Michael Sipser

Spotted an error? Send a correction. Read how we write and check articles in our editorial policy.