0% found this document useful (0 votes)
15 views63 pages

Theory of Computation: C S I S

The document outlines the course CS 2204: Theory of Computation, taught by Prafulla Kalapatapu at the Centre for Sustainable Infrastructure and Systems. It covers course details, grading policies, expectations, and the primary topics including Automata Theory, Computability Theory, and Complexity Theory. The course aims to explore the fundamental questions of computation, including what can be computed and the limits of computational models.

Uploaded by

abhishavarma
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views63 pages

Theory of Computation: C S I S

The document outlines the course CS 2204: Theory of Computation, taught by Prafulla Kalapatapu at the Centre for Sustainable Infrastructure and Systems. It covers course details, grading policies, expectations, and the primary topics including Automata Theory, Computability Theory, and Complexity Theory. The course aims to explore the fundamental questions of computation, including what can be computed and the limits of computational models.

Uploaded by

abhishavarma
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 63

Centre for Sustainable Infrastructure

and Systems (CSIS)

20th Jan 2025

CS 2204
Theory of Computation
Introduction

Prafulla Kalapatapu
Dept of CSE, Program Coordinator for AI
Center for Sustainable Infrastructure and Systems
(CSIS) CS2204-TOC
CSIS - MU
École Centrale School of Engineering, Mahindra University
Centre for Sustainable Infrastructure
and Systems (CSIS)

Lecture -1
Introduction
Course Details, Components, Motivation

CSIS - MU CS2204-TOC
Prafulla Kalapatapu
Centre for Sustainable Infrastructure
and Systems (CSIS)

Instructor: Prafulla Kalapatapu


Office Hours 4:00 PM – 5:00 PM Wednesday (CSIS – SF)
Lecture
TAs: TBD

Monday 01:35 – 02:30 AM (ELT3) Homework, Exams, Quizzes :


Tuesday 02:35 – 03:30 AM (ELT3) - See Course Information on Course Handout
- Handout will be mailed.
Thursday 02:35 – 03:30 AM (ELT3)

Course Content :
- Slides will be shared to your outlook mails on every Friday.

Text
- “Introduction to the Theory of Computation” Sipser, 3rd Edition.
(Other editions ok but are missing some Exercises and Problems).

CSIS - MU CS2204-TOC
Prafulla Kalapatapu
Centre for Sustainable Infrastructure
and Systems (CSIS)

Course Grading Policy

S.No Evaluation Weightage Mode

1 Assignment/S-quizes 20% Closed Book

2 Major Exam 40% Closed Book

4 Minor -1 20% Closed Book

5 Minor -2 20% Closed Book

CSIS - MU CS2204-TOC
Prafulla Kalapatapu
Centre for Sustainable Infrastructure
and Systems (CSIS)

Course Coverage

Topics No.of Lectuers


Module 1 4
Module 2 16
Module 3 4
Module 4 6
Module 5 8

CSIS - MU CS2204-TOC
Prafulla Kalapatapu
Centre for Sustainable Infrastructure
and Systems (CSIS)

Course Expectation

Prerequisites
• Prior substantial experience and comfort with mathematical concepts, theorems,
and proofs.
• Creativity & practice will be needed for attempting exams well.

CSIS - MU CS2204-TOC
Prafulla Kalapatapu
Centre for Sustainable Infrastructure
and Systems (CSIS)

Course Motivation

What should you expect to get out of this course?

1. Applications
2. Basic Research
3. Connections to other fields
4. What is the nature of computation?

CSIS - MU CS2204-TOC
Prafulla Kalapatapu
Centre for Sustainable Infrastructure
and Systems (CSIS)

What is computable?
Examples:
– check if a number n is prime
– compute the product of two numbers
– sort a list of numbers
– find the maximum number from a list
Hard but computable:
– Given a set of linear inequalities, maximize a linear function
Eg. maximize 5x+2y
3x+2y < 53
x < 32
5x –9y > 22
CSIS - MU CS2204-TOC
Prafulla Kalapatapu
Centre for Sustainable Infrastructure
and Systems (CSIS)

