SlideShare a Scribd company logo
1 of 22
Dr. Hussien Sharaf
Computer Science Department
dr.sharaf@from-masr.com
p.434: Regular Languages and non-
regular languages
Dr. Hussien M. Sharaf 2
Language
Defined
by
Corresponding
Accepting
Machine
Nondeter-
minism=
Determinism
Language
Closed Under
What Can Be
Decided?
Examples of
Applications
Regular
expression
Finite
automaton,
transition graph
Yes Union,productKl
eene star,
intersection,
complement
Equivalence,
emptiness,
finiteness,
membership
Text editors,
sequential
circuits,
verification
Context-
free
grammar
Pushdown
automaton
No Union,
product,
Kleene star
Emptiness,
finiteness,
membership
Parsing,
compilers
Type 0
grammar
Turing machine,
Post machine,
Pushdown
automaton
Yes Union,
product,
Kleene star
Not much Computers
PDA
 A Pushdown Automata (PDA ) is a DFA equipped
with a single stack.
Dr. Hussien M. Sharaf 3
1
4
3
2
1 2 3 4
Input Tape
Tape cells
PDA
Dr. Hussien M. Sharaf 4
1. Q : A finite set of states (Q).
2. Σ : A set of input alphabet.
3. Γ (capital Gammma): A set of stack alphabet.
4. (delta): A transition function represents the set of
transitions that moves PDA to the next states.
: Q x Σ x Γ →Q.
5. q0 Q : start state.
6. F ⊆ Q is the set of final states.
ε Γ and Σ : start symbol for the stack and end symbol
for the Input Tape.

 
 FA = “a 5-tuple “ (Q, Σ, , q0, F)
1. Q: {q0, q1, q2, …} is set of states.
2. Σ: {a, b, …} set of alphabet.
3. (delta): represents the set of transitions that
FA can take between its states.
: Q x Σ→Q
4. q0 Q is the start state.
5. F Q is the set of final/accepting states.
Dr. Hussien M. Sharaf
Remember and compare FA


5
PDA as a deterministic machine
Its inputs are
1. The current state (of its “NFA”),
2. The current input symbol (or Λ),
and
3. The current symbol on top of its
stack.
Dr. Hussien M. Sharaf 6
1
4
3
2
Its actions are:
1. Change state.
2. Change stack if needed.
Power of PDA
Dr. Hussien M. Sharaf 7
Ex1 P.295 cohen Edition 2:
 Consider the following PDA for anbn
Dr. Hussien M. Sharaf 8
Ex1 P.295:
 Consider the following Input
Dr. Hussien M. Sharaf 9
Δ
a a
Input Tape
a b b b Δ
Start
ReadPush Δa
b
Ex1 P.295:
 Consider the following PDA
Dr. Hussien M. Sharaf 10
a
a a
Input Tape
a b b b Δ
Start
ReadPush Δa
b
Δ
Ex1 P.295:
 Consider the following PDA
Dr. Hussien M. Sharaf 11
a
a a
Input Tape
a b b b Δ
Start
ReadPush Δa
b
Δ
a
a
Ex1 P.295:
 Consider the following PDA
Dr. Hussien M. Sharaf 12
a
a a
Input Tape
a b b b Δ
POP ab, Δ
a
Δ
a
Read Δ
b b
Reject
Reject
Ex1 P.295:
 Consider the following PDA
Dr. Hussien M. Sharaf 13
a
a a
Input Tape
a b b b Δ
POP ab, Δ
a
Δ
Read Δ
b b
Reject
Reject
Ex1 P.295:
 Consider the following PDA
Dr. Hussien M. Sharaf 14
a a
Input Tape
a b b b Δ
POP ab, Δ
a
Δ
Read Δ
b b
Reject
Reject
Ex1 P.295:
 Consider the following PDA
Dr. Hussien M. Sharaf 15
a a
Input Tape
a b b b Δ
Read Δ Pop a,b
Accept
Δ
Reject
Ex2: Even Palindrome P.304
 Can you list samples of words in even palindrome?
