18 views

Uploaded by Raja Mehtab

save

- Theory of Automata Lecture 1
- MELJUN CORTES -- AUTOMATA THEORY LECTURE - 10
- Java Advance
- Basic
- Android Chapter16 Resources
- psychology with grammar learning to english language
- Flash Debugger Protocol
- Lesson 1 - Python Grammar
- 05dpmhybrid Wons
- String Operations in Java
- Understanding Formulas Mid Row Indirect - Microsoft Community
- 4.Function
- Spec Style Guide
- B4.pdf
- CP 1 Practical List Prog No 20 to 25
- Les 09
- Tutorial2_CI5100
- pytut
- TOC Lecture 3 Dated 21-March-2013
- Jade Tutorial
- MODBUS
- R_ Character Translation and Casefolding
- What is Obiee
- Calisma Sorulari
- MIT6_00SCS11_ps0
- Cup of c.o.f.f.e.e
- pyton
- 2 Slides
- Assignment
- ArrayList (ch10)
- Sapiens: A Brief History of Humankind
- The Unwinding: An Inner History of the New America
- Yes Please
- Dispatches from Pluto: Lost and Found in the Mississippi Delta
- Elon Musk: Tesla, SpaceX, and the Quest for a Fantastic Future
- The Innovators: How a Group of Hackers, Geniuses, and Geeks Created the Digital Revolution
- John Adams
- Devil in the Grove: Thurgood Marshall, the Groveland Boys, and the Dawn of a New America
- A Heartbreaking Work Of Staggering Genius: A Memoir Based on a True Story
- This Changes Everything: Capitalism vs. The Climate
- Grand Pursuit: The Story of Economic Genius
- The Emperor of All Maladies: A Biography of Cancer
- The Prize: The Epic Quest for Oil, Money & Power
- Team of Rivals: The Political Genius of Abraham Lincoln
- The New Confessions of an Economic Hit Man
- The World Is Flat 3.0: A Brief History of the Twenty-first Century
- Rise of ISIS: A Threat We Can't Ignore
- Smart People Should Build Things: How to Restore Our Culture of Achievement, Build a Path for Entrepreneurs, and Create New Jobs in America
- The Hard Thing About Hard Things: Building a Business When There Are No Easy Answers
- How To Win Friends and Influence People
- Steve Jobs
- Angela's Ashes: A Memoir
- Bad Feminist: Essays
- The Light Between Oceans: A Novel
- The Silver Linings Playbook: A Novel
- Leaving Berlin: A Novel
- Extremely Loud and Incredibly Close: A Novel
- The Sympathizer: A Novel (Pulitzer Prize for Fiction)
- You Too Can Have a Body Like Mine: A Novel
- The Incarnations: A Novel
- Life of Pi
- The Love Affairs of Nathaniel P.: A Novel
- A Man Called Ove: A Novel
- Bel Canto
- The Master
- The Rosie Project: A Novel
- The Blazing World: A Novel
- We Are Not Ourselves: A Novel
- The First Bad Man: A Novel
- The Flamethrowers: A Novel
- Brooklyn: A Novel
- The Art of Racing in the Rain: A Novel
- Wolf Hall: A Novel
- The Wallcreeper
- Interpreter of Maladies
- Beautiful Ruins: A Novel
- The Kitchen House: A Novel
- The Perks of Being a Wallflower
- The Bonfire of the Vanities: A Novel
- Lovers at the Chameleon Club, Paris 1932: A Novel
- A Prayer for Owen Meany: A Novel
- The Cider House Rules
- Mislaid: A Novel

You are on page 1of 35

Mr. Zaheed Ahmed

Theory of Computation

Chapter No 2

LANGUAGES

Theory of Computation

Mr. Zaheed Ahmed

2

Introduction

What does automata mean?

It is the plural of automaton, and it means

“something that works automatically”

Introduction to languages

There are two types of languages

Formal Languages (Syntactic languages)

Informal Languages (Semantic languages)

Theory of Computation

Mr. Zaheed Ahmed

3