Theory of Computation?
Primary aim of the course: What is “computation”?

• Can we define computation without referring to a modern C computer?

• Can we define, mathematically, a computer? (yes, Turing machines)

• Is computation definable independent of present-day engineering limitations,


understanding of physics, etc.?

• Can a computer solve any problem, given enough time and disk-space? Or
are they fundamental limits to computation?

In short, understand the mathematics of computation


CSIS - MU CS2204-TOC
Prafulla Kalapatapu
Centre for Sustainable Infrastructure
and Systems (CSIS)

Logic Building
Algorithms, flow charts, logics

CSIS - MU CS2204-TOC
Prafulla Kalapatapu
Centre for Sustainable Infrastructure
and Systems (CSIS)

Problem Statement 1
• Write an algorithm to find sum of numbers from 1 to 10
Pre-Analysis :
1 2 3 4 5 6 7 8 9 10
3
Logic = prev sum + nxt numb
6

10

15

21

• How many variables required ?


- Previous sum (sum=0) prev sum of first numbers is ? 0,
so sum=0
- Next number (i=1)
- Till how many numbers (n=10)

CSIS - MU CS2204-TOC
Centre for Sustainable Infrastructure
and Systems (CSIS)

Algorithm

step 1 : Begin
step 2 : input n
step 3 : initialize sum=0, i=1
step 4 : sum= sum+i
step 5 : i=i+1
step 6 : if (i<=n) then goto step4
step 7 : display sum
step 8 : end

CSIS - MU CS2204-TOC
Centre for Sustainable Infrastructure
and Systems (CSIS)

Problem Statement 2
• Write an algorithm to find sum of individual digits of a given number
Pre-Analysis :
Ex: given number n = 376
3 7 6
13 Logic = individual digit(unit’s place)
+ prev sum
16
First get individual digit of Unit’s
place

• How many variables required ?


- Previous sum (sum=0)
- input number (n=376)
- reminder variable (r)

CSIS - MU CS2204-TOC
Centre for Sustainable Infrastructure
and Systems (CSIS)

Algorithm

step 1 : Begin
step 2 : initialize n=376 or input n
step 3 : initialize sum=0, r
step 4 : r = n % 10 Observations :
• Why r=n%10 to be written
step 5 : sum = sum + r • Why n=n/10
step 6 : n = n /10 • n>0
step 7 : if (n>0) then goto step4
step 8 : display sum
step 9 : end

CSIS - MU CS2204-TOC
Centre for Sustainable Infrastructure
and Systems (CSIS)

Problem Statement 3
Write an algorithm to know given number is Armstrong number or not
Pre-Analysis :
Ex: given number n = 153
1 5 3
3*3*3 = 27 Logic = cube of individual digit(unit’s
5*5*5 =125 place) + prev sum

1*1*1 27 + 125 = 152 First get individual digit of Unit’s


place
152+1 = 153

How many variables required ?


- Previous sum (sum=0)
- input number (n=153)
- reminder variable (r)

CSIS - MU CS2204-TOC
Prafulla Kalapatapu
Centre for Sustainable Infrastructure
and Systems (CSIS)

Algorithm
step 1 : Begin
step 2 : initialize n=153 or input n
step 3 : initialize sum=0, d=n , r
step 4 : r = n % 10
Observations :
step 5 : sum = sum + r*r*r • Why d=n to be written
• What if instead of d=n, n=d written?
step 6: n = n /10 • r*r*r
step 7 : if (n>0) then goto step4 • sum == d , why not sum == n
step 8 : if(sum==d) then
step 8.1 : display “Armstrong”
else
step 8.2 : display “not Armstrong”
step 9 : end

CSIS - MU CS2204-TOC
Prafulla Kalapatapu
Centre for Sustainable Infrastructure
and Systems (CSIS)

Problem Statement 4
Write an algorithm to find the given number is even or odd
Analysis : 0 even
Logic = n % 2 =
1 odd
Algorithm

