SlideShare a Scribd company logo
1 of 15
Chapter 1
INTRODUCTION TO THE
THEORY OF
COMPUTATION
Learning Objectives
At the conclusion of the chapter, the student will be able to:
• Define the three basic concepts in the theory of
computation: automaton, formal language, and
grammar.
• Solve exercises using mathematical techniques and
notation learned in previous courses.
• Evaluate expressions involving operations on strings.
• Evaluate expressions involving operations on languages.
• Generate strings from simple grammars.
• Construct grammars to generate simple languages.
• Describe the essential components of an automaton.
• Design grammars to describe simple programming
constructs.
Theory of Computation
Basic Concepts
• Automaton: a formal construct that accepts input,
produces output, may have some temporary storage,
and can make decisions
• Formal Language: a set of sentences formed from a set
of symbols according to formal rules
• Grammar: a set of rules for generating the sentences in
a formal language
In addition, the theory of computation is concerned with
questions of computability (the types of problems
computers can solve in principle) and complexity (the
types of problems that can solved in practice).
Review of Mathematical
Preliminaries
• Sets: basic notation, operations (union,
intersection, difference, and complementation),
disjoint sets, power set, partitions.
• Functions and Relations: domain, range, total
function, partial function, order of magnitude,
equivalence relations.
• Graphs and Trees: vertices, edges, walk, path,
simple path, cycle, loop, root vertex, parent, child,
leaves, level, height.
• Proof Techniques: proof by induction and proof by
contradiction.
Formal Languages
Basic Concepts
• Alphabet: set of symbols, i.e. Σ = {a, b}
• String: finite sequence of symbols from Σ, such as
v = aba and w = abaaa
• Empty string (λ)
• Substring, prefix, suffix
• Operations on strings:
• Concatenation: vw = abaabaaa
• Reverse: wR = aaaba
• Repetition: v2 = abaaba and v0 = λ
• Length of a string: |v| = 3 and |λ| = 0
Formal Languages
Definitions
• Σ* = set of all strings formed by concatenating
zero or more symbols in Σ
• Σ+ = set of all non-empty strings formed by
concatenating symbols in Σ
In other words, Σ+ = Σ* - { λ }
• A formal language is any subset of Σ*
Examples: L1 = { anbn: n ≥ 0 } and L2 = { ab, aa }
• A string in a language is also called a sentence of
the language
Formal Languages
Set Operations
• A language is a set. Therefore, set operations are
defined as usual.
• If L1 = { anbn: n ≥ 0 } and L2 = { ab, aa }
• Union: L1 ᴜL2 = { aa, λ, ab, aabb, aaabbb, … }
• Intersection: L1 ∩ L2 = { ab }
• Difference: L1 - L2 = { λ, aabb, aaabbb, … }
• Complement: L2 = Σ* - { ab, aa }
• Practice: Find L2 – L1
Formal Languages
Other Operations
• New languages can be produced by reversing all strings
in a language, concatenating strings from two languages,
and concatenating strings from the same language.
• If L1 = { anbn: n ≥ 0 } and L2 = { ab, aa }
• Reverse: L2
R = { ba, aa }
• Concatenation: L1L2 = { ab, aa, abab, abaa, aabbab, aabbaa, … }
The concatenation L2L2 or L2
2 = { abab, abaa, aaab, aaaa }
• Star-Closure: L2* = L2
0 ᴜ L2
1 ᴜ L2
2 ᴜ L2
3 ᴜ …
• Positive Closure: L2
+ = L2
1 ᴜ L2
2 ᴜ L2
3 ᴜ …
• Practice: Find (L2 – L1)R
Grammars
Definition
• Precise mechanism to describe the strings in a
language
• Def. 1.1: A grammar G consists of:
V: a finite set of variable or non-terminal symbols
T: a finite set of terminal symbols
S: a variable called the start symbol
P: a set of productions
• Example 1.11:
V = { S }
T = { a, b }
P = { S  aSb, S  λ }
Grammars
Derivation of Strings
• Beginning with the start symbol, strings are derived
by repeatedly replacing variable symbols with the
expression on the right-hand side of any applicable
production
• Any applicable production can be used, in arbitrary
order, until the string contains no variable symbols.
• Sample derivation using grammar in Example 1.11:
S  aSb (applying first production)
 aaSbb (applying first production)
 aabb (applying second production)
