11010110
), we need to establish terminology for working with strings.0
and 1
).An alphabet \(\Sigma\) is any nonempty finite set of symbols (usually single-character identifiers).
\[\begin{align*}
\Sigma_1 &= \{0, 1\}
\\
\Sigma_2 &= \{\string{a, b, c, \ldots, z}\}
\\
\Gamma &= \{\string{0, 1, x, y, z}\}
\end{align*}\]
An string over alphabet \(\Sigma\) is a finite sequence of symbols from \(\Sigma\).
\[\begin{alignat*}{2}
w &= 010101 \quad &&\text{is a string over } \Sigma_1
\\
y &= \string{hello} \quad &&\text{is a string over } \Sigma_2
\\
z &= \string{x0yz} \quad &&\text{is a string over } \Gamma
\hspace{20em}
\end{alignat*}\]
We write strings without parentheses or commas, whereas normally we’d write the sequence 010101 as a tuple \((0, 1, 0, 1, 0, 1).\)
The length of a string \(w\) is denoted \(|w|\).
The string of length 0 is called the empty string and is denoted \(\emptystring\).
\(\emptystring\) is a string over any alphabet (including the empty alphabet \(\emptyset\)).
\(\emptystring\) corresponds to ""
in most programming languages.
We make no distinction between symbols and strings of length 1.
For example, \(0\) is both a symbol and a string over \(\Sigma_1\).
Object | Notation | Python Equivalent | Cardinality | Length |
---|---|---|---|---|
Empty set | \(\emptyset\) or \(\{\}\) | set() |
0 | Sets don’t have lengths. |
Empty string | \(\emptystring\) | "" |
Strings don’t have cardinalities. | 0 |
A set containing the empty string | \(\{\emptystring\}\) | {""} |
1 | Sets don’t have lengths. |
[]
or subscripts.The set of all strings over an alphabet \(\Sigma\) is denoted \(\Sigma^*\). \[ \string{\{0, 1\}^*} = \string{\{\emptystring, 0, 1, 00, 01, 10, 11, 000 \ldots\}} \] The set of all strings of length \(n\) is denoted \(\Sigma^n = \setbuild{ x \in \Sigma^* }{|x| = n}\).
Given a set of strings \(A\), we can order its elements by first comparing their lengths and then doing a “dictionary order” comparison.
A set of strings is called a language.
A set of strings is also called a decision problem!
(A yes/no question about strings, defined by
the set of strings for which the answer is “yes”.)
A set of languages is called a class.
Warning: when dealing with an ordinary set \(A\),
\(A^2\) instead denotes the Cartesian product \(A \times A\),
(all ordered pairs of elements from \(A\)).
The cardinality \(|A|\) of a language \(A\) is the number of strings in \(A\).
What is the cardinality of \(\Sigma^k\)?
The cardinality \(|A|\) of a language \(A\) is the number of strings in \(A\).
The cardinality of \(\Sigma^k\) is \(|\Sigma|^k\).
Similarly, in Python, ("1", "11") == "111"
is False
.
A DFA can be visually specified by a state diagram:
(A DFA can be seen as a special type of directed graph with labeled edges and nodes.)
Example processing the string 1101
:
1101
Begin in the start state \(q_1\).
Read 1
and transition to state \(q_2\).
1101
Read 1
and transition to state \(q_2\).
1101
Read 0
and transition to state \(q_3\).
1101
Read 1
and transition to state \(q_2\).
1101
Since the final state \(q_2\) is an accept state, the DFA accepts the string.
Which string(s) below are accepted by this DFA?