You are on page 1of 9

# Theory of Computation (With Automata Theory)

## Strings and Languages

Strings

Definition of Alphabet

An alphabet is defined to be a
non-empty finite set whose
members are called the
symbols of the alphabet.
The symbols can be letters,
numbers, special characters,
musical notes, emoticons, etc.
Examples:

1 = {0, 1}
2 = {a, b, c, d, e, f, g, h, i, j, k,
l, m, n, o, p, q, r, s, t, u,
v, w, x, y, z}

3 = {, , , }
Strings and Languages

* Property of STI
Page 1 of 9

## Theory of Computation (With Automata Theory)

Strings
A string over an alphabet is a
finite sequence of 0 or more
symbols from that alphabet
juxtaposed or placed side by
side (not separated by commas).
Examples:
For the binary alphabet 1,
000, 101010, 11, and 11010
are strings that can be formed
over 1.
For the alphabet 2, abba, xyz,
sti, and abracadabra are
strings that can be formed
over 2.
A string may contain no symbols
at all, and is called the empty
string, designated as .

## Strings and Languages

* Property of STI
Page 2 of 9

## Let w be a string over an

alphabet . The length of string
w is the number of symbols
contained in the string.
The length of a string w is
written as w.

For example:
If w = 010101 is a string over
the alphabet = {0, 1}, then
w= 6

0.

## Strings and Languages

* Property of STI
Page 3 of 9

## A string w over alphabet

whose length is k can be written
as
w = w1w2 wk
where w1, w2, , and wk are
elements of the alphabet .
The reverse of a string w,
designated as wR, can be
defined as the string written in
the reverse order. Specifically,
if
w = w1w2 wk
then its reverse is
wR = wk w2w1
For example:
w = abcdef
wR = fedcba
Strings and Languages

* Property of STI
Page 4 of 9

## A string z is a substring of the

string w if z appears
consecutively within w.

For example:

## If string z = def and string

w = abcdefgh, then it can
be said that z is a substring
of w.

## Like in sets, a string may be a

substring to itself.
Similarly, the empty string is a
substring of any string.

## Strings and Languages

* Property of STI
Page 5 of 9

## A prefix of a string is a substring

that is composed of any number
of leading symbols of that string.
For example:
If w = 11100101, then
some of the possible
prefixes of w are , 1, 11,
111, 1110, and 11100.
A suffix of a string is a substring
that is composed of any number
of trailing symbols of that string.
For example:
If w = 11100101, then
some of the possible
prefixes of w are , 1, 01,
101, 0101, and 00101.
Strings and Languages

* Property of STI
Page 6 of 9

## A fundamental operation that

can be performed on strings is
concatenation.
Given string x of length m and
string y of length n, the
concatenation of x and y, written
as xy, is the string obtained by
writing the string x followed by
the string y with no
intervening space between
them, as in
xy = x1xmy1yn.
For example:
If string x = sti and
string y = hq, then the
concatenation of x and y is
xy = stihq
Strings and Languages

* Property of STI
Page 7 of 9

## Strings can be arranged in

lexicographic order.
The lexicographic ordering of
strings is the same as
alphabetical ordering except that
shorter strings precede longer
strings.
For example:
Given the following strings:
000, 01, 010, 011, 0, ,
1101, 0110, and 1111.
Arranging them in
lexicographic order would
yield:
, 0, 01, 000, 010, 011,
0110, 1101, 1111
The lexicographic ordering of
strings depends of course on
how the individual ordering of
the elements of the alphabet is
defined.
Strings and Languages

* Property of STI
Page 8 of 9

## Theory of Computation (With Automata Theory)

Languages

Definition of Language
A language is a set of strings
over a given alphabet.

For example:
Given the alphabet = {0, 1}.
If the language L1 is defined as
the set of all 3-bit binary
numbers, then:

## L1 = {000, 001, 010, 011,

100, 101, 110, 111}
Given the alphabet = {0, 1}.
If the language L2 is defined as
the set of all palindromes,
then:
L2 = {, 0, 1, 00, 11, 010,
101, 110011, }

## Strings and Languages

* Property of STI
Page 9 of 9