Mathwords logoMathwords

Concatenation — Definition, Formula & Examples

Concatenation is the operation of joining two sequences, strings, or lists end-to-end to form a single longer sequence. For example, concatenating "AB" and "CD" produces "ABCD".

Given two finite sequences a=(a1,a2,,am)a = (a_1, a_2, \dots, a_m) and b=(b1,b2,,bn)b = (b_1, b_2, \dots, b_n) over some alphabet or set, the concatenation aba \cdot b is the sequence (a1,a2,,am,b1,b2,,bn)(a_1, a_2, \dots, a_m, b_1, b_2, \dots, b_n) of length m+nm + n.

Key Formula

ab=(a1,a2,,am,b1,b2,,bn)a \cdot b = (a_1, a_2, \dots, a_m, b_1, b_2, \dots, b_n)
Where:
  • aa = First sequence of length m
  • bb = Second sequence of length n
  • aba \cdot b = Resulting sequence of length m + n

How It Works

To concatenate, place the second sequence directly after the last element of the first sequence. The order matters: concatenating AA then BB usually gives a different result than concatenating BB then AA. In formal language theory, concatenation is often written with a dot (\cdot) or simply by placing symbols side by side. In programming, common operators include ++ (Python) or \| (SQL). The operation is associative, meaning (AB)C=A(BC)(A \cdot B) \cdot C = A \cdot (B \cdot C), but it is generally not commutative.

Worked Example

Problem: Let set A = {0, 1} and consider strings x = "01" and y = "110". Find the concatenation x · y and state its length.
Step 1: Write string x followed immediately by string y.
xy="01""110"="01110"x \cdot y = \text{"01"} \cdot \text{"110"} = \text{"01110"}
Step 2: The length of x is 2 and the length of y is 3, so the length of the result is their sum.
xy=2+3=5|x \cdot y| = 2 + 3 = 5
Answer: The concatenation x · y = "01110", which has length 5.

Why It Matters

Concatenation is fundamental in formal language theory and automata, where you build complex strings from simpler ones to define grammars and regular expressions. In graph theory and discrete math, concatenation appears when combining paths or encoding structures as strings. It is also one of the most common operations in programming and data processing.

Common Mistakes

Mistake: Assuming concatenation is commutative (that A · B equals B · A).
Correction: Order matters. "AB" · "CD" = "ABCD", but "CD" · "AB" = "CDAB". These are different unless both strings happen to be identical or empty.