Lecture 2
Lecture 2
Automata Theory
Lecture # 2
Languages
Alphabet and Strings
Alphabet: An alphabet is a finite set of symbols,
usually letters, digits, and punctuations.
Valid/In-valid alphabets: An alphabet may contain
letters consisting of group of symbols for example
Σ= {a, ba, bab, d}.
Remarks: While defining an alphabet of letters
consisting of more than one symbols, no letter
should be started with the letter of the same
alphabet i.e. one letter should not be the prefix of
another. However, a letter may be ended in a
letter of same alphabet.
a, ba: , c
Valid alphabet
a, ab:, c
Invalid alphabet
2
Alphabets and Strings
String or word: A finite sequence of
letters/alphabets
Examples: “cat”, “dog”, “house”, “read”
…
Defined over an alphabet:
a, b, c, , z
Three aspects/specifications
Lexical
Defines valid words/units of a language
Syntactic
Defines rules for combining the units to
form valid sentences (computer
programs in context of machines)
Semantic
Concerned with the interpretation or
meaning of a sentence (what output
to produce in context of machines)
Affected by ambiguity the most.
Formal languages
List of words
Set of all valid words of a given
language, e.g., a language
English_Words that contains all valid
words of English would have a =
{all entries of the dictionary +
punctuation marks and blank space}
Denoted by
Strings: A string a finite sequence of symbols
chosen from alphabet. For example
0111100 , 123045, abbbcdeg etc.
String Variable: A letter used for
denoting a string. The author uses w, x, y
and z as string variable. For example
w = 0111100 , x = 123045, z =
abbbcdeg
Length of String: The number of
positions for symbols in the string. For
simplicity we can say that it is the
number of symbols in the string. For
example
|w| = 7 , |x| = ? , |z| = ?
Alphabets and Strings
We will use small letters for alphabets:
a, b
Strings
a
ab
abba
baba
aaabbbaabab
12
String Operations
Let we have following strings
w a1a2 an abba
v b1b2 bm bbbaaa
Concatenation
wv a1a2 anb1b2 bm abbabbbaaa
Reverse
R
w an a2 a1 abba
aaabbb
13
String Length
w a1a2 an
Length: w n
Examples: abba 4
aa 2
a 1
14
Length of Concatenation
uv u v
Example: u aab, u 3
v abaab, v 5
uv aababaab 8
uv u v 3 5 8
15
Empty String
A string with no letters: or or
Observations: 0
w w w
abba abba abba
Note-1: A language that does not
contain any word at all is denoted
by or { }. This language doesn’t
contain any word not even the
NULL string. i.e. { } ≠ {}
16
Empty String
Note-2: Suppose a language L
doesn’t contain NULL then
L=L+
but L ≠ L + {}.
17
Substring
Substring of string:
a subsequence of consecutive
characters
String Substring
abbab ab
abbab abba
abbab b
abbab bbab
18
Prefix and Suffix
Let the string isabbab
Prefixes Suffixes
abbab w uv
a bbab
prefix
ab bab
suffix
abb ab
abba b
abbab
19
Repeat Operation
n
w - w repeated n time; that is,
2
Example:abba abbaabba
0
w
0
Definition: abba
20
The * Operation
: the set of all possible strings from
* alphabet , called closure of alphabets also
known as Kleene star operator or Kleene star closure.
a, b
i.e. infinitely many words each of finite length.
* , a, b, aa, ab, ba, bb, aaa, aab,
21
The + Operation
: the set of all possible strings from
alphabet except , also known as Kleene plus operator.
a, b
*
Note :
, a , b , aa , ab , ba ,
are infinite
bb, aaa , aab,
*
a, b, aa, ab, ba, bb, aaa, aab,
* and
22
Languages
A language is a set of strings OR
A language is any subset of * , usually
denoted by L. It may be finite or infinite.
Example: a, b
Sets { } {}
Set size { } 0
n n
An infinite language L {a b : n 0}
ab
L abb L
aabb
aaaaabbbbb
25
Operations on Languages
The usual set operations
Special case:L
0
a, bba, aaa
0
28
More Examples
n n
L {a b : n 0}
2 n n m m
L {a b a b : n, m 0}
2
aabbaaabbb L
29
Star-Closure (Kleene *)
0 1 2
Definition: L* L L L
Example:
,
a, bb,
a, bb*
aa , abb, bba , bbbb,
aaa, aabb, abba, abbbb,
30
Positive Closure
1 2
Definition: L L L
L *
a, bb,
a, bb aa, abb, bba, bbbb,
aaa, aabb, abba, abbbb,
Note: L+ includes if and only if L includes
31