ArticleslgStudy

computer science

Empty string

Empty string is a computer science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Empty string rather than just read about it. In short: In formal language theory, the empty string, also known as the empty word or null string, is the unique string of length zero. Formal theory Formally, a string is a finite, ordered sequence of characters such as letters, digits or spaces.

Key takeaways

  • Empty string belongs to computer science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Empty string to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Empty string from memory before moving on to harder problems.

Reference excerpt

In formal language theory, the empty string, also known as the empty word or null string, is the unique string of length zero.

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".

Use in programming languages In most programming languages, the term "string" often refers to instances of a data type and thus they're a concept distinct from the one in the formal theory. Such strings are typically stored at distinct memory addresses (locations) and thus have an identity. Thus, representatives of the same formal string (e.g., the empty string) may be stored in two or more places in memory and they can be taken as names of the formal empty string. In this way, there could be multiple representatives of the empty string in memory, in contrast with the formal theory definition, for which there is only one possible empty string. However, a "string comparison function" would indicate that all of these representatives are equal to each other. Even a string of length zero can require memory to store it, depending on the format being used. In most programming languages, the empty string is distinct from a null reference (or null pointer) because a null reference points to no string at all, not even the empty string. The empty string is a legitimate string, upon which most string operations should work. Some languages treat some or all of the following in similar ways: empty strings, null references, the integer 0, the floating point number 0, the Boolean value false, the ASCII character NUL, or other such values. The empty string is usually represented similarly to other strings. In implementations with string terminating character (null-terminated strings or plain text lines), the empty string is indicated by the immediate use of this terminating character. Different functions, methods, macros, or idioms exist for checking if a string is empty in different languages.

Representations of the empty string

The empty string is a syntactically valid representation of zero in positional notation (in any base), which does not contain leading zeros. Since the empty string does not have a standard visual representation outside of formal language theory, the number zero is traditionally represented by a single decimal digit 0 instead. Zero-filled memory area, interpreted as a null-terminated string, is an empty string. Empty lines of text show the empty string. This can occur from two consecutive EOLs, as often occur in text files. This is sometimes used in text processing to separate paragraphs, e.g. in MediaWiki.

See also Empty set Null-terminated string Concatenation theory String literal

References

Worked examples

Example 1 — a first encounter with Empty string

Start with the simplest possible case. Write down what Empty string claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In computer science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Empty string before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Empty string ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Empty string

In research
Empty string appears in computer science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Empty string in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Empty string is common in secondary-school and first-year university syllabi. It links to neighbouring topics Formal languages, String (computer science), Zero (linguistics), so understanding it makes those chapters shorter.
In everyday life
Look for Empty string outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Empty string” →

How to study Empty string in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Empty string means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Empty string out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Empty string in simple terms?

In formal language theory, the empty string, also known as the empty word or null string, is the unique string of length zero. Formal theory Formally, a string is a finite, ordered sequence of characters such as letters, digits or spaces.

Why does Empty string matter?

Because it connects several computer science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Empty string?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Empty string.

Tags

  • Formal languages
  • String (computer science)
  • Zero (linguistics)

Keep exploring