step 1 : begin
step 2 : Read n
step 3 : if(n%2 == 0) then
step 3.1 : print “even”
else
step 3.2 : print “odd”
step 4 : end

CSIS - MU CS2204-TOC
Prafulla Kalapatapu
Centre for Sustainable Infrastructure
and Systems (CSIS)

Problem Statement 5
Write an algorithm to swap two numbers
(i) using temp variable
(ii) without using temp variable
Logic :
How many variables required ?
3
c=a
- First value a=b
- Second value b=c

- Temp variable

How many variable required ?


2 a=a+b
b=a-b
- First value a=a-b
- Second value

CSIS - MU CS2204-TOC
Prafulla Kalapatapu
Centre for Sustainable Infrastructure
and Systems (CSIS)

Algorithm (i) : Algorithm (ii) : Observations :

Step 1 : begin Step 1 : begin With respect to speed :


Algorithm (i) is preferred
Step 2 : read a , b Step 2 : read a , b Why ?
3 operations (all assignment opts)
Step 3 : c = a Step 3 : a = a + b
With respect to memory :
Step 4 : a = b Step 4 : b = a - b Algorithm (ii) is preferred
why ?
Step 5 : b = c Step 5 : a = a - b 2 variables used ( a, b)

Step 6 : print a , b Step 6 : print a , b

Step 7 : end Step 7 : end

CSIS - MU CS2204-TOC
Prafulla Kalapatapu
Centre for Sustainable Infrastructure
and Systems (CSIS)

Lecture -2
Automata, computation, complexity

CSIS - MU CS2204-TOC
Prafulla Kalapatapu
Centre for Sustainable Infrastructure
and Systems (CSIS)

This course teaches two things:

• Mathematical maturity -> Is the key to success in your scientific career


- Practice mathematical notation: sets, quantifiers, etc.
- Get some exposure to proofs

• Theory of computation
- We develop models of computation, and ask:
-> what can and cannot be computed in these models, and how
quickly? with how much memory?

- Questions fundamental to all of science.


-> Nature computes!

CSIS - MU CS2204-TOC
Prafulla Kalapatapu
Centre for Sustainable Infrastructure
and Systems (CSIS)

Theory of computation:

• Most famous open question:


Is P = NP ?

• “Millennium Problem” with prize $1M

• We will learn what this question means in this course

CSIS - MU CS2204-TOC
Prafulla Kalapatapu
Centre for Sustainable Infrastructure
and Systems (CSIS)

Overview of material in Theory of Computation:

• Automata Theory

• Computability Theory

• Complexity Theory

CSIS - MU CS2204-TOC
Prafulla Kalapatapu
Centre for Sustainable Infrastructure
and Systems (CSIS)

Automata Theory

• Finite automata: Computers with no memory

Motivation: Numbers, names, in Prog. Languages


Example: x = -0.0565

• Context-free grammars: Memory = stack

Motivation: Syntax, grammar of Prog. Languages


Example: if (...) then (…) else (…)

CSIS - MU CS2204-TOC
Prafulla Kalapatapu
Centre for Sustainable Infrastructure
and Systems (CSIS)

Computability Theory

• Turing Machines: “Compute until the sun dies”

Motivation: What problems can be solved at all?


Example: Given a program, does it have a bug?

We will prove impossible to determine!

CSIS - MU CS2204-TOC
Prafulla Kalapatapu
Centre for Sustainable Infrastructure
and Systems (CSIS)

Complexity Theory

• P, NP: Model your laptop

Motivation: What problems can be solved fast?

Example: Given a formula with 1000 variables like


(X OR Y) AND (X OR NOT Z) AND (Z OR Y) …
Is it satisfiable or not?
Does it take 1 thousand years or 1 second to know?

CSIS - MU CS2204-TOC
Prafulla Kalapatapu
Centre for Sustainable Infrastructure
and Systems (CSIS)

Lecture -3
Automata Theory

