TOA Lecture01
TOA Lecture01
Automata
By
Introduction to languages
• There are two types of languages
– Formal Languages (Syntactic languages)
– Informal Languages (Semantic languages)
Dr. Nazir Ahmad Zafar 6
Alphabets
Definition (alphabet)
A finite non-empty set of symbols (called
letters), is called an alphabet.
It is denoted by Σ (Greek letter sigma).
Example 1
1. Σ = {a, b}
2. Σ = {0,1} (important as this is the language
which the computer understands)
3. Σ = {i, j , k} etc.
Dr. Nazir Ahmad Zafar 7
Strings
• Σ (alphabet) includes letters, digits and a
variety of operators including sequential
operators such as GOTO and IF
Definition (Strings)
• Concatenation of finite letters from the
alphabet is called a string.
Example 2
If Σ = {a,b} then
a, abab, aaabb, ababababababababab
Dr. Nazir Ahmad Zafar 8
Strings
Empty string or null string
Sometimes a string with no symbol at all is
used
It is denoted by small Greek letter Lambda λ
OR capital Greek letter Lambda Λ, called an
empty string or null string.
The capital lambda will mostly be used to
denote the empty string, in further discussion.
Note:
All words are strings, but not all strings are words.
Dr. Nazir Ahmad Zafar 10
Valid/In-valid alphabets
While defining an alphabet, It may contain letters
consisting of group of symbols
Example 4
Σ1 = {B, aB, bab, d}.
Example 5
If Σ2 = {B, Ba, bab, d} then a string BababB can
be tokenized in two ways
– (Ba), (bab), (B) is identified as a string
– (B), (abab), (B) is not identified as a string
Ambiguous alphabets
Dr. Nazir Ahmad Zafar 11
Words
• Which shows that the second group cannot be
identified as a string defined over Σ
• As when this string is scanned by the compiler
(Lexical Analyzer),
• First symbol B is identified as a letter belonging to Σ,
while for the second letter the lexical analyzer would
not be able to identify it
• Hence while defining an alphabet it should be kept in
mind that ambiguity should not be created
Mathematical Description
L = {s : S | Length(s) = 2 }
Number of strings = 23 = 8
L = (Σ x Σ) x (Σ x Σ)
= {aa, ab, ba, bb} x {aa, ab, ba, bb}
= {aaaa, aaab, aaba, aabb, abaa, abab, abba,
abbb, baaa, baab, baba, babb, bbaa, bbab,
bbba, bbbb}
Dr. Nazir Ahmad Zafar 31
Example 31: Palindromes of length 2n, 2n-1
Procedure: Palindromes of length 2n
• Compute all strings of length n
• Find reverse of every string
• Palindrome of length 2n = {sRev(s): s is string}
n=2 aa aa aaaa
bb bb bbbb
ab ba abba
ba ab baab