Dr. Hussien M. Sharaf 16
PUSH a READ2READ1
POP3
POP2
POP1
START
ACCEPT
PUSH b
a
b
a
a
a
b b
b
Δ
Δ
Δ
Ex2: Even Palindrome
Dr. Hussien M. Sharaf 17
 Consider babbab
Ex2: Even Palindrome
Dr. Hussien M. Sharaf 18
 Jump to the right part
Ex2: Even Palindrome
Dr. Hussien M. Sharaf 19
 We have just read first many blanks on the TAPE
Assignment #5
 Read Example P.308 in Cohen’s book and hand in a
stack table for input 4
* 4 + 4.
 The assignment must be hand written.
Dr. Hussien M. Sharaf 20
PDA for Balanced strings
State diagram for
L = {0n 1n | n >= 0}
Dr. Hussien M. Sharaf 21
0,ε
0
q4
q1
(delta) is shown in
the state diagram
"ε“ or “Λ” means ignore or don’t
care for both input and stack.
$ means end for both input or
stack
q3
q2
0,0
0
1,0
pop
1,0
pop$ , $
no Action
$ , $
no Action
Thank you
Dr. Hussien M. Sharaf 22

More Related Content

What's hot

8 queens problem using back tracking
8 queens problem using back tracking8 queens problem using back tracking
8 queens problem using back tracking
Tech_MX
 
02. chapter 3 lexical analysis
02. chapter 3   lexical analysis02. chapter 3   lexical analysis
02. chapter 3 lexical analysis
raosir123
 

What's hot (20)

Automata theory - Push Down Automata (PDA)
Automata theory - Push Down Automata (PDA)Automata theory - Push Down Automata (PDA)
Automata theory - Push Down Automata (PDA)
 
Input-Buffering
Input-BufferingInput-Buffering
Input-Buffering
 
Chomsky Normal Form
Chomsky Normal FormChomsky Normal Form
Chomsky Normal Form
 
push down automata
push down automatapush down automata
push down automata
 
Finite Automata
Finite AutomataFinite Automata
Finite Automata
 
8 queens problem using back tracking
8 queens problem using back tracking8 queens problem using back tracking
8 queens problem using back tracking
 
Lecture Notes-Finite State Automata for NLP.pdf
Lecture Notes-Finite State Automata for NLP.pdfLecture Notes-Finite State Automata for NLP.pdf
Lecture Notes-Finite State Automata for NLP.pdf
 
Peephole Optimization
Peephole OptimizationPeephole Optimization
Peephole Optimization
 
Lecture 6
Lecture 6Lecture 6
Lecture 6
 
Context free grammar
Context free grammar Context free grammar
Context free grammar
 
02. chapter 3 lexical analysis
02. chapter 3   lexical analysis02. chapter 3   lexical analysis
02. chapter 3 lexical analysis
 
Pumping lemma for cfl
Pumping lemma for cflPumping lemma for cfl
Pumping lemma for cfl
 
Context free languages
Context free languagesContext free languages
Context free languages
 
Lecture 7
Lecture 7Lecture 7
Lecture 7
 
Regular Expression in Compiler design
Regular Expression in Compiler designRegular Expression in Compiler design
Regular Expression in Compiler design
 
Finite automata-for-lexical-analysis
Finite automata-for-lexical-analysisFinite automata-for-lexical-analysis
Finite automata-for-lexical-analysis
 
Theory of computation / Post’s Correspondence Problems (PCP)
Theory of computation / Post’s Correspondence Problems (PCP)Theory of computation / Post’s Correspondence Problems (PCP)
Theory of computation / Post’s Correspondence Problems (PCP)
 
Pumping lemma for regular language
Pumping lemma for regular languagePumping lemma for regular language
Pumping lemma for regular language
 
Parse Tree
Parse TreeParse Tree
Parse Tree
 
Lecture: Regular Expressions and Regular Languages
Lecture: Regular Expressions and Regular LanguagesLecture: Regular Expressions and Regular Languages
Lecture: Regular Expressions and Regular Languages
 

More from Arab Open University and Cairo University

More from Arab Open University and Cairo University (20)

Infos2014
Infos2014Infos2014
Infos2014
 
