Code360 powered by Coding Ninjas X Naukri.com. Code360 powered by Coding Ninjas X Naukri.com
Table of contents
1.
Introduction
2.
PDA Components:
3.
How language can be accepted using PDA
4.
Final State Acceptability
5.
Empty State Acceptability
5.1.
Example 1
5.2.
Example 2
6.
Frequently Asked Questions
6.1.
What type of language is accepted by pushdown automata?
6.2.
What are the approaches used by the PDA to accept a language?
6.3.
What are the types of PushDown automata?
7.
Conclusion
Last Updated: Aug 31, 2024

Introduction to Pushdown Automata

Theory of Computation

Introduction

A pushdown automaton (PDA) is a computational model that recognizes context-free languages. It consists of an input tape, a stack, and a finite set of states. The PDA transitions between states based on input symbols and stack operations, which allows it to parse and validate strings generated by context-free grammars. In this article, we will discuss pushdown automata in detail.

A Pushdown Automata (PDA) can be defined as :

  • Q is the set of states
  • ∑is the set of input symbols
  • Γ is the set of pushdown symbols (which can be pushed and popped from stack)
  • q0 is the initial state
  • Z is the initial pushdown symbol (which is initially present in the stack)
  • F is the set of final states

 Also See, Moore Machine

PDA Components:

 

1. Input Tape:
  - A read-only tape that contains the input string to be processed by the PDA.
  - The input string is a sequence of symbols from the input alphabet.
  - The PDA reads the input string from left to right, one symbol at a time.

2. Stack:
  - A last-in-first-out (LIFO) data structure used for storing and manipulating symbols.
  - The stack has an alphabet of stack symbols, which can be pushed onto or popped from the top of the stack.
  - The stack is used to store information and make decisions based on the stored information.

3. States:
  - A finite set of states that represent the different configurations of the PDA.
  - The PDA transitions between states based on the current input symbol and the top symbol of the stack.
  - There is a designated start state where the PDA begins its computation.
  - There are also one or more final states (also called accept states) that indicate successful processing of the input string.

4. Transition Function:
  - A set of rules that define how the PDA moves from one state to another based on the current input symbol and the top symbol of the stack.
  - The transition function specifies the next state, the symbol to be pushed onto the stack (if any), and the symbol to be popped from the stack (if any).
  - The transition function can be represented as a transition table or a set of transition rules.

5. Input Alphabet:
  - A finite set of symbols that the input string can consist of.
  - The input alphabet is used to define the valid symbols that can appear on the input tape.

6. Stack Alphabet:
  - A finite set of symbols that can be stored on the stack.
  - The stack alphabet includes a special symbol (usually denoted as Z) that represents the bottom of the stack.

7. Acceptance Condition:
  - The criteria that determine whether the PDA accepts or rejects an input string.
  - The PDA accepts an input string if it reaches a final state after consuming all the input symbols and the stack is empty.
  - If the PDA cannot reach a final state or the stack is not empty after consuming all the input symbols, the input string is rejected.

How language can be accepted using PDA

  • Final State Acceptability
  • Empty State Acceptability

Final State Acceptability

We will discuss how PDA is accepted using the final state.

Let G =(Q, ∑, Γ, δ, q0, Z, F) be a PDA.

The language accepted by P is the set of all strings, acceptable by the final state for any input stack string x can be depicted as follows:

L(PDA) = {w | (q0, w, Z) ⊢* (p, ε, ε), q ∈ F} 

Empty State Acceptability

Over reading the input string from the initial for some PDA, the stack of PDA gets empty.

For a PDA, G= (Q, ∑, S, δ, q0, I, F), the language accepted by the empty stack will be as follows:

L(PDA) = {w | (q0, w, I) ⊢* (q, ε, ε), q ∈ Q}

Example 1

We have to construct a PDA that accepts L = { wwR | w = (a+b)* }

Solution

PDA for L1

 

Initially, we will insert a special symbol '$' into the empty stack. At the state q2, the w is being read. In-state q3, each 0 or 1 is popped when it matches the input. The PDA will go into the dead state if any other input is given. When we reach the inserted special symbol '$,' we go to the accepting state q4.

Example 2

We have to construct a PDA that accepts L = {0n 1n | n ≥ 0}

Solution

PDA for L

 

This language accepts L = {ε, 01, 0011, 000111, ............................. }

In the above example, the number of 'a' and 'b' must be identical.

  • Initially, we will insert a special symbol, '$,' in the empty stack.
  • At the state q2, if we encounter input 0 and the top is Null, we push 0 into the stack. This may iterate. And if we encounter input 1 and the top is 0, we pop this 0.
  • At state q3, by chance, we encounter input 1, and the top is 0. We pop this 0. This may also iterate. And if we encounter input 1 and the top is 0, we pop the top element.
  • If the special symbol '$' is encountered at the top of the stack, it is popped out, finally going to the accepting state q4.
     

Also see, Turing Machine in TOC.

Frequently Asked Questions

What type of language is accepted by pushdown automata?

Pushdown automata are used for context-free languages, i.e., languages in which the length of elements is unrestricted, and one element's length is related to the other.

What are the approaches used by the PDA to accept a language?

Two approaches are using which a language can be accepted.

  • Acceptance by final state
  • Acceptance by empty stack

What are the types of PushDown automata?

  • Decider
  • Turing Machine
  • Linear Bounded
  • Nested stack
  • Embedded pushdown

Conclusion

In this article, we talked about pushdown automata (PDA), a computational model that recognizes context-free languages. We discussed its components, including the input tape, stack, states, transition function, and acceptance condition, which together enable the PDA to process input strings and determine their validity based on a given context-free grammar.

Recommended Readings:

Do check out The Interview guide for Product Based Companies as well as some of the Popular Interview Problems from Top companies like Amazon, Adobe, Google, etc. on Code 360.

Also check out some of the Guided Paths on topics such as Data Structure and Algorithms, Competitive Programming, Operating Systems, etc. as well as some Contests, Test Series, Interview Bundles, and some Interview Experiences curated by top Industry Experts only on Code 360

Live masterclass