Lably
Skip to content

Empty string

Unique string of length zero

  • 3 min read
  • 2 chapters

Related on Lably

Through String (computer science), Palindrome and Context-free grammar

Formal theory

Formally, a string is a finite, ordered sequence of characters such as letters, digits or spaces. The empty string is the special case where the sequence has length zero, so there are no symbols in the string. There is only one empty string, because two strings are only different if they have different lengths or a different sequence of symbols. In formal treatments, the empty string is denoted with ε or sometimes Λ or λ.

The empty string should not be confused with the empty language ∅, which is a formal language (i.e. a set of strings) that contains no strings, not even the empty string.

The empty string has several properties:

  • |ε| = 0. Its string length is zero.
  • ε ⋅ s = s ⋅ ε = s. The empty string is the identity element of the concatenation operation. The set of all strings forms a free monoid with respect to ⋅ and ε.
  • εR = ε. Reversal of the empty string produces the empty string, so the empty string is a palindrome.
  • ∀c∈s:P(c). Statements that are about all characters in a string are vacuously true.
  • The empty string precedes any other string under lexicographical order, because it is the shortest of all strings.

In context-free grammars, a production rule that allows a symbol to produce the empty string is known as an ε-production, and the symbol is said to be "nullable".

Sign in to keep reading

One more chapter is free with a Lably account.

More in Computing and communication