File Organization & processing Mid term summer 2014 - modelanswer
File Organization & processing Mid term summer 2014 - modelanswerFile Organization & processing Mid term summer 2014 - modelanswer
File Organization & processing Mid term summer 2014 - modelanswer
 
Model answer of compilers june spring 2013
Model answer of compilers june spring 2013Model answer of compilers june spring 2013
Model answer of compilers june spring 2013
 
Model answer of exam TC_spring 2013
Model answer of exam TC_spring 2013Model answer of exam TC_spring 2013
Model answer of exam TC_spring 2013
 
Theory of computation Lec6
Theory of computation Lec6Theory of computation Lec6
Theory of computation Lec6
 
Lec4
Lec4Lec4
Lec4
 
Theory of computation Lec3 dfa
Theory of computation Lec3 dfaTheory of computation Lec3 dfa
Theory of computation Lec3 dfa
 
Theory of computation Lec1
Theory of computation Lec1Theory of computation Lec1
Theory of computation Lec1
 
Setup python with eclipse
Setup python with eclipseSetup python with eclipse
Setup python with eclipse
 
Cs419 lec8 top-down parsing
Cs419 lec8    top-down parsingCs419 lec8    top-down parsing
Cs419 lec8 top-down parsing
 
Cs419 lec11 bottom-up parsing
Cs419 lec11   bottom-up parsingCs419 lec11   bottom-up parsing
Cs419 lec11 bottom-up parsing
 
Cs419 lec12 semantic analyzer
Cs419 lec12  semantic analyzerCs419 lec12  semantic analyzer
Cs419 lec12 semantic analyzer
 
Cs419 lec9 constructing parsing table ll1
Cs419 lec9   constructing parsing table ll1Cs419 lec9   constructing parsing table ll1
Cs419 lec9 constructing parsing table ll1
 
Cs419 lec10 left recursion and left factoring
Cs419 lec10   left recursion and left factoringCs419 lec10   left recursion and left factoring
Cs419 lec10 left recursion and left factoring
 
Cs419 lec7 cfg
Cs419 lec7   cfgCs419 lec7   cfg
Cs419 lec7 cfg
 
Cs419 lec6 lexical analysis using nfa
Cs419 lec6   lexical analysis using nfaCs419 lec6   lexical analysis using nfa
Cs419 lec6 lexical analysis using nfa
 
Cs419 lec5 lexical analysis using dfa
Cs419 lec5   lexical analysis using dfaCs419 lec5   lexical analysis using dfa
Cs419 lec5 lexical analysis using dfa
 
Cs419 lec4 lexical analysis using re
Cs419 lec4   lexical analysis using reCs419 lec4   lexical analysis using re
Cs419 lec4 lexical analysis using re
 
Cs419 lec3 lexical analysis using re
Cs419 lec3   lexical analysis using reCs419 lec3   lexical analysis using re
Cs419 lec3 lexical analysis using re
 
Compilers Final spring 2013 model answer
 Compilers Final spring 2013 model answer Compilers Final spring 2013 model answer
Compilers Final spring 2013 model answer
 

Recently uploaded

Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
ciinovamais
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
heathfieldcps1
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
negromaestrong
 

Recently uploaded (20)

SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Asian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptxAsian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptx
 
Third Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptxThird Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptx
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
Dyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxDyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptx
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 