Zaheed Ahmed 4 . Σ = {i. Example 1.Alphabets Definition A finite non-empty set of symbols (called letters). j . is called an alphabet. b} 2. It is denoted by Σ (Greek letter sigma).1} (important as this is the language which the computer understands) 3. k} etc. Σ = {0. Σ = {a. Theory of Computation Mr.

Example If Σ= {a. abab.b} then a. 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. ababababababababab Theory of Computation Mr. aaabb.Strings Σ (alphabet) includes letters. Zaheed Ahmed 5 .

Strings Empty string or null string Sometimes a string with no symbol at all is used. The Λ will mostly be used to denote the empty string. It is denoted by small Greek letter Lambda λ OR capital Greek letter Lambda Λ. Theory of Computation Mr. in further discussion. Zaheed Ahmed 6 . called an empty string or null string.

. Theory of Computation Mr. xx. Zaheed Ahmed 7 . . . .Words Definition Words are strings belonging to some language. 3. but not all strings are words. } or L = {x. . } Here x. … are the words of L Note: All words are strings. 2. . Example If Σ = {x} then language L can be defined as L = {xn : n =1. xxx. xx.

aB. bab. (B) (B). (bab). d} then a string BababB can be tokenized in two ways (Ba). It may contain letters consisting of group of symbols Example1 Σ1 = {B. Zaheed Ahmed 8 . bab. (abab). Example 2 If Σ2 = {B.Valid/In-valid Alphabets While defining an alphabet. (B) Theory of Computation Mr. Ba. d}.

Zaheed Ahmed 9 . Theory of Computation Mr. 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. First symbol B is identified as a letter belonging to Σ.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).

a letter may be ended in a letter of same alphabet. One letter should not be the prefix of another. Zaheed Ahmed 10 . no letter should be started with the letter of the same alphabet i.e. Theory of Computation Mr.Remarks While defining an alphabet of letters consisting of more than one symbols. However.

bab. bab. Zaheed Ahmed 11 .Examples of Valid and In-Valid Alphabets Example 1 Σ1 = {B. Theory of Computation Mr. aB. d} Σ2 is an in-valid alphabet. d} Σ1 is a valid alphabet Example 2 Σ2 = {B. Ba.

Zaheed Ahmed 12 . denoted by |s|. d} and s = BaBbabBd then Tokenizing = (B). Example 1 If Σ = {a. b} and s = ababa. bab. (d) And |s| = 5 Theory of Computation Mr. aB. (bab). (aB). then|s| = 5 Example 2 Σ = {B. is the number of letters in the string. (B).Length of Strings Definition (Length of Strings) The length of string s.

Zaheed Ahmed 13 . d} and s = BaBbabBd then Rev(s) = dBbabaBB Theory of Computation Mr. bab. c} then Rev(s) = cba Example 2 Σ = {B. Example 1 If s = abc is defined over Σ = {a. aB.Reverse of a String Definition The reverse of a string s denoted by Rev(s) is obtained by writing the letters of s in reverse order. b.

Recursive definition. such as Descriptive definition.Defining Languages The languages can be defined in different ways . Using Regular Expressions (RE) and Using Finite Automaton (FA) etc. Zaheed Ahmed 14 . Theory of Computation Mr.

Descriptive Definition of Language The language is defined. c}. defined over Σ = {a}. . . bc. b. bb. can be written as L = {b. } Theory of Computation Mr. . aaa. ba. . aaaaa. . c. Zaheed Ahmed 15 . defined over Σ = {a. ca. Example 1 The language L of strings of odd length. can be written as L = {a. } Example 2 Language L. of strings that does not start with a. . describing the conditions imposed on its words.

11. 2}. 1.12.10.20. 02.Descriptive Definition of Language The language L of strings of length 2.21. Zaheed Ahmed 16 . 01. can be written as L = {00.22} Mathematical Description L = {s : S | Length(s) = 2 } Theory of Computation Mr. defined over Σ = {0.

defined over Σ = {0. . Zaheed Ahmed 17 . can be written as {Λ. ab. abab. 110. 010. 100. 10. } Theory of Computation Mr. 00.abba. . b}. . aabb. of strings with number of a’s equal to number of b’s. can be written as L= {0. baba.} Example 5 The language EQUAL.More Examples Example 4 The language L of strings ending in 0. . 000. . . 1}. defined over Σ = {a.

. . b}. } Theory of Computation Mr. bbaa. 4. can be written as {Λ. Zaheed Ahmed 18 . 2. . 1. bb. baba. can be written as INTEGER = {. -2. 3. . abba. 6. -1. 0. 0. . . 9}. . 7. of strings defined over Σ = {-. 8. 1. aa. aabb. 2. bbbb. baab. abab. of strings with even number of a’s and even number of b’s. .} Example 7 The language INTEGER. 5.More Examples Example 6 The language EVEN-EVEN. aaaa. defined over Σ = {a.

. . 7. . of stings defined over Σ = {-. . 4. 0. 9} is written as EVEN = {. 2. . .. . 4. 5. 3. 2.More Examples Example 8 The language EVEN. } Theory of Computation Mr. . of strings defined over Σ = {a. Zaheed Ahmed 19 . . 1. b}. aaabbb. 3. . 6. 0.} Example 9 The language {anbn }. aabb. aaaabbbb. 2. is {anbn | n = 1. -2. } can be written as {ab. 8. -4. .

2. ..} Example 11 The language factorial. 2. of strings defined over Σ = {0. 9} is {1. aabbaa. b}.More Examples Example 10 The language {anbnan}. 24. . 2. Zaheed Ahmed 20 . . 3. 3. 5. 6. aaaabbbbaaaa. .} Theory of Computation Mr. can be written as : {aba. 120. 7. 1. is {anbnan| n = 1. . of strings defined over Σ = {a. 1. 6.…}. aaabbbaaa. 4. 8.

. . . is {an! | n = 1. }. . . aa. of strings defined over Σ = {a}. 2. 3. Theory of Computation Mr. Zaheed Ahmed 21 . . aaaaaa.More Examples Example 12 The language FACTORIAL.} Note: It is to be noted that the language FACTORIAL can be defined over any single letter alphabet. which can be written as {a.

. 2. . aaaaaabbbbbb.More Examples Example 13 The language DOUBLEFACTORIAL.}. . . Zaheed Ahmed 22 .…} Example 14 The language SQUARE. b}. 3. which can be written as {ab. . and can be written as: {a. 3.} Theory of Computation Mr. aabb. aaaaaaaaa. of strings defined over Σ = {a. . 2. is {an2 n = 1. aaaa. of strings defined over Σ = {a}. . is {an!bn! | n = 1. .}. .

aaaabbbb. . is {an2 bn2 | n = 1. is {ap | p is prime}. . b}. aaaaa.} Example 16 The language PRIME. . 3.More Examples Example 15 The language DOUBLESQUARE. aaa. aaaaaaaaabbbbbbbbb. . .}. . . . can be written as {aa. Zaheed Ahmed 23 .} Theory of Computation Mr. . aaaaaaa. of strings defined over Σ = {a}. of strings defined over Σ = {a. which can be written as {ab. 2.

aa.} Theory of Computation Mr. aba. b. Example 17 For Σ = {a. aaa. .More Examples An Important language PALINDROME The language consisting of Λ and the strings s defined over Σ such that Rev(s) = s. . Zaheed Ahmed 24 . a. . It is to be denoted that the words of PALINDROME are called palindromes. b} PALINDROME = {Λ . bbb. bb. bab.

Lexicographical Order Assume that the symbols in Σ are themselves ordered. Theory of Computation Mr. Definition: A set of strings is in lexicographical order if - - The strings are grouped first according to their length. within each group. Then. Zaheed Ahmed 25 . the strings are ordered “alphabetically” according to the ordering of the symbols.

…. bbb. } Theory of Computation Mr. a. bbbb. bb. ba. aaa. b. …. ab. aa.Lexicographical Order Example: Let the alphabet be Σ = {a. b} The set of all strings in Lexicographical order is { . aaaa.. …. Zaheed Ahmed 26 .

the following is to be noted Analysis Note that number of strings of length ‘m’ defined over alphabet of ‘n’ letters is nm.Theorem Theorem There are as many palindromes of length 2n as there are of length 2n-1. Note Before proving the above theorem. Zaheed Ahmed 27 . Theory of Computation Mr.

defined over Σ = {a. bb} i. number of strings = 8 = 23 Theory of Computation Mr.Theorem Example 1 The language of strings of length 2.e. bba. aab. b} is L = {aa.e. abb. b} is L = {aaa. ba. ab. baa. bbb} i. bab. aba. defined over Σ = {a. Zaheed Ahmed 28 . number of strings = 4 = 22 Example 2 The language of strings of length 3.

Proof To calculate the number of palindromes of length(2n). consider the following diagram. Zaheed Ahmed 29 . Theory of Computation Mr.

Zaheed Ahmed 30 . the required number of palindromes are 2n.e. To calculate the number of palindromes of length (2n-1) with ‘a’ as the middle letter. consider the following diagram Theory of Computation Mr.Proof It shows that there are as many palindromes of length 2n as there are strings of length n i.

Proof Theory of Computation Mr. Zaheed Ahmed 31 .

Theory of Computation Mr. with ‘ b ’ as middle letter. the required number of palindromes are 2n-1. will be 2n-1 as well. Zaheed Ahmed 32 . Hence the total number of palindromes of length 2n-1 will be = 2n-1 + 2n-1 = 2n-1(1 + 1) = 2n-1(2) = 2n-1+1 =2n.Proof The above diagram shows that there are as many palindromes of length 2n-1 as there are strings of length n-1 i. Similarly the number of palindromes of length 2n1.e.

Theory of Computation Mr. This is the most important tool in our whole study.Constructive Algorithm The method of proving that something exists by showing how to create it is called proof by constructive algorithm. Zaheed Ahmed 33 .

Summary Introduction to the course title Formal and In-formal languages Alphabets. Words Valid and In-valid alphabets Length of a string Reverse of a string Defining languages Descriptive definition of languages Theory of Computation Mr. Strings. Zaheed Ahmed 34 . Null string.

INTEGER. EVEN-EVEN. EVEN { an bn} {an bn an } Factorial FACTORIAL DOUBLE FACTORIAL SQUARE DOUBLE SQUARE PRIME PALINDROME Theory of Computation Mr.Summary EQUAL. Zaheed Ahmed 35 .

- Theory of Automata Lecture 1Uploaded byRazi Ejaz
- MELJUN CORTES -- AUTOMATA THEORY LECTURE - 10Uploaded byMELJUN CORTES, MBA,MPA
- Java AdvanceUploaded byHaseeb Minhas
- BasicUploaded byfaouzi_genrali
- Android Chapter16 ResourcesUploaded byX Man
- psychology with grammar learning to english languageUploaded byapi-328143145
- Flash Debugger ProtocolUploaded byDheeraj Tyagi
- Lesson 1 - Python GrammarUploaded bygoblinph
- 05dpmhybrid WonsUploaded bySushate Sandal
- String Operations in JavaUploaded byMITMCA
- Understanding Formulas Mid Row Indirect - Microsoft CommunityUploaded byvietpine
- 4.FunctionUploaded byaaanathan
- Spec Style GuideUploaded byPablo Q.
- B4.pdfUploaded byGaby Bumbac
- CP 1 Practical List Prog No 20 to 25Uploaded byPravin Sanap
- Les 09Uploaded bysuresh1130
- Tutorial2_CI5100Uploaded byVladu Ionut
- pytutUploaded byVysakh Sreenivasan
- TOC Lecture 3 Dated 21-March-2013Uploaded byAyaz
- Jade TutorialUploaded byMinh Nguyen
- MODBUSUploaded bymadhan_22
- R_ Character Translation and CasefoldingUploaded byloshude
- What is ObieeUploaded byashish_s_6174
- Calisma SorulariUploaded bySezer Erdoğan
- MIT6_00SCS11_ps0Uploaded byJuan Dominguez
- Cup of c.o.f.f.e.eUploaded byNick Watson
- pytonUploaded bySimma Jhansi
- 2 SlidesUploaded byMeow All
- AssignmentUploaded byMohammed
- ArrayList (ch10)Uploaded bySarah Abdalla