CSIS - MU CS2204-TOC
Prafulla Kalapatapu
Centre for Sustainable Infrastructure
and Systems (CSIS)

What is Automata Theory?


• Study of abstract computing devices, or “machines”
• Automaton = an abstract computing device
• Note: A “device” need not even be a physical hardware!
• A fundamental question in computer science:
• Find out what different models of machines can do and cannot do
• The theory of computation
• Computability vs. Complexity

CSIS - MU CS2204-TOC
28
Prafulla Kalapatapu
Centre for Sustainable Infrastructure
and Systems (CSIS)
(A pioneer of automata theory)
Alan Turing (1912-1954)
• Father of Modern Computer Science
• English mathematician
• Studied abstract machines called Turing
machines even before computers existed
• Heard of the Turing test?

CSIS - MU CS2204-TOC
29
Prafulla Kalapatapu
Centre for Sustainable Infrastructure
and Systems (CSIS)

Theory of Computation: A Historical Perspective


1930s • Alan Turing studies Turing machines
• Decidability
• Halting problem

1940-1950s • “Finite automata” machines studied


• Noam Chomsky proposes the
“Chomsky Hierarchy” for formal
languages

1969 Cook introduces “intractable” problems


or “NP-Hard” problems

1970- Modern computer science: compilers,


computational & complexity theory evolve

CSIS - MU CS2204-TOC
30
Prafulla Kalapatapu
Centre for Sustainable Infrastructure
and Systems (CSIS)

Languages & Grammars

• Languages: “A language is a collection of


Or “words” sentences of finite length all
constructed from a finite alphabet of
symbols”
• Grammars: “A grammar can be regarded
as a device that enumerates the
sentences of a language” - nothing
more, nothing less

• N. Chomsky, Information and Control,


Vol 2, 1959

CSIS - MU Image source: Nowak et al. Nature, vol 417, 2002 CS2204-TOC
31
Centre for Sustainable Infrastructure
and Systems (CSIS)

The Chomsky Hierachy


• A containment hierarchy of classes of formal languages

Regular Context-
(DFA) free Context- Recursively-
(PDA) sensitive enumerable
(LBA) (TM)

CSIS - MU CS2204-TOC
32
Prafulla Kalapatapu
33 Centre for Sustainable Infrastructure
and Systems (CSIS)

The Central Concepts of


Automata Theory

CSIS - MU CS2204-TOC
Centre for Sustainable Infrastructure
and Systems (CSIS)

Alphabet
An alphabet is a finite, non-empty set of symbols
• We use the symbol ∑ (sigma) to denote an alphabet
• Examples:
• Binary: ∑ = {0,1}
• All lower case letters: ∑ = {a,b,c,..z}
• Alphanumeric: ∑ = {a-z, A-Z, 0-9}
• DNA molecule letters: ∑ = {a,c,g,t}
• …

CSIS - MU CS2204-TOC
34
Prafulla Kalapatapu
Centre for Sustainable Infrastructure
and Systems (CSIS)

Strings
A string or word is a finite sequence of symbols chosen from ∑
• Empty string is  (or “epsilon”)

• Length of a string w, denoted by “|w|”, is equal to the number of (non-


) characters in the string
• E.g., x = 010100 |x| = 6
• x = 01  0  1  00  |x| = ?

• xy = concatenation of two strings x and y

CSIS - MU CS2204-TOC
35
Prafulla Kalapatapu
Centre for Sustainable Infrastructure
and Systems (CSIS)

Powers of an alphabet
Let ∑ be an alphabet.

• ∑k = the set of all strings of length k

• ∑* = ∑0 U ∑1 U ∑2 U …

• ∑+ = ∑1 U ∑2 U ∑3 U …

CSIS - MU CS2204-TOC
36
Prafulla Kalapatapu
Centre for Sustainable Infrastructure
and Systems (CSIS)