The Language Generated by a
Grammar
• Def. 1.2: For a given grammar G, the language
generated by G, L(G), is the set of all strings
derived from the start symbol
• To show a language L is generated by G:
• Show every string in L can be generated by G
• Show every string generated by L is in G
• A given language can normally be generated by
different grammars
Equivalence of Grammars
• Two grammars are equivalent if they
generate the same language
• For convenience, productions with the same
left-hand sides are written on the same line
• Example 1.14:
V = { A, S }, T = { a, b }, and productions
S  aAb | λ
A  aAb | λ
• The grammars in examples 1.11 and 1.14 can
be shown to be equivalent
Automata
• An automaton is an abstract model of a digital
computer
• An automaton consists of
• An input mechanism
• A control unit
• Possibly, a storage mechanism
• Possibly, an output mechanism
• Control unit can be in any number of internal
states, as determined by a next-state or transition
function.
Diagram of a General Automaton
Application
Grammars for Programming Languages
• The syntax of constructs in a programming
language is commonly described with grammars
• Assume that in a hypothetical programming
language,
• Identifiers consist of digits and the letters a, b, or c
• Identifiers must begin with a letter
• Productions for a sample grammar:
<id>  <letter> <rest>
<rest>  <letter> <rest> | <digit> <rest> | λ
<letter>  a | b | c
<digit>  0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9

More Related Content

Similar to 9781284077247_PPTx_CH01.pptx

Similar to 9781284077247_PPTx_CH01.pptx (20)

Context free langauges
Context free langaugesContext free langauges
Context free langauges
 
Module 1 TOC.pptx
Module 1 TOC.pptxModule 1 TOC.pptx
Module 1 TOC.pptx
 
Theory of computing
Theory of computingTheory of computing
Theory of computing
 
Flat unit 3
Flat unit 3Flat unit 3
Flat unit 3
 
01-Introduction&Languages.pdf
01-Introduction&Languages.pdf01-Introduction&Languages.pdf
01-Introduction&Languages.pdf
 
2. context free langauages
2. context free langauages2. context free langauages
2. context free langauages
 
Control structure
Control structureControl structure
Control structure
 
Context Free Grammar
Context Free GrammarContext Free Grammar
Context Free Grammar
 
Unit-1-part-1.pptx
Unit-1-part-1.pptxUnit-1-part-1.pptx
Unit-1-part-1.pptx
 
L_2_apl.pptx
L_2_apl.pptxL_2_apl.pptx
L_2_apl.pptx
 
contextfreegrammars-120925004035-phpapp02.pdf
contextfreegrammars-120925004035-phpapp02.pdfcontextfreegrammars-120925004035-phpapp02.pdf
contextfreegrammars-120925004035-phpapp02.pdf
 
LVEE 2014: Text parsing with Python and PLY
LVEE 2014: Text parsing with Python and PLYLVEE 2014: Text parsing with Python and PLY
LVEE 2014: Text parsing with Python and PLY
 
Theory of Automata ___ Basis ...........
Theory of Automata ___ Basis ...........Theory of Automata ___ Basis ...........
Theory of Automata ___ Basis ...........
 
theory of computation lecture 02
theory of computation lecture 02theory of computation lecture 02
theory of computation lecture 02
 
Theory of automata and formal language
Theory of automata and formal languageTheory of automata and formal language
Theory of automata and formal language
 
Lex and Yacc ppt
Lex and Yacc pptLex and Yacc ppt
Lex and Yacc ppt
 
intro.ppt
intro.pptintro.ppt
intro.ppt
 
Regular Expression to Finite Automata
Regular Expression to Finite AutomataRegular Expression to Finite Automata
Regular Expression to Finite Automata
 
Theory of Computation Basic Concepts and Grammar
Theory of Computation Basic Concepts and GrammarTheory of Computation Basic Concepts and Grammar
Theory of Computation Basic Concepts and Grammar
 
Syntax
SyntaxSyntax
Syntax
 

Recently uploaded

Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxAvyJaneVismanos
 
Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...jaredbarbolino94
 
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxsocialsciencegdgrohi
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfUjwalaBharambe
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupJonathanParaisoCruz
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
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
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfMahmoud M. Sallam
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementmkooblal
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfSumit Tiwari
 
Meghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentMeghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentInMediaRes1
 
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
 
Capitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitolTechU
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxEyham Joco
 

Recently uploaded (20)

Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptx
 
Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...
 
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
 
OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized Group
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).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
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdf
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of management
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
 
Meghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentMeghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media Component
 
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
 
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
 
Capitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptx
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptx
 

