Document Details

StylishSpessartine

Uploaded by StylishSpessartine

University of Science and Technology

2023

Tags

pushdown automata theory of computation computer science

Full Transcript

**University of Science and Technology** **Faculty of Computer Science and Information Technology** [Computer Science Department] Subject: Theory of Computation Lecture (11) Instructor: Prof. Noureldien Abdelrahman Date 18-1-2023 **How PDA Works** A PDA is more powerful than FA. Any language...

**University of Science and Technology** **Faculty of Computer Science and Information Technology** [Computer Science Department] Subject: Theory of Computation Lecture (11) Instructor: Prof. Noureldien Abdelrahman Date 18-1-2023 **How PDA Works** A PDA is more powerful than FA. Any language which can be acceptable by FA can also be acceptable by PDA. PDA also accepts a class of language which even cannot be accepted by FA. Thus PDA is much more superior to FA. Pushdown Automata **PDA Components:** **Input tape:** The input tape is divided in many cells or symbols. The input head is read-only and may only move from left to right, one symbol at a time. **Finite control:** The finite control has some pointer which points to the current symbol which is to be read. **Stack:** The stack is a structure in which we can push and remove the items from one end only. It has an infinite size. In PDA, the stack is used to store the items temporarily. **Formal Definition of PDA:** The PDA can be defined as a collection of 7 components: **Q:** the finite set of states **∑:** the input set **Γ:** a stack symbol which can be pushed and popped from the stack **q0:** the initial state **Z:** a start symbol which is in Γ. **F:** a set of final states **δ:** mapping function which is used for moving from current state to next state. **Instantaneous Description (ID)** **[ID is an informal notation of how a PDA computes an input string and make a decision that string is accepted or rejected.]** **An instantaneous description is a triple (q, w, α) where:** **q**: describes the current state. **w**: describes the remaining input. **α**: describes the stack contents, top at the left. **Notation:** ⊢ sign describes and represents one move. ⊢\* sign describes a sequence of moves. **For example,** (p, b, T) ⊢ (q, w, α) In the above example, while taking a **[transition from state p to q]**, the input **[symbol \'b\' is consumed]**, and the top of the **[stack \'T\' is represented by a new string α.]** Example 1: Design a PDA for accepting a language {a^n^b^2n^ \| n\>=1}. **Solution:** In this language, [n number of a\'s should be followed by 2n number of b\'s.] Hence, we will apply a very simple logic, and that is if we [read single \'a\', we will push two a\'s onto the stack. As soon as we read \'b\' then for every single \'b\' only one \'a\' should get popped from the stack.] The ID can be constructed as follows: **When we read a** 1. δ(q0, a, Z) = (q0, aaZ)   2. δ(q0, a, a) = (q0, aaa)   Now when we **[read b, we will change the state from q0 to q1 and start popping corresponding \'a\'.]** Hence, 1\. δ(q0, b, a) = (q1, ε)   Thus this process of popping a on reading \'b\' will be repeated unless all the symbols are read. The **[popping action occurs in state q1]** only. 2\. δ(q1, b, a) = (q1, ε)   After reading all b\'s, all the corresponding a\'s should get popped. Hence when we read ε as input symbol (that denote the end of the input) then there should be nothing in the stack. Hence the move will be: 3\. δ(q1, ε, Z) = (q2, ε)   Where PDA = ({q0, q1, q2}, {a, b}, {a, Z}, δ, q0, Z, {q2}) We can summarize the ID as: 1. δ(q0, a, Z) = (q0, aaZ)   2. δ(q0, a, a) = (q0, aaa)   3. δ(q0, b, a) = (q1, ε)   4. δ(q1, b, a) = (q1, ε)   5. δ(q1, ε, Z) = (q2, ε)   Now we will simulate this PDA for the input string \"aaabbbbbb\". 1. δ(q0, aaabbbbbb, Z) ⊢ δ(q0, aabbbbbb, aaZ)   2.                     ⊢ δ(q0, abbbbbb, aaaaZ)   3.                     ⊢ δ(q0, bbbbbb, aaaaaaZ)   4.                     ⊢ δ(q1, bbbbb, aaaaaZ)   5.                     ⊢ δ(q1, bbbb, aaaaZ)   6.                     ⊢ δ(q1, bbb, aaaZ)   7.                     ⊢ δ(q1, bb, aaZ)   8.                     ⊢ δ(q1, b, aZ)   9.                     ⊢ δ(q1, ε, Z)   10.                     ⊢ δ(q2, ε)         11.                       ACCEPT   **Example 2:** Design a PDA for accepting a language {0^n^1^m^0^n^ \| m, n\>=1}. **Solution:** In this PDA, n number of 0\'s are followed by any number of 1\'s followed by n number of 0\'s. Hence the logic for design of such PDA will be as follows: Push all 0\'s onto the stack on encountering first 0\'s. Then if we read 1, just do nothing. Then when we start reading 0, on each read of 0, pop one 0 from the stack. **For instance:** ![Pushdown Automata](media/image2.png) **This scenario can be written in the ID form as:** 1. δ(q0, 0, Z) = δ(q0, 0Z)   2. δ(q0, 0, 0) = δ(q0, 00)   3. δ(q0, 1, 0) = δ(q1, 0)   4. δ(q0, 1, 0) = δ(q1, 0)   5. δ(q1, 0, 0) = δ(q1, ε)   6. δ(q0, ε, Z) = δ(q2, Z)      (ACCEPT state)   Now we will simulate this PDA for the input string \"0011100\". 1. δ(q0, 0011100, Z) ⊢ δ(q0, 011100, 0Z)   2.                   ⊢ δ(q0, 11100, 00Z)   3.                   ⊢ δ(q0, 1100, 00Z)   4.                   ⊢ δ(q1, 100, 00Z)   5.                   ⊢ δ(q1, 00, 00Z)   6.                   ⊢ δ(q1, 0, 0Z)   7.                   ⊢ δ(q1, ε, Z)   8.                   ⊢ δ(q2, Z)   9.                     ACCEPT  **PDA Acceptance** A language can be accepted by Pushdown automata using two approaches: **1. Acceptance by Final State:** The PDA is said to accept its input by the final state if it **[enters any final state]** in zero or more moves after reading the entire input. Let P =(Q, ∑, Γ, δ, q0, Z, F) be a PDA. The language acceptable by the final state can be defined as: 1. L(PDA) = {w \| (q0, w, Z) ⊢\* (p, ε, ε), q ∈ F}   **2. Acceptance by Empty Stack:** On reading the input string from the initial configuration for some **PDA, the stack of PDA gets empty** **Example:** Construct a PDA that accepts the language L over {0, 1} by empty stack which accepts all the string of 0\'s and 1\'s in which a number of 0\'s are twice of number of 1\'s. **Solution:** There are two parts for designing this PDA: - If 1 comes before any 0\'s - If 0 comes before any 1\'s. We are going to design the first part i.e. 1 comes before 0\'s. The logic is that read single 1 and push two 1\'s onto the stack. Thereafter on reading two 0\'s, POP two 1\'s from the stack. The δ can be 1. δ(q0, 1, Z) = (q0, 11, Z)        Here Z represents that stack is empty   2. δ(q0, 0, 1) = (q0, ε)   Now, consider the second part i.e. if 0 comes before 1\'s. The logic is that read first 0, push it onto the stack and change state from q0 to q1. \[Note that state q1 indicates **that first 0 is read and still second 0 has yet** to read\]. Being in q1, if 1 is encountered then POP 0. Being in q1, if 0 is read then simply read that second 0 and move without doing anything. The δ will be: 1. δ(q0, 0, Z) = (q1, 0Z)   2.  δ(q1, 0, 0) = (q1, 0)   3. δ(q1, 0, Z) = (q0, ε)        (indicate that one 0 and one 1 is already read, so simply read the second 0)   4. δ(q1, 1, 0) = (q1, ε)   Now, summarize the complete PDA for given L is: 1. δ(q0, 1, Z) = (q0, 11Z)   2. δ(q0, 0, 1) = (q1, ε)   3. δ(q0, 0, Z) = (q1, 0Z)   4. δ(q1, 0, 0) = (q1, 0)   5. δ(q1, 0, Z) = (q0, ε)   6. δ(q0, ε, Z) = (q0, ε)      ACCEPT state  

Use Quizgecko on...
Browser
Browser