Principles of Computing – UFCFA3-30-1

Slides:



Advertisements
Similar presentations
STACKS & QUEUES. Stacks Abstract data types An abstract data type (ADT) is an abstraction of a data structure An ADT specifies : –Data stored –Operations.
Advertisements

Data Structure HKOI training /4/2010 So Pak Yeung.
Pushdown Automata Section 2.2 CSC 4170 Theory of Computation.
Pushdown Automata Chapter 12. Recognizing Context-Free Languages We need a device similar to an FSM except that it needs more power. The insight: Precisely.
Stacks, Queues, and Deques. 2 A stack is a last in, first out (LIFO) data structure Items are removed from a stack in the reverse order from the way they.
ADT Stacks and Queues. Stack: Logical Level “An ordered group of homogeneous items or elements in which items are added and removed from only one end.”
Queue Overview Queue ADT Basic operations of queue
Stack and Queue COMP171 Fall Stack and Queue / Slide 2 Stack Overview * Stack ADT * Basic operations of stack n Pushing, popping etc. * Implementations.
Data Structures & Algorithms
Costas Busch - RPI1 Pushdown Automata PDAs. Costas Busch - RPI2 Pushdown Automaton -- PDA Input String Stack States.
1 … NPDAs continued. 2 Pushing Strings Input symbol Pop symbol Push string.
Courtesy Costas Busch - RPI1 Pushdown Automata PDAs.
Stacks and Queues COMP171 Fall Stack and Queue / Slide 2 Stack Overview * Stack ADT * Basic operations of stack n Pushing, popping etc. * Implementations.
1 Normal Forms for Context-free Grammars. 2 Chomsky Normal Form All productions have form: variable and terminal.
CS 106 Introduction to Computer Science I 12 / 11 / 2006 Instructor: Michael Eckmann.
Fall 2004COMP 3351 Pushdown Automata PDAs. Fall 2004COMP 3352 Pushdown Automaton -- PDA Input String Stack States.
Fall 2006Costas Busch - RPI1 Pushdown Automata PDAs.
CS 206 Introduction to Computer Science II 10 / 26 / 2009 Instructor: Michael Eckmann.
1 Normal Forms for Context-free Grammars. 2 Chomsky Normal Form All productions have form: variable and terminal.
Prof. Busch - LSU1 Pushdown Automata PDAs. Prof. Busch - LSU2 Pushdown Automaton -- PDA Input String Stack States.
CS 106 Introduction to Computer Science I 12 / 13 / 2006 Instructor: Michael Eckmann.
Fall 2005Costas Busch - RPI1 Pushdown Automata PDAs.
1 Pushdown Automata PDAs. 2 Pushdown Automaton -- PDA Input String Stack States.
ADT Stacks and Queues. Stack: Logical Level “An ordered group of homogeneous items or elements in which items are added and removed from only one end.”
Objectives of these slides:
Lecture Pushdown Automata. stack stack head finite control tape head tape.
Stack Overview. Stack Stack ADT Basic operations of stack – Pushing, popping etc. Implementations of stacks using – array – linked list.
Stacks And Queues Chapter 18.
1 Linked-list, stack and queue. 2 Outline Abstract Data Type (ADT)‏ Linked list Stack Queue.
PushDown Automata. What is a stack? A stack is a Last In First Out data structure where I only have access to the last element inserted in the stack.
Computer Engineering Rabie A. Ramadan Lecture 6.
Stacks and Queues CMSC 201. Stacks and Queues Sometimes, when we use a data-structure in a very specific way, we have a special name for it. This is to.
CS 154 Formal Languages and Computability March 15 Class Meeting Department of Computer Science San Jose State University Spring 2016 Instructor: Ron Mak.
Pushdown Automata - like NFA-  but also has a stack - transition takes the current state, the current input symbol, and the top-of-the-stack symbol (which.
Lecture # 21.
STACKS & QUEUES for CLASS XII ( C++).
Formal Languages, Automata and Models of Computation
G.PULLAIAH COLLEGE OF ENGINEERING AND TECHNOLOGY
COSC160: Data Structures: Lists and Queues
September 29 – Stacks and queues
Chapter 15 Lists Objectives
Objectives In this lesson, you will learn to: Define stacks
Stacks and Queues.
Pushdown Automata PDAs
Pushdown Automata PDAs
Pushdown Automata PDAs
Pushdown Automata PDAs
CS 461 – Sept. 28 Section 2.2 – Pushdown Automata { 0n 1n }
Theory of Computation Lecture #27-28.
AUTOMATA THEORY VI.
Pushdown Automata PDAs
Stack and Queue APURBO DATTA.
Introduction to Data Structure
Data Structures and Database Applications Queues in C#
Building Java Programs
i206: Lecture 11: Stacks, Queues
CMSC 341 Lecture 5 Stacks, Queues
i206: Lecture 10: Lists, Stacks, Queues
Data Structures and Database Applications Stacks in C#
Stacks and Queues.
Principles of Computing – UFCFA3-30-1
Stacks and Queues CLRS, Section 10.1.
Principles of Computing – UFCFA3-30-1
… NPDAs continued.
17CS1102 DATA STRUCTURES © 2016 KL University – The contents of this presentation are an intellectual and copyrighted property of KL University. ALL RIGHTS.
Stacks, Queues, and Deques
More About Nondeterminism
Stacks and Queues.
Normal Forms for Context-free Grammars
Presentation transcript:

Principles of Computing – UFCFA3-30-1 Week-7 Pushdown Automata Instructor : Mazhar H Malik Email : mazhar@gcet.edu.om Global College of Engineering and Technology

Stack and Queue

Stack Overview Stack Basic operations of stack Pushing, popping etc. Implementations of stacks using array linked list

The Stack A stack is a list with the restriction that insertions and deletions can only be performed at the top of the list The other end is called bottom Fundamental operations: Push: Equivalent to an insert Pop: Deletes the most recently inserted element Top: Examines the most recently inserted element

Stack Stacks are less flexible but are more efficient and easy to implement Stacks are known as LIFO (Last In, First Out) lists. The last element inserted will be the first to be retrieved

Push and Pop Primary operations: Push and Pop Push Pop Add an element to the top of the stack Pop Remove the element at the top of the stack empty stack push an element push another pop top B top top A A A top

Implementation of Stacks Any list implementation could be used to implement a stack Arrays (static: the size of stack is given initially) Linked lists (dynamic: never become full) We will explore implementations based on array and linked list Let’s see how to use an array to implement a stack first

Queue Overview Queue Basic operations of queue Implementation of queue Enqueuing, dequeuing etc. Implementation of queue Array Linked list

Queue Like a stack, a queue is also a list. However, with a queue, insertion is done at one end, while deletion is performed at the other end. Accessing the elements of queues follows a First In, First Out (FIFO) order. Like customers standing in a check-out line in a store, the first customer in is the first customer served.

The Queue ADT Another form of restricted list Basic operations: Insertion is done at one end, whereas deletion is performed at the other end Basic operations: enqueue: insert an element at the rear of the list dequeue: delete the element at the front of the list First-in First-out (FIFO) list

Enqueue and Dequeue Primary queue operations: Enqueue and Dequeue Like check-out lines in a store, a queue has a front and a rear. Enqueue Insert an element at the rear of the queue Dequeue Remove an element from the front of the queue Insert (Enqueue) Remove (Dequeue) front rear

Pushdown Automata PDAs

Pushdown Automaton -- PDA Input String Stack States

Stack

Initial Stack Symbol $ Stack Stack stack head top bottom special symbol Appears at time 0

The States Pop symbol Input symbol Push symbol a, b  c q1 q2

  transition , b  c Non-Determinism PDAs are non-deterministic q2 Allowed non-deterministic transitions q2 a, b  c , b  c q1 q1 q2   transition a, b  c q3

PDA M : L(M )  {anbn : n  0} ,    q1 b, a   , $  $ Example PDA PDA M : L(M )  {anbn : n  0} a,   a b, a   ,    q1 b, a   , $  $ q0 q2 q3

L(M )  {anbn : n  0} ,    q1 b, a   , $  $ a,   a b, a   Basic Idea: 1. Push the a’s on the stack Match the b’s on input with a’s on stack Match found a,   a b, a   ,    q1 b, a   , $  $ q0 q2 q3

q0 ,    q1 b, a   , $  $ b $ a,   a b, a   q2 q3 a Time 0 Execution Example: Input Time 0 a b $ Stack current state a,   a b, a   q0 ,    q1 b, a   , $  $ q2 q3

,    b, a   q2 , $  $ b $ a,   a b, a   q0 q1 q3 a Time 1 Input a b $ Stack a,   a b, a   ,    b, a   q2 , $  $ q0 q1 q3

,    b, a   q2 , $  $ b $ a,   a b, a   q0 q1 q3 a a Time 2 Input a b a $ Stack a,   a b, a   ,    b, a   q2 , $  $ q0 q1 q3

,    b, a   q2 , $  $ $ b a,   a b, a   q0 q1 q3 a a a Time 3 Input a a $ Stack a b a,   a b, a   ,    b, a   q2 , $  $ q0 q1 q3

,    b, a   q2 , $  $ b $ a,   a b, a   q0 q1 q3 a a a a Time 4 a a Input a b a $ Stack a,   a b, a   ,    b, a   q2 , $  $ q0 q1 q3

,    q1 b, a   , $  $ b $ a,   a b, a   q0 q2 q3 a a a a Time 5 a a a Input a b $ Stack a,   a b, a   ,    q1 b, a   , $  $ q0 q2 q3

,    q1 b, a   , $  $ $ b a,   a b, a   q0 q2 q3 a a a Time 6 Input a a $ Stack a b a,   a b, a   ,    q1 b, a   , $  $ q0 q2 q3

,    q1 b, a   , $  $ $ b a,   a b, a   q0 q2 q3 a a Time 7 Input a $ Stack a b a,   a b, a   ,    q1 b, a   , $  $ q0 q2 q3

,    q1 b, a   , $  $ b $ a,   a b, a   q0 q2 q3 a Time 8 Input a b $ Stack a,   a b, a   accept ,    q1 b, a   , $  $ q0 q2 q3

A string is accepted if there is a computation such that: All the input is consumed AND The last state is an accepting state we do not care about the stack contents at the end of the accepting computation

q0 ,    q1 b, a   , $  $ b $ a,   a b, a   q2 q3 a Time 0 Rejection Example: Input Time 0 a b $ Stack current state a,   a b, a   q0 ,    q1 b, a   , $  $ q2 q3

q0 ,    q1 b, a   , $  $ b $ a,   a b, a   q2 q3 a Time 1 Rejection Example: Input Time 1 a b $ Stack current state a,   a b, a   q0 ,    q1 b, a   , $  $ q2 q3

q0 ,    q1 b, a   , $  $ $ b a,   a b, a   q2 q3 a a Rejection Example: Input Time 2 a $ Stack a b current state a,   a b, a   q0 ,    q1 b, a   , $  $ q2 q3

q0 ,    q1 b, a   , $  $ b $ a,   a b, a   q2 q3 a a a Rejection Example: Input Time 3 a a a b $ Stack current state a,   a b, a   q0 ,    q1 b, a   , $  $ q2 q3

q0 ,    q1 b, a   , $  $ b $ a,   a b, a   q2 q3 a a a Rejection Example: Input Time 4 a a a b $ Stack current state a,   a b, a   q0 ,    q1 b, a   , $  $ q2 q3

q0 ,    q1 b, a   , $  $ b $ reject b, a   a,   a q2 q3 Rejection Example: Input Time 4 a a a b $ Stack reject b, a   current state a,   a q0 ,    q1 b, a   , $  $ q2 q3

There is no accepting computation for aab The string aab is rejected by the PDA a,   a b, a   ,    q1 b, a   , $  $ q0 q2 q3

With Empty Input

With Empty Input

With Input (aaabbb) a b

With Input (aaabbb) a b

With Input (aaabbb) a b

With Input (aaabbb) a b

With Input (aaabbb) a b

With Input (aaabbb) a b

With Input (aaabbb) a b

With Input (aaabbb) a b

With Input (aaabbb) a b

With Input (aaabbb) a b

constructing a deterministic NPDA for the language L = {anbn : n > 0}.