Languages
L is a said to be a language over alphabet ∑, only if L  ∑*
➔ this is because ∑* is the set of all strings (of all possible length including 0) over the given
alphabet ∑
Examples:
1. Let L be the language of all strings consisting of n 0’s followed by n 1’s:
L = {, 01, 0011, 000111,…}
2. Let L be the language of all strings of with equal number of 0’s and 1’s:
L = {, 01, 10, 0011, 1100, 0101, 1010, 1001,…}

Canonical ordering of strings in the language

Definition: Ø denotes the Empty language


• Let L = {}; Is L=Ø? NO

CSIS - MU CS2204-TOC
37
Prafulla Kalapatapu
Centre for Sustainable Infrastructure
and Systems (CSIS)

The Membership Problem


Given a string w ∑*and a language L over ∑, decide whether or not wL.

Example:
Let w = 100011
Q) Is w  the language of strings with equal number of 0s and 1s?

CSIS - MU CS2204-TOC
38
Prafulla Kalapatapu
Centre for Sustainable Infrastructure
and Systems (CSIS)

Finite Automata
• Some Applications
• Software for designing and checking the behavior of digital circuits
• Lexical analyzer of a typical compiler
• Software for scanning large bodies of text (e.g., web pages) for pattern finding
• Software for verifying systems of all types that have a finite number of states
(e.g., stock market transaction, communication/network protocol)

CSIS - MU CS2204-TOC
39
Prafulla Kalapatapu
Centre for Sustainable Infrastructure
and Systems (CSIS)

Finite Automata : Examples


• On/Off switch action
state

• Modeling recognition of the word “then”

Start state Transition Intermediate Final state


state

CSIS - MU CS2204-TOC
40
Prafulla Kalapatapu
Centre for Sustainable Infrastructure
and Systems (CSIS)

Structural expressions
• Grammars
• Regular expressions
• E.g., unix style to capture city names such as “Palo Alto CA”:

• [A-Z][a-z]*([ ][A-Z][a-z]*)*[ ][A-Z][A-Z]

Start with a letter

A string of other Should end w/ 2-letter state code


letters (possibly
empty)
Other space delimited words
(part of city name)

CSIS - MU CS2204-TOC
41
Prafulla Kalapatapu
42 Centre for Sustainable Infrastructure
and Systems (CSIS)

Formal Proofs

CSIS - MU CS2204-TOC
Centre for Sustainable Infrastructure
and Systems (CSIS)

Deductive Proofs
From the given statement(s) to a conclusion statement (what we want to prove)
• Logical progression by direct implications

Example for parsing a statement:


“If y≥4, then 2y≥y2.”
given conclusion

(there are other ways of writing this).

CSIS - MU CS2204-TOC
43
Prafulla Kalapatapu
Centre for Sustainable Infrastructure
and Systems (CSIS)

Example: Deductive proof


Let Claim 1: If y≥4, then 2y≥y2.
Let x be any number which is obtained by adding the squares of 4 positive integers.

Claim 2:
Given x and assuming that Claim 1 is true, prove that 2x≥x2
Proof:
1) Given: x = a2 + b2 + c2 + d2
2) Given: a≥1, b≥1, c≥1, d≥1
3) ➔ a2≥1, b2≥1, c2≥1, d2≥1 (by 2)
4) ➔x≥4 (by 1 & 3)
5) ➔ 2x ≥ x2 (by 4 and Claim 1)
“implies” or “follows”

CSIS - MU CS2204-TOC
44
Prafulla Kalapatapu
Centre for Sustainable Infrastructure
and Systems (CSIS)

On Theorems, Lemmas and Corollaries


We typically refer to:
• A major result as a “theorem”
• An intermediate result that we show to prove a larger result as a “lemma”
• A result that follows from an already proven result as a “corollary”

An example:
Theorem: The height of an n-node binary tree is at least floor(lg n)

Lemma: Level i of a perfect binary tree has 2i nodes.

Corollary: A perfect binary tree of height h has 2h+1-1 nodes.