9781284077247_PPTx_CH01.pptx

  • 1. Chapter 1 INTRODUCTION TO THE THEORY OF COMPUTATION
  • 2. Learning Objectives At the conclusion of the chapter, the student will be able to: • Define the three basic concepts in the theory of computation: automaton, formal language, and grammar. • Solve exercises using mathematical techniques and notation learned in previous courses. • Evaluate expressions involving operations on strings. • Evaluate expressions involving operations on languages. • Generate strings from simple grammars. • Construct grammars to generate simple languages. • Describe the essential components of an automaton. • Design grammars to describe simple programming constructs.
  • 3. Theory of Computation Basic Concepts • Automaton: a formal construct that accepts input, produces output, may have some temporary storage, and can make decisions • Formal Language: a set of sentences formed from a set of symbols according to formal rules • Grammar: a set of rules for generating the sentences in a formal language In addition, the theory of computation is concerned with questions of computability (the types of problems computers can solve in principle) and complexity (the types of problems that can solved in practice).
  • 4. Review of Mathematical Preliminaries • Sets: basic notation, operations (union, intersection, difference, and complementation), disjoint sets, power set, partitions. • Functions and Relations: domain, range, total function, partial function, order of magnitude, equivalence relations. • Graphs and Trees: vertices, edges, walk, path, simple path, cycle, loop, root vertex, parent, child, leaves, level, height. • Proof Techniques: proof by induction and proof by contradiction.
  • 5. Formal Languages Basic Concepts • Alphabet: set of symbols, i.e. Σ = {a, b} • String: finite sequence of symbols from Σ, such as v = aba and w = abaaa • Empty string (λ) • Substring, prefix, suffix • Operations on strings: • Concatenation: vw = abaabaaa • Reverse: wR = aaaba • Repetition: v2 = abaaba and v0 = λ • Length of a string: |v| = 3 and |λ| = 0
  • 6. Formal Languages Definitions • Σ* = set of all strings formed by concatenating zero or more symbols in Σ • Σ+ = set of all non-empty strings formed by concatenating symbols in Σ In other words, Σ+ = Σ* - { λ } • A formal language is any subset of Σ* Examples: L1 = { anbn: n ≥ 0 } and L2 = { ab, aa } • A string in a language is also called a sentence of the language
  • 7. Formal Languages Set Operations • A language is a set. Therefore, set operations are defined as usual. • If L1 = { anbn: n ≥ 0 } and L2 = { ab, aa } • Union: L1 ᴜL2 = { aa, λ, ab, aabb, aaabbb, … } • Intersection: L1 ∩ L2 = { ab } • Difference: L1 - L2 = { λ, aabb, aaabbb, … } • Complement: L2 = Σ* - { ab, aa } • Practice: Find L2 – L1
  • 8. Formal Languages Other Operations • New languages can be produced by reversing all strings in a language, concatenating strings from two languages, and concatenating strings from the same language. • If L1 = { anbn: n ≥ 0 } and L2 = { ab, aa } • Reverse: L2 R = { ba, aa } • Concatenation: L1L2 = { ab, aa, abab, abaa, aabbab, aabbaa, … } The concatenation L2L2 or L2 2 = { abab, abaa, aaab, aaaa } • Star-Closure: L2* = L2 0 ᴜ L2 1 ᴜ L2 2 ᴜ L2 3 ᴜ … • Positive Closure: L2 + = L2 1 ᴜ L2 2 ᴜ L2 3 ᴜ … • Practice: Find (L2 – L1)R
  • 9. Grammars Definition • Precise mechanism to describe the strings in a language • Def. 1.1: A grammar G consists of: V: a finite set of variable or non-terminal symbols T: a finite set of terminal symbols S: a variable called the start symbol P: a set of productions • Example 1.11: V = { S } T = { a, b } P = { S  aSb, S  λ }
  • 10. Grammars Derivation of Strings • Beginning with the start symbol, strings are derived by repeatedly replacing variable symbols with the expression on the right-hand side of any applicable production • Any applicable production can be used, in arbitrary order, until the string contains no variable symbols. • Sample derivation using grammar in Example 1.11: S  aSb (applying first production)  aaSbb (applying first production)  aabb (applying second production)
  • 11. The Language Generated by a Grammar • Def. 1.2: For a given grammar G, the language generated by G, L(G), is the set of all strings derived from the start symbol • To show a language L is generated by G: • Show every string in L can be generated by G • Show every string generated by L is in G • A given language can normally be generated by different grammars
  • 12. Equivalence of Grammars • Two grammars are equivalent if they generate the same language • For convenience, productions with the same left-hand sides are written on the same line • Example 1.14: V = { A, S }, T = { a, b }, and productions S  aAb | λ A  aAb | λ • The grammars in examples 1.11 and 1.14 can be shown to be equivalent
  • 13. Automata • An automaton is an abstract model of a digital computer • An automaton consists of • An input mechanism • A control unit • Possibly, a storage mechanism • Possibly, an output mechanism • Control unit can be in any number of internal states, as determined by a next-state or transition function.
  • 14. Diagram of a General Automaton
  • 15. Application Grammars for Programming Languages • The syntax of constructs in a programming language is commonly described with grammars • Assume that in a hypothetical programming language, • Identifiers consist of digits and the letters a, b, or c • Identifiers must begin with a letter • Productions for a sample grammar: <id>  <letter> <rest> <rest>  <letter> <rest> | <digit> <rest> | λ <letter>  a | b | c <digit>  0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9