Theory of computation Lec7 pda

  • 1. Dr. Hussien Sharaf Computer Science Department dr.sharaf@from-masr.com
  • 2. p.434: Regular Languages and non- regular languages Dr. Hussien M. Sharaf 2 Language Defined by Corresponding Accepting Machine Nondeter- minism= Determinism Language Closed Under What Can Be Decided? Examples of Applications Regular expression Finite automaton, transition graph Yes Union,productKl eene star, intersection, complement Equivalence, emptiness, finiteness, membership Text editors, sequential circuits, verification Context- free grammar Pushdown automaton No Union, product, Kleene star Emptiness, finiteness, membership Parsing, compilers Type 0 grammar Turing machine, Post machine, Pushdown automaton Yes Union, product, Kleene star Not much Computers
  • 3. PDA  A Pushdown Automata (PDA ) is a DFA equipped with a single stack. Dr. Hussien M. Sharaf 3 1 4 3 2 1 2 3 4 Input Tape Tape cells
  • 4. PDA Dr. Hussien M. Sharaf 4 1. Q : A finite set of states (Q). 2. Σ : A set of input alphabet. 3. Γ (capital Gammma): A set of stack alphabet. 4. (delta): A transition function represents the set of transitions that moves PDA to the next states. : Q x Σ x Γ →Q. 5. q0 Q : start state. 6. F ⊆ Q is the set of final states. ε Γ and Σ : start symbol for the stack and end symbol for the Input Tape.   
  • 5.  FA = “a 5-tuple “ (Q, Σ, , q0, F) 1. Q: {q0, q1, q2, …} is set of states. 2. Σ: {a, b, …} set of alphabet. 3. (delta): represents the set of transitions that FA can take between its states. : Q x Σ→Q 4. q0 Q is the start state. 5. F Q is the set of final/accepting states. Dr. Hussien M. Sharaf Remember and compare FA   5
  • 6. PDA as a deterministic machine Its inputs are 1. The current state (of its “NFA”), 2. The current input symbol (or Λ), and 3. The current symbol on top of its stack. Dr. Hussien M. Sharaf 6 1 4 3 2 Its actions are: 1. Change state. 2. Change stack if needed.
  • 7. Power of PDA Dr. Hussien M. Sharaf 7
  • 8. Ex1 P.295 cohen Edition 2:  Consider the following PDA for anbn Dr. Hussien M. Sharaf 8
  • 9. Ex1 P.295:  Consider the following Input Dr. Hussien M. Sharaf 9 Δ a a Input Tape a b b b Δ Start ReadPush Δa b
  • 10. Ex1 P.295:  Consider the following PDA Dr. Hussien M. Sharaf 10 a a a Input Tape a b b b Δ Start ReadPush Δa b Δ
  • 11. Ex1 P.295:  Consider the following PDA Dr. Hussien M. Sharaf 11 a a a Input Tape a b b b Δ Start ReadPush Δa b Δ a a
  • 12. Ex1 P.295:  Consider the following PDA Dr. Hussien M. Sharaf 12 a a a Input Tape a b b b Δ POP ab, Δ a Δ a Read Δ b b Reject Reject
  • 13. Ex1 P.295:  Consider the following PDA Dr. Hussien M. Sharaf 13 a a a Input Tape a b b b Δ POP ab, Δ a Δ Read Δ b b Reject Reject
  • 14. Ex1 P.295:  Consider the following PDA Dr. Hussien M. Sharaf 14 a a Input Tape a b b b Δ POP ab, Δ a Δ Read Δ b b Reject Reject
  • 15. Ex1 P.295:  Consider the following PDA Dr. Hussien M. Sharaf 15 a a Input Tape a b b b Δ Read Δ Pop a,b Accept Δ Reject
  • 16. Ex2: Even Palindrome P.304  Can you list samples of words in even palindrome? Dr. Hussien M. Sharaf 16 PUSH a READ2READ1 POP3 POP2 POP1 START ACCEPT PUSH b a b a a a b b b Δ Δ Δ
  • 17. Ex2: Even Palindrome Dr. Hussien M. Sharaf 17  Consider babbab
  • 18. Ex2: Even Palindrome Dr. Hussien M. Sharaf 18  Jump to the right part
  • 19. Ex2: Even Palindrome Dr. Hussien M. Sharaf 19  We have just read first many blanks on the TAPE
  • 20. Assignment #5  Read Example P.308 in Cohen’s book and hand in a stack table for input 4 * 4 + 4.  The assignment must be hand written. Dr. Hussien M. Sharaf 20
  • 21. PDA for Balanced strings State diagram for L = {0n 1n | n >= 0} Dr. Hussien M. Sharaf 21 0,ε 0 q4 q1 (delta) is shown in the state diagram "ε“ or “Λ” means ignore or don’t care for both input and stack. $ means end for both input or stack q3 q2 0,0 0 1,0 pop 1,0 pop$ , $ no Action $ , $ no Action
  • 22. Thank you Dr. Hussien M. Sharaf 22