CSIS - MU CS2204-TOC
45
Prafulla Kalapatapu
Centre for Sustainable Infrastructure
and Systems (CSIS)

Quantifiers
“For all” or “For every”
• Universal proofs
• Notation=

“There exists”
• Used in existential proofs
• Notation=

Implication is denoted by =>


• E.g., “IF A THEN B” can also be written as “A=>B”

CSIS - MU CS2204-TOC
46
Prafulla Kalapatapu
Centre for Sustainable Infrastructure
and Systems (CSIS)

Proving techniques
• By contradiction
• Start with the statement contradictory to the given statement
• E.g., To prove (A => B), we start with:
• (A and ~B)
• … and then show that could never happen

What if you want to prove that “(A and B => C or D)”?


• By induction
• (3 steps) Basis, inductive hypothesis, inductive step
• By contrapositive statement
• If A then B ≡ If ~B then ~A

CSIS - MU CS2204-TOC
47
Prafulla Kalapatapu
Centre for Sustainable Infrastructure
and Systems (CSIS)

Proving techniques…
• By counter-example
• Show an example that disproves the claim

• Note: There is no such thing called a “proof by example”!


• So when asked to prove a claim, an example that satisfied that claim is not a
proof

CSIS - MU CS2204-TOC
48
Prafulla Kalapatapu
Centre for Sustainable Infrastructure
and Systems (CSIS)

Different ways of saying the same thing

“If H then C”:


i. H implies C
ii. H => C
iii. C if H
iv. H only if C
v. Whenever H holds, C follows

CSIS - MU CS2204-TOC
49
Prafulla Kalapatapu
Centre for Sustainable Infrastructure
and Systems (CSIS)

“If-and-Only-If” statements
• “A if and only if B” (A <==> B)
• (if part) if B then A ( <= )
• (only if part) A only if B ( => )
(same as “if A then B”)
• “If and only if” is abbreviated as “iff”
• i.e., “A iff B”
• Example:
• Theorem: Let x be a real number. Then floor of x = ceiling of x if and only if x is
an integer.
• Proofs for iff have two parts
• One for the “if part” & another for the “only if part”

CSIS - MU CS2204-TOC
50
Prafulla Kalapatapu
Centre for Sustainable Infrastructure
and Systems (CSIS)

Take home message


• Automata theory & a historical perspective
• Chomsky hierarchy
• Finite automata
• Alphabets, strings/words/sentences, languages
• Membership problem
• Proofs:
• Deductive, induction, contrapositive, contradiction, counterexample
• If and only if

• Read chapter 1 for more examples and exercises from prescribed TextBook

CSIS - MU CS2204-TOC
51
Prafulla Kalapatapu
52 Centre for Sustainable Infrastructure
and Systems (CSIS)

Finite Automaton (FA)

CSIS - MU CS2204-TOC
Centre for Sustainable Infrastructure
and Systems (CSIS)

Finite Automaton (FA)


• Informally, a state diagram that comprehensively captures all possible states and
transitions that a machine can take while responding to a stream or sequence of
input symbols
• Recognizer for “Regular Languages”

• Deterministic Finite Automata (DFA)


• The machine can exist in only one state at any given time
• Non-deterministic Finite Automata (NFA)
• The machine can exist in multiple states at the same time

CSIS - MU CS2204-TOC
53
Prafulla Kalapatapu
Centre for Sustainable Infrastructure
and Systems (CSIS)

Deterministic Finite Automata - Definition


• DFA refers to Deterministic Finite Automata.
• Deterministic refers to the uniqueness of the computation.
• The finite automata are called deterministic finite automata if the
machine reads an input string -> one symbol at a time.
• In DFA, there is only one path for specific input from the current state to
the next state.
• DFA does not accept the null move, i.e., the DFA cannot change state
without any input character.
• DFA can contain multiple final states. It is used in Lexical Analysis in
Compiler.

CSIS - MU CS2204-TOC
Prafulla Kalapatapu
Centre for Sustainable Infrastructure
and Systems (CSIS)

