SlideShare a Scribd company logo
1 of 33
Chapter One
Alphabets , Strings, Languages and
Grammars
Prepared By Haftom B.1
Prepared By Haftom B.2
Alphabets and Strings
A common way to talk about words, number, pairs of
words, etc. is by representing them as strings
To define strings, we start with an alphabet
Examples
An alphabet is a finite set of symbols.
S1 = {a, b, c, d, …, z}: the set of letters in English
S2 = {0, 1, …, 9}: the set of (base 10) digits
S3 = {a, b, …, z, #}: the set of letters plus the
special symbol #
S4 = {(, )}: the set of open and closed brackets
Prepared By Haftom B.3
Strings
The empty string will be denoted by E
Examples
A string over alphabet S is a finite sequence of symbols in S.
abfbz is a string over S1 = {a, b, c, d, …, z}
9021 is a string over S2 = {0, 1, …, 9}
ab#bc is a string over S3 = {a, b, …, z, #}
))()(() is a string over S4 = {(, )}
Prepared By Haftom B.4
Cont.…
We will use small alphabets:
Strings
5
abbaw
bbbaaav
abu



 ba,
baaabbbaaba
baba
abba
ab
a
Prepared By Haftom B.
String Operations
6
m
n
bbbv
aaaw


21
21


bbbaaa
abba
mn bbbaaawv  2121
1. Concatenation
abbabbbaaa
Prepared By Haftom B.
7
12aaaw n
R

naaaw 21 ababaaabbb
2. Reverse
bbbaaababa
Prepared By Haftom B.
3. String Length
Length:
Examples:
8
naaaw 21
nw 
1
2
4



a
aa
abba
Prepared By Haftom B.
Recursive Definition of Length
For any letter:
For any string :
Example:
9
1a
1 wwawa
4
1111
111
11
1





a
ab
abbabba
Prepared By Haftom B.
4. Length of Concatenation
 Example:
10
vuuv 
853
8
5,
3,




vuuv
aababaabuv
vabaabv
uaabu
Prepared By Haftom B.
Proof of Concatenation Length
• Claim:
• Proof: By induction on the length
• Induction basis:
• From definition of length:
11
vuuv 
v
1v
vuuuv  1
Prepared By Haftom B.
Empty String
 A string with no letters:
 Observations:
12

abbaabbaabba
www





 0
Prepared By Haftom B.
Substring
Substring of string:
a subsequence of consecutive characters
String Substring
13
bbab
b
abba
ab
abbab
abbab
abbab
abbab
Prepared By Haftom B.
Prefix and Suffix
 Given string
 Prefixes Suffixes
14
abbab
abbab
abba
abb
ab
a


b
ab
bab
bbab
abbab uvw 
prefix
suffix
Prepared By Haftom B.
Another Operation
• Example:
• Definition:
•
15
 
n
n
wwww 
  abbaabbaabba 2
0
w
  0
abba
Prepared By Haftom B.
The * Operation
• : the set of all possible strings from alphabet
16
* 
 
 ,,,,,,,,,*
,
aabaaabbbaabaaba
ba


Prepared By Haftom B.
17
The + Operation
: the set of all possible strings from
alphabet except



 
 ,,,,,,,,,*
,
aabaaabbbaabaaba
ba



*
 ,,,,,,,, aabaaabbbaabaaba

Prepared By Haftom B.
1.2 Languages
 Languages can be used to describe problems with
“yes/no” answers, for example:
A language is a set of strings over an alphabet.
L1 = The set of all strings over S1 that contain
the substring “fool”
L2 = The set of all strings over S2 that are divisible by 7
= {7, 14, 21, …}
L3 = The set of all strings of the form s#s where s is any
string over {a, b, …, z}
L4 = The set of all strings over S4 where every ( can be
matched with a subsequent )
Prepared By Haftom B.18
Cont.…
 A language is any subset of
 Example 1:
 Languages:
19
*
 
 ,,,,,,,,*
,
aaabbbaabaaba
ba


 
 
},,,,,{
,,
aaaaaaabaababaabba
aabaaa


Prepared By Haftom B.
Example 2
 An infinite language
 is aabbaa ?
20
}0:{  nbaL nn
aaaaabbbbb
aabb
ab

L Labb
L
Prepared By Haftom B.
21
Note that:
}{}{ 
0}{ 
1}{ 
0
Sets
Set size
Set size
String length
Prepared By Haftom B.
1.2.1 Operations on Languages
• The usual set operations
• Complement:
22
   
   
     aaaaaabbbaaaaaba
ababbbaaaaaba
aaaabbabaabbbaaaaaba
,,,,
}{,,,
},,,{,,,





LL  *
   ,,,,,,, aaabbabaabbaa 
Prepared By Haftom B.
Reverse
 Definition:
 Examples:
23
}:{ LwwL RR

   ababbaabababaaabab R
,,,, 
}0:{
}0:{


nabL
nbaL
nnR
nn
Prepared By Haftom B.
Concatenation
 Definition:
 Example:
24
 2121 ,: LyLxxyLL 
  
 baaabababaaabbaaaab
aabbaaba
,,,,,
,,,

Prepared By Haftom B.
Another Operation
Definition:
Special case:
25
 
n
n
LLLL 
       bbbbbababbaaabbabaaabaaababababa ,,,,,,,,,,,
3

 
   



0
0
,, aaabbaa
L
Prepared By Haftom B.
More Examples
26
}0:{  nbaL nn
}0,:{2
 mnbabaL mmnn
2
Laabbaaabbb
Prepared By Haftom B.
Star-Closure (Kleene *)
• Definition:
• Example:
•
27
 210
* LLLL 
 















,,,,
,,,,
,,
,
*,
abbbbabbaaabbaaa
bbbbbbaabbaa
bba
bba

Prepared By Haftom B.
Positive Closure
 Definition:
28
 

*
21
L
LLL 
 











,,,,
,,,,
,,
,
abbbbabbaaabbaaa
bbbbbbaabbaa
bba
bba
Prepared By Haftom B.
Grammar
Prepared By Haftom B.29
A grammar is a mechanism used for describing
languages. This is one of the most simple but yet
powerful mechanism.
The grammar for English tells us what are the
words in it and the rules to construct sentences.
Formal definitions of a Grammar
Prepared By Haftom B.30
A grammar G is defined as a quadruple
Example
Prepared By Haftom B.31
Consider the grammar , where N = {S}, ={a, b} and P is
the set of the following production rules .
Some terminal strings are generated by this grammar together
with their derivation is given below
Cont..
Prepared By Haftom B.32
Cont.…
Prepared By Haftom B.33
 Example: Find a grammar for the language
It is possible to find a grammar for L by modifying the previous
grammar since we need to generate an extra b at the
end of the string .
We can do this by adding a production S Bb
where the non-terminal B generates

More Related Content

What's hot

Regular expressions-Theory of computation
Regular expressions-Theory of computationRegular expressions-Theory of computation
Regular expressions-Theory of computationBipul Roy Bpl
 
Matrix chain multiplication
Matrix chain multiplicationMatrix chain multiplication
Matrix chain multiplicationRespa Peter
 
Deciability (automata presentation)
Deciability (automata presentation)Deciability (automata presentation)
Deciability (automata presentation)Sagar Kumar
 
Regular Languages
Regular LanguagesRegular Languages
Regular Languagesparmeet834
 
Sequence and Series in Discrete Structure
Sequence and Series in Discrete Structure Sequence and Series in Discrete Structure
Sequence and Series in Discrete Structure Zain Abid
 
Lecture 3,4
Lecture 3,4Lecture 3,4
Lecture 3,4shah zeb
 
Matrix chain multiplication
Matrix chain multiplicationMatrix chain multiplication
Matrix chain multiplicationKiran K
 
Huffman Coding Algorithm Presentation
Huffman Coding Algorithm PresentationHuffman Coding Algorithm Presentation
Huffman Coding Algorithm PresentationAkm Monir
 
DESIGN AND ANALYSIS OF ALGORITHMS
DESIGN AND ANALYSIS OF ALGORITHMSDESIGN AND ANALYSIS OF ALGORITHMS
DESIGN AND ANALYSIS OF ALGORITHMSGayathri Gaayu
 
9. chapter 8 np hard and np complete problems
9. chapter 8   np hard and np complete problems9. chapter 8   np hard and np complete problems
9. chapter 8 np hard and np complete problemsJyotsna Suryadevara
 
Longest common subsequence
Longest common subsequenceLongest common subsequence
Longest common subsequenceKiran K
 
Syntax Analysis in Compiler Design
Syntax Analysis in Compiler Design Syntax Analysis in Compiler Design
Syntax Analysis in Compiler Design MAHASREEM
 

What's hot (20)

Regular expressions-Theory of computation
Regular expressions-Theory of computationRegular expressions-Theory of computation
Regular expressions-Theory of computation
 
Matrix chain multiplication
Matrix chain multiplicationMatrix chain multiplication
Matrix chain multiplication
 
Chomsky Normal Form
Chomsky Normal FormChomsky Normal Form
Chomsky Normal Form
 
Deciability (automata presentation)
Deciability (automata presentation)Deciability (automata presentation)
Deciability (automata presentation)
 
Context free grammar
Context free grammar Context free grammar
Context free grammar
 
Regular Languages
Regular LanguagesRegular Languages
Regular Languages
 
Sequence and Series in Discrete Structure
Sequence and Series in Discrete Structure Sequence and Series in Discrete Structure
Sequence and Series in Discrete Structure
 
Lecture 3,4
Lecture 3,4Lecture 3,4
Lecture 3,4
 
Minimum spanning tree
Minimum spanning treeMinimum spanning tree
Minimum spanning tree
 
Regular expressions
Regular expressionsRegular expressions
Regular expressions
 
Matrix chain multiplication
Matrix chain multiplicationMatrix chain multiplication
Matrix chain multiplication
 
Huffman Coding Algorithm Presentation
Huffman Coding Algorithm PresentationHuffman Coding Algorithm Presentation
Huffman Coding Algorithm Presentation
 
Context free grammar
Context free grammarContext free grammar
Context free grammar
 
DESIGN AND ANALYSIS OF ALGORITHMS
DESIGN AND ANALYSIS OF ALGORITHMSDESIGN AND ANALYSIS OF ALGORITHMS
DESIGN AND ANALYSIS OF ALGORITHMS
 
9. chapter 8 np hard and np complete problems
9. chapter 8   np hard and np complete problems9. chapter 8   np hard and np complete problems
9. chapter 8 np hard and np complete problems
 
Chomsky Hierarchy.ppt
Chomsky Hierarchy.pptChomsky Hierarchy.ppt
Chomsky Hierarchy.ppt
 
Longest common subsequence
Longest common subsequenceLongest common subsequence
Longest common subsequence
 
Concurrency control
Concurrency controlConcurrency control
Concurrency control
 
Backtracking
BacktrackingBacktracking
Backtracking
 
Syntax Analysis in Compiler Design
Syntax Analysis in Compiler Design Syntax Analysis in Compiler Design
Syntax Analysis in Compiler Design
 

Similar to Alphabets , strings, languages and grammars

Similar to Alphabets , strings, languages and grammars (20)

Theory of Automata ___ Basis ...........
Theory of Automata ___ Basis ...........Theory of Automata ___ Basis ...........
Theory of Automata ___ Basis ...........
 
Theory of Automata
Theory of AutomataTheory of Automata
Theory of Automata
 
Lesson-01-29092022-081117pm.ppt
Lesson-01-29092022-081117pm.pptLesson-01-29092022-081117pm.ppt
Lesson-01-29092022-081117pm.ppt
 
Language
LanguageLanguage
Language
 
Theory of Automata Lesson 01
 Theory of Automata Lesson 01  Theory of Automata Lesson 01
Theory of Automata Lesson 01
 
Lesson 03
Lesson 03Lesson 03
Lesson 03
 
Lesson 03
Lesson 03Lesson 03
Lesson 03
 
Theory of automata and formal language
Theory of automata and formal languageTheory of automata and formal language
Theory of automata and formal language
 
Lecture 3,4
Lecture 3,4Lecture 3,4
Lecture 3,4
 
Lecture 1,2
Lecture 1,2Lecture 1,2
Lecture 1,2
 
Lesson 01.ppt
Lesson 01.pptLesson 01.ppt
Lesson 01.ppt
 
Mod 2_RegularExpressions.pptx
Mod 2_RegularExpressions.pptxMod 2_RegularExpressions.pptx
Mod 2_RegularExpressions.pptx
 
Class7
 Class7 Class7
Class7
 
Compilers midterm spring 2013 model answer
Compilers midterm spring 2013   model answerCompilers midterm spring 2013   model answer
Compilers midterm spring 2013 model answer
 
Introduction to Automata Theory
Introduction to Automata TheoryIntroduction to Automata Theory
Introduction to Automata Theory
 
Theory of Automata Lesson 02
Theory of Automata Lesson 02Theory of Automata Lesson 02
Theory of Automata Lesson 02
 
L_2_apl.pptx
L_2_apl.pptxL_2_apl.pptx
L_2_apl.pptx
 
Lesson 02
Lesson 02Lesson 02
Lesson 02
 
Lesson 02
Lesson 02Lesson 02
Lesson 02
 
Grammar
GrammarGrammar
Grammar
 

Recently uploaded

18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaVirag Sontakke
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsKarinaGenton
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptxENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptxAnaBeatriceAblay2
 
Science lesson Moon for 4th quarter lesson
Science lesson Moon for 4th quarter lessonScience lesson Moon for 4th quarter lesson
Science lesson Moon for 4th quarter lessonJericReyAuditor
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting DataJhengPantaleon
 
Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfadityarao40181
 

Recently uploaded (20)

18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of India
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its Characteristics
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptxENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Science lesson Moon for 4th quarter lesson
Science lesson Moon for 4th quarter lessonScience lesson Moon for 4th quarter lesson
Science lesson Moon for 4th quarter lesson
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
 
Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdf
 

Alphabets , strings, languages and grammars

  • 1. Chapter One Alphabets , Strings, Languages and Grammars Prepared By Haftom B.1
  • 3. Alphabets and Strings A common way to talk about words, number, pairs of words, etc. is by representing them as strings To define strings, we start with an alphabet Examples An alphabet is a finite set of symbols. S1 = {a, b, c, d, …, z}: the set of letters in English S2 = {0, 1, …, 9}: the set of (base 10) digits S3 = {a, b, …, z, #}: the set of letters plus the special symbol # S4 = {(, )}: the set of open and closed brackets Prepared By Haftom B.3
  • 4. Strings The empty string will be denoted by E Examples A string over alphabet S is a finite sequence of symbols in S. abfbz is a string over S1 = {a, b, c, d, …, z} 9021 is a string over S2 = {0, 1, …, 9} ab#bc is a string over S3 = {a, b, …, z, #} ))()(() is a string over S4 = {(, )} Prepared By Haftom B.4
  • 5. Cont.… We will use small alphabets: Strings 5 abbaw bbbaaav abu     ba, baaabbbaaba baba abba ab a Prepared By Haftom B.
  • 6. String Operations 6 m n bbbv aaaw   21 21   bbbaaa abba mn bbbaaawv  2121 1. Concatenation abbabbbaaa Prepared By Haftom B.
  • 7. 7 12aaaw n R  naaaw 21 ababaaabbb 2. Reverse bbbaaababa Prepared By Haftom B.
  • 8. 3. String Length Length: Examples: 8 naaaw 21 nw  1 2 4    a aa abba Prepared By Haftom B.
  • 9. Recursive Definition of Length For any letter: For any string : Example: 9 1a 1 wwawa 4 1111 111 11 1      a ab abbabba Prepared By Haftom B.
  • 10. 4. Length of Concatenation  Example: 10 vuuv  853 8 5, 3,     vuuv aababaabuv vabaabv uaabu Prepared By Haftom B.
  • 11. Proof of Concatenation Length • Claim: • Proof: By induction on the length • Induction basis: • From definition of length: 11 vuuv  v 1v vuuuv  1 Prepared By Haftom B.
  • 12. Empty String  A string with no letters:  Observations: 12  abbaabbaabba www       0 Prepared By Haftom B.
  • 13. Substring Substring of string: a subsequence of consecutive characters String Substring 13 bbab b abba ab abbab abbab abbab abbab Prepared By Haftom B.
  • 14. Prefix and Suffix  Given string  Prefixes Suffixes 14 abbab abbab abba abb ab a   b ab bab bbab abbab uvw  prefix suffix Prepared By Haftom B.
  • 15. Another Operation • Example: • Definition: • 15   n n wwww    abbaabbaabba 2 0 w   0 abba Prepared By Haftom B.
  • 16. The * Operation • : the set of all possible strings from alphabet 16 *     ,,,,,,,,,* , aabaaabbbaabaaba ba   Prepared By Haftom B.
  • 17. 17 The + Operation : the set of all possible strings from alphabet except       ,,,,,,,,,* , aabaaabbbaabaaba ba    *  ,,,,,,,, aabaaabbbaabaaba  Prepared By Haftom B.
  • 18. 1.2 Languages  Languages can be used to describe problems with “yes/no” answers, for example: A language is a set of strings over an alphabet. L1 = The set of all strings over S1 that contain the substring “fool” L2 = The set of all strings over S2 that are divisible by 7 = {7, 14, 21, …} L3 = The set of all strings of the form s#s where s is any string over {a, b, …, z} L4 = The set of all strings over S4 where every ( can be matched with a subsequent ) Prepared By Haftom B.18
  • 19. Cont.…  A language is any subset of  Example 1:  Languages: 19 *    ,,,,,,,,* , aaabbbaabaaba ba       },,,,,{ ,, aaaaaaabaababaabba aabaaa   Prepared By Haftom B.
  • 20. Example 2  An infinite language  is aabbaa ? 20 }0:{  nbaL nn aaaaabbbbb aabb ab  L Labb L Prepared By Haftom B.
  • 21. 21 Note that: }{}{  0}{  1}{  0 Sets Set size Set size String length Prepared By Haftom B.
  • 22. 1.2.1 Operations on Languages • The usual set operations • Complement: 22              aaaaaabbbaaaaaba ababbbaaaaaba aaaabbabaabbbaaaaaba ,,,, }{,,, },,,{,,,      LL  *    ,,,,,,, aaabbabaabbaa  Prepared By Haftom B.
  • 23. Reverse  Definition:  Examples: 23 }:{ LwwL RR     ababbaabababaaabab R ,,,,  }0:{ }0:{   nabL nbaL nnR nn Prepared By Haftom B.
  • 24. Concatenation  Definition:  Example: 24  2121 ,: LyLxxyLL      baaabababaaabbaaaab aabbaaba ,,,,, ,,,  Prepared By Haftom B.
  • 25. Another Operation Definition: Special case: 25   n n LLLL         bbbbbababbaaabbabaaabaaababababa ,,,,,,,,,,, 3           0 0 ,, aaabbaa L Prepared By Haftom B.
  • 26. More Examples 26 }0:{  nbaL nn }0,:{2  mnbabaL mmnn 2 Laabbaaabbb Prepared By Haftom B.
  • 27. Star-Closure (Kleene *) • Definition: • Example: • 27  210 * LLLL                   ,,,, ,,,, ,, , *, abbbbabbaaabbaaa bbbbbbaabbaa bba bba  Prepared By Haftom B.
  • 28. Positive Closure  Definition: 28    * 21 L LLL               ,,,, ,,,, ,, , abbbbabbaaabbaaa bbbbbbaabbaa bba bba Prepared By Haftom B.
  • 29. Grammar Prepared By Haftom B.29 A grammar is a mechanism used for describing languages. This is one of the most simple but yet powerful mechanism. The grammar for English tells us what are the words in it and the rules to construct sentences.
  • 30. Formal definitions of a Grammar Prepared By Haftom B.30 A grammar G is defined as a quadruple
  • 31. Example Prepared By Haftom B.31 Consider the grammar , where N = {S}, ={a, b} and P is the set of the following production rules . Some terminal strings are generated by this grammar together with their derivation is given below
  • 33. Cont.… Prepared By Haftom B.33  Example: Find a grammar for the language It is possible to find a grammar for L by modifying the previous grammar since we need to generate an extra b at the end of the string . We can do this by adding a production S Bb where the non-terminal B generates