Lecture # 2
Theory Of Automata
Languages
There are two types of languages
Informal Languages (Semantic languages)
formal Languages (Syntactic languages)
Informal languages
In which we do not strictly follow the Grammar
Rules and we divert somehow form the strict
grammatical rules.
 All Spoken languages are informal languages;
• e.g. urdu, english, arabic, etc.
Formal Languages
In which we are not allowed to divert from the strict
and predefined grammatical rules.
We must make and consider all the possible
strings/subsets according to the predefined rules.
Can be Finite or Infinite.
Note: Language and Set are the same things.
Formal Languages
Example:
A = {1, 2, 3}
Make set of all subsets of A (Rule)
 [ {}, {1}, {2}, {3}. {1.2}, {1,3}, {2,3}, {1,2,3} ]
 Make set of all subsets containing 2 members (Rule)
[{1,2}, {1,3}, {2,3}]
Formal Languages
 C++, Jave, VB, etc (all Programming Languages)
 set of standard English-Words (Finite)
 set of all valid sentences of size 3 (infinite)
 Many other small formal languages that we will in this
subject for practice
English as a Formal Language
i.e. just follow the syntactic rules and do not care
about the meanings of the sentences, then we
how different correct (syntactically) words can
be made.
let us see..
English as a Formal Language
S + V + O (Syntactic Rule)
 I eat apples (S + V + O)
 table eat apples (S + V + O)
Tree walk on Road (S + V + O)
 etc.
Properties of Formal Languages
Alphabets
Tokenizing (Factorization)
Strings
Words
Length of a String
Reverse of a String
Alphabets
Definition:
A finite non-empty set of symbols (letters), is
called an alphabet. It is denoted by Σ ( Greek
letter sigma), also called the set of units
elements.
According to the nature of problem (formal
language ) any symbol can be part of Σ
Alphabets
Example:
Σ1={a,b}
Σ2={0,1} //important as this is the language
//which the computer understands.
Σ3={i,j,k}
Strings based upon Σ1 may be as follows;
“aaa”, “bbab” , “bbbb” , etc
Tokenizing
Process of Breaking a word/string according to
the given alphabet.
Example
 Σ={a, b} Given String ; S = “aababa”
 (a) (a) (b) (a) (b) (a)
Strings
Definition:
Concatenation of finite symbols from the
alphabet is called a string.
Example:
If Σ= {a,b} then
a, abab, aaabb, ababababababababab
NOTE:
Empty String or Null String
Sometimes a string with no symbol at all is
used, denoted by (Small Greek letter Lambda)
λ or (Capital Greek letter Lambda) Λ, is called
an empty string or null string.
The capital lambda will be used to denote the
empty string in this text.
Words
 Definition:
Words are the strings belonging to some
language/set.
Example:
If Σ= {x} then a language/set L can be
defined as
L={xn : n=1,2,3,…..} or L={x, xx, xxx,….}
Here x,xx,… are the words of L
NOTE:
All words are strings, but not all strings
are words.
Length of Strings
Definition:
The length of string s, denoted by |s|, is the
number of letters in the string.
Two Ways to determine string length.
 Tokenizing the string OR
 Counting individual symbols
Note: by which we should count the string length is
indicated in the question
Length of Strings
Example-1: (Tokenizing)
Σ={a, b}
s=“ababa”
tokens = (a)(b)(a)(b)(a)
|s|=5
Length of Strings
Example-2: (Tokenizing)
Σ= {B, aB, bab, d}
s=“BaBbabBd”
Tokenizing=(B), (aB), (bab), (B), (d)
|s|=5
Note: also the string contains 8 number of letters. See in
next example3.
Length of Strings
Example-3: (Counting individual letters)
Σ= {B, aB, bab, d}
s=“BaBbabBd”
|s|=8
Note: which method will be used it is described.
Reverse of a String
Definition:
The reverse of a string s denoted by Rev(s)
or sr, is obtained by writing the letters of s
in reverse order.
Example:
If s=abc is a string defined over Σ={a,b,c}
then Rev(s) or sr = cba
Example:
Composite symbols are not reversed further
Σ= {B, aB, bab, d}
s=BaBbabBd
Rev(s)=dBbabaBB
While defining an alphabet of letters
consisting of more than one symbols, no
letter should be started with the letter of the
same alphabet.
Valid/In-valid alphabets
i.e. one letter should not be the prefix
of another.
However, a letter may be ended in the letter
of same alphabet
i.e. one letter may be the suffix of
another.
Note: in this text we will avoid the usage of composite
alphabets.
Valid/In-valid alphabets
Valid/In-valid alphabets
Example-1
 Consider an alphabet
Σ1= {B, aB, bab, d} and a string Bababd.
 (B), (abab), (d)
 (B), a , (bab), (d)
Valid/In-valid alphabets
Example-2
Now consider another alphabet
Σ2= {B, Ba, bab, d} and a string Bababd.
 (Ba), (bab), (d)
 (B), (abab), (d)