Deterministic Finite Automata - Definition


• A Deterministic Finite Automaton (DFA) consists of:
• Q ==> a finite set of states
• ∑ ==> a finite set of input symbols (alphabet)
• q0 ==> a start state
• F ==> set of accepting states
• δ ==> a transition function, which is a mapping between Q x ∑ ==> Q
• A DFA is defined by the 5-tuple:
• {Q, ∑ , q0,F, δ }

CSIS - MU CS2204-TOC
55
Prafulla Kalapatapu
Centre for Sustainable Infrastructure
and Systems (CSIS)

What does a DFA do on reading an input string?

• Input: a word w in ∑*
• Question: Is w acceptable by the DFA?
• Steps:
• Start at the “start state” q0
• For every input symbol in the sequence w do
• Compute the next state from the current state, given the current input symbol in w and
the transition function
• If after all symbols in w are consumed, the current state is one of the
accepting states (F) then accept w;
• Otherwise, reject w.

CSIS - MU CS2204-TOC
56
Prafulla Kalapatapu
Centre for Sustainable Infrastructure
and Systems (CSIS)

Regular Languages
• Let L(A) be a language recognized by a DFA ‘A’.
• Then L(A) is called a “Regular Language”.

• Locate regular languages in the Chomsky Hierarchy

CSIS - MU CS2204-TOC
57
Prafulla Kalapatapu
Centre for Sustainable Infrastructure
and Systems (CSIS)

The Chomsky Hierachy


• A containment hierarchy of classes of formal languages

Regular Context-
(DFA) free Context-
Recursively-
(PDA) sensitive
enumerable
(LBA)
(TM)

CSIS - MU CS2204-TOC
Prafulla Kalapatapu
Centre for Sustainable Infrastructure
and Systems (CSIS)

Examples to discuss in lecture hour - DFA


1. L= set of all strings that start with 0 over {0,1}

2. L= DFA that accepts sets of al strings over {0,1} of length 2

3. L= DFA which accepts all the strings containing atleast 3 a’s with {a,b}
into three broad categories atleast, exactly, atmost.

CSIS - MU 122 CS2204-TOC


59
Prafulla Kalapatapu
Centre for Sustainable Infrastructure
and Systems (CSIS)

Example #1 Transition diagram

Q = {q0, q1, q2}


∑ = {0, 1}
q0 = {q0}
F = {q2}
Transition table

Present State Next state for Next State of


Input 0 Input 1
→q0 q0 q1
q1 q2 q1
*q2 q2 q2

CSIS - MU CS2204-TOC
60
Prafulla Kalapatapu
Centre for Sustainable Infrastructure
and Systems (CSIS)

Example #2
DFA with ∑ = {0, 1} accepts all starting with 0.

Transition diagram Transition table ?????

Present State Next state for Next State of


Input 0 Input 1

CSIS - MU CS2204-TOC
61
Prafulla Kalapatapu
Centre for Sustainable Infrastructure
and Systems (CSIS)

Example #3
• Build a DFA for the following language:
• L = {w | w is a binary string that contains 01 as a substring}
• Steps for building a DFA to recognize L:
• ∑ = {0,1}
• Decide on the states: Q
• Designate start state and final state(s)
• δ: Decide on the transitions:
• “Final” states == same as “accepting states”
• Other states == same as “non-accepting states”

CSIS - MU CS2204-TOC
62
Prafulla Kalapatapu
Centre for Sustainable Infrastructure
and Systems (CSIS)

DFA for strings containing 01 Regular expression: (0+1)*01(0+1)*

• What makes this DFA deterministic? • Q = {q0,q1,q2}

1 0,1 • ∑ = {0,1}
0
• start state = q0
start 0 1
q0 q1 q2 • F = {q2}
Accepting • Transition table
state symbols
0 1
q0 q1 q0
• What if the language allows

states
q1 q1 q2
empty strings? *q2 q2 q2

CSIS - MU CS2204-TOC

You might also like