Conclusion
Σ1= {B, aB, bab, d}
Σ2= {B, Ba, bab, d}
Σ1 is a valid alphabet while Σ2 is an in-valid
alphabet and should be avoided.
Defining Formal Languages
Simple Tools for Defining Formal languages are:
Descriptive definition (DD)
Recursive definition (RD)
Regular Expressions(RE)
Descriptive Definition
In this method the formal language is defined,
describing the conditions imposed on its words.
Descriptive Definition
Example-1:
The language L of strings of odd length,
defined over Σ={a}, can be written as
L={a, aaa, aaaaa,…..}
Descriptive Definition
Example-2:
The language L of strings that does not start
with a, defined over Σ={a,b,c}, can be written
as
L={b, c, ba, bb, bc, ca, cb, cc, …}
Descriptive Definition
Example-3:
The language L of all strings of length 2,
defined over Σ={0,1,2}, can be written as
L={00, 01, 02,10, 11,12,20,21,22}
Descriptive Definition
Example-4:
The language L of strings ending in 0,
defined over Σ ={0,1}, can be written as
L={0,00,10,000,010,100,110,…}
Descriptive Definition
Example-5:
The language EQUAL, of strings with number of
a’s equal to number of b’s, defined over
Σ={a,b}, can be written as
EQUAL = {Λ ,ab,aabb,abab,baba,abba,…}
Descriptive Definition
Example-6:
The language EVEN-EVEN, of strings with even
number of a’s and even number of b’s, defined
over Σ={a,b}, can be written as
{Λ, aa, bb, aaaa,aabb,abab, abba, baab, baba,
bbaa, bbbb,…}
Descriptive Definition
Example-7:
The language INTEGER, of strings defined over
Σ={-,0,1,2,3,4,5,6,7,8,9}, can be written as
INTEGER = {…,-2,-1,0,1,2,…}
Descriptive Definition
Example-8:
The language EVEN, of stings defined over
Σ={-,0,1,2,3,4,5,6,7,8,9}, can be written as
EVEN = { …,-4,-2,0,2,4,…}
Descriptive Definition
Example-9:
The language {an
bn
}, of strings defined over
Σ={a,b}, as
{an
bn
: n=1,2,3,…}, can be written as
{ab, aabb, aaabbb,aaaabbbb,…}
Descriptive Definition
Example-10:
The language {an
bn
an
}, of strings defined over
Σ={a,b}, as
{an
bn
an
: n=1,2,3,…}, can be written as
{aba, aabbaa, aaabbbaaa,aaaabbbbaaaa,…}
Descriptive Definition
Example-11:
The language factorial, of strings defined over
Σ={1,2,3,4,5,6,7,8,9} i.e.
{1,2,6,24,120,…}
Descriptive Definition
Example-12:
The language FACTORIAL, of strings
defined over Σ={a}, as
{an!
: n=1,2,3,…}, can be written as
{a,aa,aaaaaa,…}.
It is to be noted that the language FACTORIAL
can be defined over any single letter alphabet.
Descriptive Definition
Example-13:
The language DOUBLEFACTORIAL, of strings
defined over Σ={a, b}, as
{an!
bn!
: n=1,2,3,…}, can be written as
{ab, aabb, aaaaaabbbbbb,…}
Descriptive Definition
Example-14:
The language SQUARE, of strings defined over
Σ={a}, as
{an2
: n=1,2,3,…}, can be written as
{a, aaaa, aaaaaaaaa,…} (i.e. 12 , 32 , 42 …..)
Descriptive Definition
Example-15:
The language DOUBLESQUARE, of
strings defined over Σ={a,b}, as
{an2
bn2
: n=1,2,3,…}, can be written as
{ab, aaaabbbb, aaaaaaaaabbbbbbbbb,…}
Descriptive Definition
Example-16:
The language PRIME, of strings defined
over Σ={a}, as
{ap
: p is prime}, can be written as
{aa,aaa,aaaaa,aaaaaaa,aaaaaaaaaaa…}
Descriptive Definition
 Example-17:
PALINDROME:
The language consisting of Λ and the strings s
defined over Σ such that Rev(s)=s.
Descriptive Definition
 Example-17:
PALINDROME:
It is to be denoted that the words of
PALINDROME are called palindromes.
For Σ={a,b},
PALINDROME={Λ , a, b, aa, bb, aaa, aba, bab,
bbb, ...}
Note:
Generalized Rule on the number of strings
Number of strings of length ‘m’ defined over
alphabet of ‘n’ letters is nm.
where
n = string length and
m = number of alphabets
Note:
Generalized Rule on the number of strings
Example-1:
The language of strings of length 2, defined
over Σ={a,b} is;
L={aa, ab, ba, bb}
i.e. number of strings = 22
Note:
Generalized Rule on the number of strings
Example-2:
The language of strings of length 3, defined
over Σ={a,b} is
L={aaa, aab, aba, baa, abb, bab, bba, bbb}
i.e. number of strings = 23
End

Language