Pushdown Automata

Introduction

Pushdown automata (in short PDA) is the machine format of the context-free language. It is the same as finite automata with the attachment of an auxiliary amount of storage as stack. Already, we have discussed the limitations of finite automata. Pushdown automata is designed to remove those limitations. Remember the example of a n b n , which is not recognizable by the finite automata due to the limitation of memory, but pushdown automata can memorize the number of occurrences of ‘a’ and match it with the number of occurrences of ‘b’ with the help of the stack. In this chapter, we shall learn about the mathematical representation of PDA, acceptance by a PDA, deterministic PDA, non-deterministic PDA, conversion of CFG to PDA and PDA to CFG, and the graphical representation of PDA.

7.1  Basics of PDA

7.1.1  Definition

A PDA consists of a 7-tuple

M = (Q, Σ, Γ, δ, q 0 , z 0 , F)

where

    Q denotes a finite set of states.

    Σ denotes a finite set of input symbols.

    Γ denotes a finite set of pushdown symbols or stack symbols.

    δ denotes the transitional functions.

    q 0 is the initial state of the PDA (q 0 ∈ Q).

    z 0 is the stack bottom symbol.

    F is the final state of the PDA.

In PDA, the transitional function δ is in the form

Q × (Σ ∪ {λ}) × Γ → (Q, Γ)

(The PDA is in some state. With an input symbol from the input tape and with the stack top symbol, the PDA moves to one right. It may change its state and push some symbol in the stack or pop symbol from the stack top.)

7.1.2.  Mechanical Diagram of the PDA ( Fig. 7.1 )

Fig 7.1

Fig. 7.1

Mechanical diagram of PDA is given in Fig. 7.1 . The components of it are described below.

  • Input tape: The input tape contains the input symbols. The tape is divided into a number of squares. Each square contains a single input character. The string placed in the input tape is traversed from left to right. The two end sides of the input string contain an infinite number of blank symbols.

  • Reading head: The head scans each square in the input tape and reads the input from the tape. The head moves from left to right. The input scanned by the reading head is sent to the finite control of the PDA.

  • Finite control: The finite control can be considered as a control unit of a PDA. An automaton always resides in a state. The reading head scans the input from the input tape and sends it to the finite control. A two-way head is also added with the finite control to the stack top. Depending on the input taken from the input tape and the input from the stack top, the finite control decides in which state the PDA will move and which stack symbol it will push to the stack or pop from the stack or do nothing on the stack.

  • Stack: A stack is a temporary storage of stack symbols. Every move of the PDA indicates one of the following to the stack

    – One stack symbol may be added to the stack (push)

    – One stack symbol may be deleted from the top of the stack (pop)

    The stack is the component of the PDA which differentiates it from the finite automata. In the stack, there is always a symbol z 0 which denotes the bottom of the stack.

7.1.2.1 Why Pushdown?

Push is an operation related to the stack. By this operation, one symbol is added to the stack top.

In finite automata, the states act as a form of primitive memory. The states memorize the nonterminals encountered at the time of derivation of a string. So, only the state is suitable for traversing a regular expression as in the case of finite automata. Now, let us consider a case of L = {a n b n , where n ≥ 1}. It is not a regular expression but a context-free language. Here, n is any number. In the string, there is an equal number of ‘a’ and ‘b’. In the string, all ‘a’s appear before ‘b’. So, the machine for traversing a n b n has to remember n number of a’s to traverse an equal number of ‘b’. n is any number. Thus, to memorize the number of a’s in the string, the machine requires an infinite number of states, i.e., the machine will not be a finite state machine.

To remove this bottleneck, we need to add an auxiliary memory in the form of a stack. For each occurrence of ‘a’ in the string L, one symbol is pushed into the stack. For each occurrence of b (after finishing ‘a’), one symbol will be popped from the stack. By this process, the matching of ‘a’ and ‘b’ will be done.

By adding a stack to the finite automata, the PDA is generated.

7.1.2.2 Instantaneous Description (ID)

It describes the configuration of the PDA at a given instance. ID remembers the information of the state and the stack content at a given instance of time.

An ID is a format of triple (q, w, κ), where q ∈ Q (finite set of states), w ∈ Σ (finite set of input alphabets), and κ ∈ Γ (finite set of stack symbols).

7.2  Acceptance by a PDA

There are two ways to declare a string to be accepted by a PDA:

  1. Accepted by an empty stack (store)
  2. Accepted by the final state

7.2.1.  Accepted by an Empty Stack (Store)

We know in each PDA there is a stack attached. In the stack at the bottom, there is a symbol called the stack bottom symbol, say z 0 . In each move of the PDA, one symbol called the stack symbol is either pushed in or popped from the stack. But the symbol z 0 still remains in the stack.

A string w may be declared accepted by an empty stack after processing all the symbols of w, if the stack is empty after reading the rightmost input character of the string w. In mathematical notation, we can say that if M = {Q, Σ, Γ, δ, q 0 , z 0 , F} is a PDA, the string w is declared accepted by empty stack if

Equation

In general, we can say that a string is accepted by a PDA by empty stack if both the following conditions are fulfilled:

  1. The string is finished (totally traversed)
  2. The stack is empty

7.2.2  Accepted by the Final State

A string w may be declared accepted by the final state if after total traversal of the string w the PDA enters into its final state. In mathematical notation, we can say that if M = {Q, Σ, Γ, δ, q 0 , z 0 , F} is a PDA, the string w is declared accepted by the final state if

Equation

In general, we can say that a string is accepted by a PDA by the final state if both the following conditions are fulfilled:

  1. The string is finished (totally traversed)
  2. The PDA enters into its final state

[Although there are two ways to declare a string to be accepted by a PDA, it can be proved that both the ways are equivalent. In general, for both the cases all the steps are the same, except the last step. In the last step, it is differentiated whether the string is accepted by the empty stack or by the final state.

Equation

Theorem 7.1: A language is accepted by a PDA by the empty stack if and only if the language is accepted by a PDA by the final state.

Proof: Let M 1 = {Q, Σ, Γ, δ, q 0 , z 0 , F} be a PDA. Let it accept a language L by the final state. Let there exist another PDA M 2 , which accepts the same language L by the empty stack.

Equation

The transitional function δ′ is defined as follows:

  1. δ′(q′ 0 , λ, z′ 0 ) contains (q 0 , z 0 z′ 0 )
  2. δ′(q i , a, z) is the same as δ(q i , a, z) for all q i ∈ Q, a ∈ Σ ∪ {λ}, and z ∈ Γ
  3. δ′(q i , λ, z) contains (q e , λ) for q i ∈ F and for all z ∈ Γ ∪ {z′ 0 }
  4. δ′(q e , λ, z) contains (q e , λ) for all z ∈ Γ ∪ {z′ 0 }

[Here (a) describes that M 2 enters in the initial configuration of M 1 with z′ 0 as the leftmost push down symbol. (b) describes to make M 2 simulate the behaviour of M 1 , thus reading an input word w if M 1 reads w and enters a final state. Once w is read and M 2 enters a final state of M 1 , the effect of (c) and (d) are to empty the pushdown store.]

Here, w ∈ M 1 if and only if

Equation

where q f is the final state of the machine M 1 .

By rule (a), we can write

Equation

Conversely, let M 2 = (Q′, Σ′, Γ′, δ′, q′ 0 , z′ 0 , ɸ) be a PDA accepting L by the empty store.

Then,

M 1 = {Q, Σ, Γ, δ, q 0 , z 0 , F}

equation

  1. δ(q 0 , λ, z 0 ) contains (q′ 0 , z 0 , z′ 0) .
  2. δ(q i , a, z) is the same as δ′(q i , a, z) for all q i ∈ Q′, a ∈ Σ ∪ {λ}, and z ∈ Γ′.
  3. δ(q i , λ, z 0 ) contains (q j , z 0 ) for all q i ∈ Q′.

From these two, it can be proved that a language is accepted by a PDA by the empty stack if and only if the language is accepted by a PDA by the final state.

Example 7.1

Construct a PDA to accept a given language L by both the empty stack and the final state where L = (a n b n , where n ≥ 1).

Solution: The string is a n b n where n ≥ 1. The remarks we can draw from the string a n b n , where n ≥ 1, are the following.

  • The string consists of two alphabets ‘a’ and ‘b’.
  • All ‘a’ appear before ‘b’.
  • The number of ‘a’ is equal to the number of ‘b’.
  • There is at least one ‘a’ and one ‘b’ in the string.

We have to check for equal number of ‘a’ and ‘b’. Let us take a stack symbol z 1 , which is pushed into the stack as an ‘a’ is traversed from the input tape. At the beginning, the PDA is in state q 0 and the stack top is z 0 (as at the beginning there is no other symbol in the stack). In this state, it gets an input ‘a’ from the input tape ( the string starts with ‘a’ ). So, a stack symbol z 1 is pushed to the stack. The δ function is

Equation

( At the right hand side, the stack denotes the placement of the symbols. z 1 z 0 denotes that there was z 0 in the stack. Now, the symbol z 1 is pushed into the stack. It is given for better understanding of the placement of the stack symbols. )

From the next input ‘a’ from the input tape, the PDA is in state q 0 and the stack top is z 1 , so another z 1 is pushed into the stack. The δ function is

Equation

By this δ function, all the remaining ‘a’s are traversed. After the end of ‘a’ in the input tape, ‘b’ occurs. When the first ‘b’ occurs on the input tape, at that time the PDA is in state q 0 with the stack top z 1 ( Just before it, the ‘a’s are traversed .). When ‘b’ is traversed, the stack top z 1 will be popped and the PDA will change its state to q 1 . ( So that there will be no chance to push z 1 in the stack if any ‘a’ occurs. The PDA is designed only for string a n b n , but the input string may not be in the form of a n b n . In that case, the string will not be accepted by the PDA. ) The δ function is

δ(q 0 , b, z 1 ) → (q 1 , λ)

When the next ‘b’ appears, the PDA is in state q 1 with the stack top z 1 . That z 1 is popped. The δ function is

δ(q 1 , b, z 1 ) → (q 1 , λ)

By this δ function, all the remaining ‘b’s are traversed.

If the input string is in the form of a n b n , where n ≥ 1, then after traversing the last ‘b’ the PDA will be in state q 1 with the stack top z 0 ( all the other stack symbols are removed ).

If we have to design the PDA accepted by the empty stack, the δ function will be

δ(q 1 , λ, z 0 ) → (q 1 , λ)

If we have to design the PDA accepted by the final state, the δ function will be

δ(q 1 , λ, z 0 ) → (q f , z 0 )

So, the PDA for L = (a n b n , where n ≥ 1) is

Equation

δ is defined as follows:

Equation

Example 7.2

Construct a PDA to accept L = (a, b)* with equal number of ‘a’ and ‘b’, i.e., n a (L) = n b (L) by the empty stack and the final state.

Solution: The string is any combination of ‘a’ and ‘b’ including null and the number of ‘a’ is equal to the number of ‘b’. In the language set, a string may start with ‘a’ or a string may start with ‘b’. ‘a’ can come after ‘a’ or ‘b’ can come after ‘a’, and similarly ‘a’ can come after ‘b’ or ‘b’ can come after ‘b’. If a string starts with ‘a’, then push a stack symbol z 1 in the stack. If a string starts with ‘b’, then push a stack symbol z 2 in the stack. For these two cases, the PDA is in state q 0 . The δ function for these two cases are

Equation

If the string starts with ‘a’ and ‘a’ comes after ‘a’, then the PDA is in state q 0 with the stack top z 1 . Another z 1 will be pushed to the stack. The δ function is

δ(q 0 , a, z 1 ) → (q 0 , z 1 z 1 )

If the string starts with ‘a’ and ‘b’ comes after ‘a’, then one match of ‘a’ and ‘b’ is got and the stack top, i.e., z 1 will be popped from the stack. The δ function is

δ(q 0 , b, z 1 ) → (q 0 , λ)

If the string starts with ‘b’ and ‘b’ comes after ‘b’, then the PDA is in state q 0 with the stack top z 2 . Another z 2 will be pushed to the stack. The δ function is

δ(q 0 , b, z 2 ) → (q 0 , z 2 z 2 )

If the string starts with ‘b’ and ‘a’ comes after ‘b’, then one match of ‘a’ and ‘b’ is got and the stack top, i.e., z 2 will be popped from the stack. The δ function is

δ(q 0 , a, z 2 ) → (q 0 , λ)

By these δ functions, all the input symbols of the input tape will be traversed. The PDA will be in state q 0 with the stack top z 0 .

If we have to design the PDA accepted by the empty stack, the δ function will be

δ(q 0 , λ, z 0 ) → (q 0 , λ)

If we have to design the PDA accepted by the final state, the δ function will be

δ(q 0 , λ, z 0 ) → (q f , z 0 )

( In the language set, a null string can occur. If a null string occurs in the language set, then it will also be accepted by the last two δ functions directly .)

So, the PDA for L = (a, b)* with equal number of ‘a’ and ‘b’, i.e., n a (L) = n b (L) is

Equation

δ is defined as follows:

Equation

Example 7.3

Construct a PDA to accept L = (a, b) + with an equal number of ‘a’ and ‘b’, i.e., n a (L) = n b (L) by the empty stack and the final state.

Solution: In the string (a, b) + , there will be at least one ‘a’ and one ‘b’ with an equal number of ‘a, and ‘b’. So, the PDA will be made such that the null string will not be accepted. All the conditions are the same like (a, b)* , but to avoid null occurrence the transitions will be like this.

On getting an ‘a’ at the beginning, change the state from q 0 to q 1 and push z 1 in the stack. From the next input, all the transitions will be on state q 1 .

In a similar way, if the string starts with ‘b’, change the state from q 0 to q 1 and push z 2 in the stack. From the next input, all the transitions will be on state q 1 . Changing the state to q 1 removes the possibility of accepting null string. There may come a situation when z 0 will be stacktop but the string is not totally traversed (example: abba). Following two extra δ functions are added to push z 1 or z 2 in the stack.

Equation

Other transitional functions (δ) will be

Equation

[ If in the language set there is a null string, there exists no transitional function in the PDA, because the null string will only be traversed if the machine is in state q 1 . For coming to q 1 , it needs to traverse at least one ‘a’ or one ‘b’. It is clear from the discussion that the PDA will not accept null string, i.e., it is for L = (a, b) + with an equal number of ‘a’ and ‘b’ .]

Example 7.4

Construct a PDA to accept the language L = {WCW R , where W ∈ (a, b) + and W R is the reverse of W} by the empty stack and by the final state.

Solution: W is a string which consists of any combination of ‘a’ and ‘b’ not including null. The string W may start with ‘a’ or may start with ‘b’. In the string, ‘a’ may come after ‘a’ (for example, aa) or ‘b’ may come after ‘a’ (for example, ab). Or, ‘a’ may come after ‘b’ (ba) or ‘b’ may come after ‘b’ (for example, bb).

W R is the reverse of W. It means that in W R if ‘a’ occurs at the ith place from the beginning, then ‘a’ will occur at the ith place from the end in W. C is the marker which denotes the end of W and the beginning of W R .

The PDA will be designed as follows.

The PDA is in state q 0 with the stack top z 0 . In the string W, if ‘a’ is traversed as the start symbol, a stack symbol z 1 will be pushed and the PDA will change its state to q 1 (to avoid accepting the null string). If ‘b’ is traversed a stack symbol z 2 will be pushed, the PDA will change its state to q 1 (to avoid accepting the null string). The δ function will be

Equation

If in W, ‘a’ occurs after ‘a’, then the state is q 1 and the stack top is z 1 . One z 1 will be pushed to the stack. If ‘b’ occurs after ‘a’, then the state is q 1 and the stack top is z 1 . One z 2 will be pushed to the stack. The δ function will be

Equation

If in W, ‘a’ occurs after ‘b’, then the state is q 1 and the stack top is z 2 . One z 1 will be pushed to the stack. If ‘b’ occurs after ‘b’, then the state is q 1 and the stack top is z 2 . One z 2 will be pushed to the stack. The δ function will be

Equation

By the already given transitional functions, the string W will be traversed.

At the end of W, the input head will come to the symbol C to traverse it. C indicates that the string W is finished and W R will start. Before traversing C, either ‘a’ or ‘b’ is traversed. When C is going to be traversed, at the stack top there will be either z 1 (if just before ‘a’ is traversed) or z 2 (if just before ‘b’ is traversed). Upon traversing C only there will be a state change from q 1 to q 2 , but no operation will be done on the stack. The δ function will be

Equation

After traversing C, the reverse string of W, i.e., W R will come. If ‘a’ comes at the i th place from the beginning, then ‘a’ will come at the i th place from the end in W. If for the string W R as an input ‘a’ comes, the stack top will be z 1 and the state will be q 2 . If for the string W R as an input ‘b’ comes, the stack top will be z 2 and the state will be q 2 . This stack top will be popped from the stack. The δ function will be

Equation

By these δ functions, all the input symbols of the input tape will be traversed. The PDA will be in state q 2 with the stack top z 0 .

If we have to design the PDA accepted by the empty stack, the δ function will be

δ(q 2 , λ, z 0 ) → (q 2 , λ)

If we have to design the PDA accepted by final state, the δ function will be

δ(q 2 , λ, z 0 ) → (q f , z 0 )

The PDA for L = {WCW R , where W ∈ (a, b) + and W R is the reverse of W} is

Equation

δ is defined as follows:

Equation

Example 7.5

Construct a PDA to accept the language L = {WCW R , where W ∈ (a, b)* and W R is the reverse of W} by the empty stack and by the final state.

Solution: The string W may contain a null string. If W is null, then W R is null. It means in the language set, there will be only C if W is null. The PDA will always be in state q 0 at the time of traversing the string W. The δ functions for traversing W will be

Equation

C indicates the end of W and the beginning of W R . When C will be traversed, a state change from q 0 to q 1 will occur. The string W may be null. The set L may contain only C. So, the stack top will be one of the following at the time of traversing C.

May be z 1 (if just before ‘a’ is traversed)

May be z 2 (if just before ‘b’ is traversed)

May be z 0 (if no input alphabet is traversed, i.e., W is null).

The δ function for traversing C will be

Equation

By the previous given δ functions, all the input symbols of the input tape will be traversed. The PDA will be in state q 1 with the stack top z 0 .

If we have to design the PDA accepted by the empty stack, the δ function will be

δ(q 1 , λ, z 0 ) → (q 1 , λ)

If we have to design the PDA accepted by the final state, the δ function will be

δ(q 1 , λ, z 0 ) → (q f , z 0 )

Example 7.6

Construct a PDA to accept the language L = {a n b m c m d n , where m, n ≥ 1} by the empty stack and by the final state.

Solution: The string is a n b m c m d n , where m, n ≥ 1 . The remarks we can draw from the string are as follows:

  1. The string consists of a, b, c, and d.
  2. ‘b’ will follow ‘a’, ‘c’ will follow ‘b’, and ‘d’ will follow ‘c’.
  3. The number of ‘a’ is equal to the number of ‘d’ and the number of ‘b’ is equal to the number of ‘c’.
  4. In all the strings of the language set, there will be at least one ‘a’, one ‘b’, one ‘c’, and one ‘d’.

We need to check the equal number of ‘a’ and ‘d’ and the equal number of ‘b’ and ‘c’. The string starts with ‘a’, so in the input tape ‘a’ will come first with state q 0 and the stack top z 0 . A stack symbol z 1 will be pushed to the stack. From the next appearance of ‘a’ in the input tape, the stack top will be z 1 . Another z 1 will be pushed to the stack. The δ function for traversing ‘a’ will be

Equation

After complete traversal of ‘a’ in the input tape, ‘b’ will come to be traversed. At the time of traversal of the first ‘b’ in the input tape, the PDA will be in state q 0 with the stack top z 1 (before it all ‘a’s are traversed). A state change from q 0 to q 1 will occur and a stack symbol z 2 will be added to the stack. From the next appearance of ‘b’ in the input tape, the state will be q 1 and the stack top will be z 2 . Another z 2 will be pushed to the stack. The δ function for traversing ‘b’ will be

Equation

After complete traversal of ‘b’ in the input tape, ‘c’ will come to be traversed. The number of ‘b’ and the number of ‘c’ are equal in all strings that belong to the language set L. At the time of traversal of the first ‘c’ in the input tape, the PDA will be in state q 1 with the stack top z 2 (before it, all ‘b’s are traversed). A state change from q 1 to q 2 will occur and the stack top symbol z 2 will be popped from the stack. From the next appearance of ‘b’ in the input tape, the state will be q 2 and the stack top will be z 2 . The symbol z 2 will be popped from the stack. The δ function for traversing ‘b’ will be

Equation

When all the ‘c’ will be traversed in the stack, there will be z 1 , which was added at the time of traversal of ‘a’ as the stack top, and the PDA will be in state q 2 . At the time of traversal of the first ‘d’ in the input tape, the PDA will be in state q 2 with the stack top z 1 . A state change from q 2 to q 3 will occur and the stack top symbol z 1 will be popped from the stack. From the next appearance of ‘d’ in the input tape, the state will be q 3 and the stack top will be z 1 . The symbol z 1 will be popped from the stack. The δ function for traversing ‘b’ will be

Equation

By the previous given δ functions, all the input symbols of the input tape will be traversed. The PDA will be in state q 3 with stack top z 0 .

If we have to design the PDA accepted by the empty stack, the δ function will be

δ(q 3 , λ, z 0 ) → (q 3 , λ)

If we have to design the PDA accepted by the final state, the δ function will be

δ(q 3 , λ, z 0 ) → (q f , z 0 )

The PDA for L = {a n b m c m d n , where m, n ≥ 1} is

Equation

δ is defined as follows:

Equation

Example 7.7

Construct a PDA to accept the language L = {a n b n c m d m , where m, n ≥ 1} by the empty stack and by the final state.

Solution: Here, the number of ‘a’ and the number of ‘b’ are the same and the number of ‘c’ and the number of ‘d’ are the same. The state change will occur in transition from ‘a’ to ‘b’, ‘b’ to ‘c’, and ‘c’ to ‘d’. Upon traversing ‘a’, the stack symbol z 1 will be pushed to the stack. The number of ‘b’ is the same as the number of ‘a’. The number of z 1 pushed to the stack will be equal to the number of ‘a’, i.e., the number of ‘b’. For traversal of each ‘b’ in the input tape, one z 1 will be popped from the stack.

When the first ‘c’ will be traversed, the stack top will be z 0 . Upon traversing ‘c’, the stack symbol z 2 will be pushed to the stack. Upon traversing ‘d’, those z 2 will be popped from the stack.

By these processes, all the strings will be traversed. The PDA for accepting the string a n b n c m d m /m, n ≥ 1 will be

Equation

The transition function for constructing PDA for the string a n b n c m d m /m, n ≥ 1 will be

Equation

Example 7.8

Construct a PDA to accept the language L = {a n b 2n , where n ≥ 1} by the empty stack and by the final state.

Solution: In the language set L, each string is in the form a n b 2n where n ≥ 1. The number of ‘b’ is double the number of ‘a’. At the time of traversing a single ‘a’ from the input tape, two z 1 as stack symbols will be pushed to the stack.

Equation

Equation

These two z 1 will be popped at the time of traversing the two ‘b’s. (A single ‘a’ is equal to two ‘b’s.)

The δ function for traversing ‘b’ will be

Equation

By the previous given δ functions, all the input symbols of the input tape will be traversed. The PDA will be in state q 1 with the stack top z 0 .

If we have to design the PDA accepted by the empty stack, the δ function will be

δ(q 1 , λ, z 0 ) → (q 1 , λ)

If we have to design the PDA accepted by the final state, the δ function will be

δ(q 1 , λ, z 0 ) → (q f , z 0 )

The PDA will be as follows:

Equation

The transitional function will be as follows:

Equation

Example 7.9

Construct a PDA for the language L = {a n Cb 2n , where n ≥ 1}.

Solution: In the language set, the number of ‘b’ is twice the number of ‘a’. ‘C’ is the middle element, which indicates the end of ‘a’ and the beginning of ‘b’. For each ‘a’, two z 1 are inserted in the stack, and for each ‘b’, one z 1 is popped from the stack.

The transitional functions are

Equation

Example 7.10

Construct a PDA for the language L = {a m b n where m ≤ n and m, n ≥ 1}.

Solution: In the language set, the number of ‘a’ is less than the number of ‘b’. At the time of traversing ‘a’, one z 1 is added to the stack. For m number of ‘a’, m number of z 1 are added to the stack. At the time of traversing m number of ‘b’, the stack top is z 1 , which is popped. If n > m, then at the time of traversing the last (n – m) number of ‘b’, the stack top is z 0 .

The transitional functions are

Equation

Example 7.11

Construct a PDA to accept the language L = {a n b m c n + m , where n > 0, m > 0}.

Solution: In the language set, the total number of ‘c’ is equal to the total number of ‘a’ and ‘b’. The PDA can be designed in the following way: at the time of traversing n number of ‘a’, n number of ‘z 1 ’ are added to the stack and for traversing m number of ‘b’, m number of z 1 are added to the stack. At the time of traversing (n + m) number of c, all the z 1 are popped from the stack.

The transitional functions are

Equation

Example 7.12

Construct a PDA to accept the language L = {a n b m c n + m , where n ≥ 0, m > 0}.

Solution: The string is the same as the previous one, but in the language set the number of ‘a’ may be zero. In the case when the number of ‘a’ is zero, the string starts from ‘b’.

The transitional functions are

Equation

Example 7.13

Construct a PDA to accept the language L = {a n b n + m c m , where n, m > 0}.

Solution: In the language set, the number of ‘b’ is the total number of ‘a’ and ‘c’. At the time of traversal of n number of ‘a’, n number of z 1 are pushed in the stack, and at the time of traversal of n number of ‘b’, n number of z 1 are popped from the stack. At the time of traversal of the rest m number of ‘b’, m number of z 2 are pushed into the stack, which are popped at the time of traversal of m number of ‘c’.

The transitional functions are

Equation

Example 7.14

Construct a PDA to accept the language L = {a n b n + m c m , where n ≥ 0, m > 0}.

Solution: The string is the same as the previous one, but in the language set the number of ‘a’ may be zero. In the case when the number of ‘a’ is zero, then the string starts from ‘b’.

The transitional functions are

Equation

Example 7.15

Construct a PDA to accept the following language L = {a 2n b n , where n > 0}.

Solution: The language consists of 2n number of ‘a’ and n number of ‘b’ belong to the language set. The PDA can be designed as follows—at the time of traversing the first ‘a’, two z 1 are added to the stack with a state change from q 0 to q 1 . At the time of traversing the second ‘a’, one z 1 is popped from the stack with a state change from q 1 to q 0 . By this process after traversing 2n number of ‘a’, only n number of z 1 exist in the stack. At the time of traversing the first ‘b’, the stack top is z 1 and the state is q 0 . Those z 1 are popped at the time of traversing n number of ‘b’.

The transitional functions are

Equation

Example 7.16

Construct a PDA to accept the language L = {a n b n c m , where n, m ≥ 1} by the empty stack and by the final state.

Solution: The language is in the form a n b n c m , where n, m ≥ 1. In the language set, the number of ‘a’ and the number of ‘b’ are the same, but the number of ‘c’ is different. All the strings in the language set start with n number of ‘a’s followed by n number of ‘b’s and ends with m number of ‘c’s. Here, m and n are both ≥ 1, and the null string does not belong to the language set.

The PDA for the language can be designed in the following way.

When traversing the ‘a’s from the input tape, the z 1 ’s are pushed in the stack one by one. At the time of traversing the ‘b’s, all the z 1 ’s which were pushed into the stack are popped one by one. When the first ‘c’ will be traversed, at that time the machine is in state q 1 and stack top z 0 . At the time of traversal of m number of ‘c’s, no operation is done on the stack.

The transition function for constructing the PDA for the string a n b n c m where m, n ≥ 1 are

Equation

Example 7.17

Construct a PDA to accept the language L = {a n b m c n , where n, m ≥ 1} by the empty stack and by the final state.

Solution: The language is in the form a n b m c n , where n, m ≥ 1. In the language set, the number of ‘a’s are equal to the number of ‘c’s. In the language set, ‘a’s are separated from ‘c’s by m number of ‘b’s. As m, n ≥ 1, the null string does not belong to the language set. In the language set, the number of ‘a’ is equal to the number of ‘c’ but not with the number of ‘b’.

The PDA can be designed in the following way.

When traversing ‘a’s from the input tape, z 1 ’s are pushed in the stack one by one. When the first ‘b’ is read by the input head, the machine is in state q 0 and stack top z 1 . One state change has occurred. [If after ‘b’ again ‘a’ comes as input, the language is in a wrong format. But that ‘a’ will also be traversed as there will be a function δ(q 0 , a, z 1 ) → (q 0 , z 1 z 1 ) to traverse that ‘a’. To avoid this mismatch and to guarantee that the PDA is only for accepting a n b n c m , where n, m ≥ 1, the state change is required.] At the time of traversing ‘b’, no operation is done on the stack.

When ‘c’ is going to be traversed, the machine is in state q 1 , with the stack top z 1 . The stack top is popped and a state change has occurred (to avoid appearance of ‘b’ after ‘c’).

The transition function for constructing the PDA for the string a n b n c m where m, n ≥ 1 will be

Equation

Example 7.18

Construct a PDA to accept the language L = {w, where number of ‘a’ + number of ‘b’ = number of ‘c’}.

Solution: According to the given specification, any string that belongs to the language set consists of any combination of ‘a’, ‘b’, and ‘c’, and the number of ‘c’ is equal to the number of ‘a’ and the number of ‘b’. In the string ‘a’, ‘b’ and ‘c’ can occur in any sequence by fulfilling the given condition.

The transitional functions are

Equation

7.3  DPDA and NPDA

There are two types of PDA:

  1. Deterministic pushdown automata (DPDA)
  2. Non-deterministic pushdown automata (NPDA)

7.3.1.  Deterministic Pushdown Automata (DPDA)

A PDA is said to be a DPDA if all derivations in the design give only a single move.

If a PDA being in a state with a single input and a single stack symbol gives a single move, then the PDA is called DPDA.

As an example, for L = {a n b n where n ≥ 1}, a DPDA can be designed if the transitional functions are as follows:

Equation

In the previous PDA, in a single state with a single input and a single stack symbol, there is only one move. So, the PDA is deterministic.

A context-free language is called deterministic context-free language if it is accepted by a DPDA.

7.3.2.  Non-deterministic Pushdown Automata (NPDA)

A pushdown automata is called non-deterministic if one of the derivations generates more than one move.

If a PDA being in a state with a single input and a single stack symbol gives more than one move for any of its transitional functions, then the PDA is called NPDA.

A context-free language is called non-deterministic context-free language if it is accepted by a NPDA.

The following are some examples of NPDA.

Example 7.19

Design a non-deterministic PDA for accepting the string {WW R where W ∈ (a, b) + and W R is the reverse of W} by the empty stack and by the final state.

Solution: W is a string which consists of ‘a’ and ‘b’. W R is the reverse string of W. Let W = abaa, then W R will be aaba. WW R will be abaaaaba. Traversing ‘a’ in the input tape, z 1 will be pushed into the stack, and traversing ‘b’ in the input tape z 2 will be pushed into the stack. When W R will start, for the traversal of the first symbol, the state of the PDA will be changed and the stack top will be popped. From the next input symbols belonging to W R , the stack top will be popped.

Here, there is a problem. To the PDA, it is not assigned where W is ended and W R is started. From the beginning state, the PDA will traverse the total string assuming it as W. Sometimes (in some books) attempt has been done to differentiate W and W R by traversing a λ symbol and changing the state in between W and W R . But this is also wrong, as all the input symbols are placed on the input tape from left to right in a continuous fashion. There is no gap in between the two input symbols as they are placed one by one in each square from left to right on the input tape.

From the previous discussion, it is clear that a DPDA cannot be designed for WW R .

But, this is possible for an NPDA. Our problem is to find the middle of the string where W ends and W R starts. There is a chance to be the middle of the string where two ‘a’s or two ‘b’s appear, because the last alphabet of W is the first alphabet of W R . Make two transitional functions when the stack top is z 1 and ‘a’ is traversed as input and the stack top is z 2 and ‘b’ is traversed as input. (All the other δ functions are the same as WCW R ). The PDA for accepting the string WW R /W ∈ (a, b) + , where W R is the reverse of W, is

Equation

The transitional function will be as follows:

Equation

Consider a string abbbba. The string is in the form WW R , where W = abb.

Equation

Example 7.20

Design a for accepting the string {WW R where W ∈ (a, b)* and W R is the reverse of W} by the empty stack and by the final state.

Solution: The null string may belong to the language set. The PDA will be designed in such a way that the null string can be accepted by the PDA. The transitional functions will be as follows:

Equation

Example 7.21

Design a NPDA for accepting the string L = {(Set of all palindromes over a, b)} by the empty stack and by the final state.

Solution: A string which when read from left to right and right to left gives the same result is called a palindrome. Palindromes can be of two types (a) odd palindrome and (b) even palindrome. Odd palindromes are those in which the number of characters is odd, and even palindrome are those in which the number of characters is even.

The string ‘a’ is a palindrome, and ‘b’ is a palindrome. ‘aa’ is a palindrome, and ‘bb’ is a palindrome. The string ‘aba’ is a palindrome, ‘aaa’ and ‘bbb’ are also palindromes. The null string is also a palindrome.

The PDA will be

Equation

The transitional functions are as follows:

Equation

7.4  Construction of PDA from CFG

PDA is the machine accepting a context-free language. A context-free language is generated from context-free grammar. Now, the question is whether the PDA can be directly generated from the CFG. The answer is ‘yes’. The following section describes the process of generating a PDA directly from the CFG.

Step I: Convert the PDA into a Greibach Normal Form (GNF).

Step II: First the start symbol S of the CFG is put to the stack by the transition function

δ(q 0 , ∈, z 0 ) → (q 1 , Sz 0 )

Step III: For a production in the form {NT 1 } → {Single T}{String of NT}, the transitional function will be

δ(q 1 , T, NT 1 ) → (q 1 , String of NT)

Step IV: For a production in the form {NT 1 } → {Single T}, the transitional function will be

δ(q 1 , T, NT 1 ) → (q 1 , λ)

Step V: For accepting a string, two transitional functions are added, one for being accepted by the empty stack and one for being accepted by the final state.

Follow the examples for constructing a PDA directly from the CFG.

Example 7.22

Construct a PDA that accepts the language generated by the following grammar.

Equation

Show an ID for the string abab for the PDA generated.

Solution: The context-free grammar is in GNF.

First, the start symbol S is pushed into the stack by the following production

δ(q 0 , ∈, z 0 ) → (q 1 , Sz 0 )

For the production S → aB, the transitional function is

δ(q 1 , a, S) → (q 1 , B)

For the production A → aB, the transitional function is

δ(q 1 , a, A) → (q 1 , B)

For the production B → bA/b, the transitional function is

δ(q 1 , b, B) → (q 1 , A), (q 1 , λ)

So, the PDA for the previous CFG is

Equation

δ functions are defined as follows:

Equation

ID for the String abab

Equation

[ The process is very easy. First, try to generate the string from the given grammar by leftmost derivation. Then, according to the non-terminal symbols replaced use the particular transitional function to give the ID.

For the previous case, the string ‘abab’ is generated like the following derivation (leftmost) Equation

The first transitional function is adding S in the stack. After that, the S is replaced by B for the input ‘a’ using the transitional function δ(q 1 , a, S) → (q 1 , B)

The process continues like this till the end of the string. ]

Example 7.23

Construct an equivalent PDA for the following context-free grammar.

Equation

Show an ID for the string abbaaabbbbab for the PDA generated with stack description.

Solution: The context-free grammar is in GNF.

First, the start symbol S is pushed into the stack by the following production:

δ(q 0 , ∈, z 0 ) → (q 1 , Sz 0 )

For the production S → aAB, the transitional function is

δ(q 1 , a, S) → (q 1 , AB)

For the production S → bBA, the transitional function is

δ(q 1 , b, S) → (q 1 , BA)

For the production A →bS, the transitional function is

δ(q 1 , b, A) → (q 1 , S)

For the production B → aS, the transitional function is

δ(q 1 , a, B) → (q 1 , S)

For the production A → a, the transitional function is

δ(q 1 , a, A) → (q 1 , λ)

For the production B → b, the transitional function is

δ(q 1 , b, B) → (q 1 , λ)

For acceptance, the transitional function is

Equation

ID for the String abbaaabbbbab

Equation

Example 7.24

Construct an equivalent PDA for the following context-free grammar.

Equation

Show an ID for the string 010000 for the PDA generated.

Solution: First, the start symbol S is pushed into the stack by the following production

δ(q 0 , ∈, z 0 ) → (q 1 , Sz 0 )

For the production S → 0BB, the transitional function is

δ(q 1 , 0, S) → (q 1 , BB)

For the production B → 0S, the transitional function is

δ(q 1 , 0, B) → (q 1 , S)

For the production B → 1S, the transitional function is

δ(q 1 , 1, B) → (q 1 , S)

For the production B → 0, the transitional function is

δ(q 1 , 0, B) → (q 1 , λ)

For acceptance, the transitional function is

Equation

ID for the String 010000

(q 0 , 010000, z 0 ) → (q 1 , 010000, Sz 0 ) → (q 1 , 10000, BBz 0 ) → (q 1 , 0000, SBz 0 ) → (q 1 , 000, BBBz 0 ) → (q 1 , 00, BBz 0 ) → (q 1 , 0, Bz 0 ) → (q 1 , λ, z 0 ) → (q 1 , λ) // By empty stack

Example 7.25

Construct an equivalent PDA for the following context-free grammar.

Equation

Show an ID for the string aabbbc for the PDA generated.

Solution: First, the start symbol S is pushed into the stack by the following production

δ(q 0 , ∈, z 0 ) → (q 1 , Sz 0 )

For the production S → aA, the transitional function is

δ(q 1 , a, S) → (q 1 , A)

For the production A → aABC, the transitional function is

δ(q 1 , a, A) → (q 1 , ABC)

For the production A → bB, the transitional function is

δ(q 1 , b, A) → (q 1 , B)

For the production A → a, the transitional function is

δ(q 1 , a, A) → (q 1 , λ)

For the production C → c, the transitional function is

δ(q 1 , c, C) → (q 1 , λ)

For acceptance, the transitional function is

Equation

ID for the String aabbbc

(q 0 , aabbbc, z 0 ) → (q 1 , aabbbc, Sz 0 ) → (q 1 , abbbc, Az 0 ) → (q 1 , bbbc, ABCz 0 ) → (q 1 , bbc, BBC) → (q 1 , bc, BC) → (q 1 , c, C) → (q 1 , λ, z 0 ) → (q f , z 0 ) // accepted by the final state.

Example 7.26

Construct an equivalent PDA for the following context-free grammar.

S → aSbb/aab

Show an ID for the string aaabbb for the PDA generated.

Solution: The given grammar is not in GNF. First, we need to convert the grammar into GNF.

Replace ‘b’ by B and ‘a’ by A. The converted grammar in GNF is as follows:

Equation

Now, the grammar can be easily converted into GNF.

The transitional functions for the PDA accepted by the language generated by the grammar are as follows:

Equation

Equation

ID for the String aaabbb

δ(q 0 , aaabbb, z 0 ) → (q 1 , aaabbb, Sz 0 ) → (q 1 , aabbb, SBBz 0 ) → (q 1 , abbb, ABBBz 0 ) → (q 1 , bbb, BBBz 0 ) → (q 1 , bb, BBz 0 ) → (q 1 , b, Bz 0 ) → (q 1 , λ, z 0 ) → (q f , z 0 ) // accepted by the final state.

7.5  Construction of CFG Equivalent to PDA

Consider a PDA M = (Q, Σ, Γ, δ, q 0 , z 0 , F) which accepts a language L by empty stack. (Accepted by empty stack and accepted by final state is equivalent). A CFG, G = (V N , Σ, P, S), equivalent to M can be constructed using the following rules.

Let S be the start symbol.

  1. For q i ∈ Q, add a production rule S → [q 0 , z 0 , q i ] to P in G. If a PDA contains n number of states, from the start symbol there will be n number of productions.
  2. For the δ function δ(q, a, Y) → (r, ε) where (q, r) ∈ Q, a ∈ Σ, and Y ∈Γ, add a production rule [qYr]→ a in P.
  3. For the transitional function δ(q, a, Y) → (r, Y 1 , Y 2 ..... Y k ) where (q, r) ∈ Q, a ∈ Σ, and Y, Y 1 , Y 2 ..... Y k ∈ Γ, then for each choice of q 1 , q 2 , q k ∈ Q, add production [qYq k ] → a[rY 1 q 1 ] [q 1 Y 2 q 2 ] ..... [q k – 1 X k q k ] P of the grammar.

Example 7.27

Convert the following PDA into equivalent CFG.

Equation

Solution: The PDA contains three states: q 0 , q 1 , and q 2 . The following productions are added to the CFG [According to rule (1)]

S → [q 0 z 0 q 0 ]/[q 0 z 0 q 1 ]/[q 0 z 0 q 2 ]

The transitional functions (iii), (iv), (vii), (viii), and (ix) are in the form δ(q, a, Y) → (r, ε). Thus, the following five productions are added to the CFG [According to rule (2)]

Equation

For the remaining transitional functions, the productions are as follows:

Equation

Equation

Equation

Equation

Equation

Example 7.28

Convert the following PDA into an equivalent CFG.

Equation

Solution: The PDA contains two states: q 0 and q 1 . The following productions are added to the CFG [according to rule (1)].

S → [q 0 z 0 q 0 ]/[q 0 z 0 q 1 ]

Transitional functions (iv), (vi), and (vii) are in the form δ(q, a, Y) → (r, ∈). Thus, the following three productions are added to the CFG [according to rule (2)]

Equation

For the remaining transitional functions, the productions are as follows:

Equation

Equation

Equation

Equation

7.6  Graphical Notation for PDA

The mathematical notation for a PDA is (Q, Σ, Γ, λ, q 0 , z 0 , F). In a PDA, the transitional function δ consists of three touples: first is a present state, second is the present input, and the third is the stack top symbol, which generates one next state and the stack symbol(s) if a symbol is pushed into the stack or ∈, if the top most symbol is popped from the stack.

In the graphical notation of the PDA, there are states. Among them a circle with an arrow indicates a beginning state and a state with double circle indicates a final state. The state transitions are denoted by arrows. The labels of the state transitions consists of input symbol, previous stack top symbol (at t i–1 ) and the current stack top symbol (at t i ) which is added after the transitions or null symbol (if a symbol is popped).

Example 7.29

Construct a PDA with a graphical notation to accept L = (a, b)* with equal number of ‘a’ and ‘b’, i.e., n a (L) = n b (L) by the final state.

Solution: At the beginning of transition, the PDA is in state q 0 with stack z 0 . The string may start with ‘a’ or ‘b’. If the string starts with ‘a’, one z 1 is pushed into the stack. If the string starts with ‘b’, one z 2 is pushed into the stack. If ‘b’ is traversed after ‘a’, and the stack top is z 1 , that stack top is popped. If ‘a’ is traversed after ‘b’, and the stack top is z 2 , that stack top is popped. If ‘a’ is traversed after ‘a’, and the stack top is z 1 , one ‘z 1 ’ is pushed into the stack. If ‘b’ is traversed after ‘b’, and the stack top is z 2 , one ‘z 2 ’ is pushed into the stack.

The PDA in graphical notation is as follows:

Equation

Example 7.30

Construct a PDA with a graphical notation to accept the language L = {WCW R , where W ∈ (a, b) + and W R is the reverse of W} by the final state.

Solution: At the beginning of the transition, the machine is in state q 0 and the stack top symbol is z 0 . If it gets the input symbol ‘a’, one z 1 is pushed into the stack; if it gets the input symbol ‘b’, one z 2 is pushed into the stack and the state is changed from q 0 to q 1 . In state q 1 , if it gets the input ‘a’ and the stack top z 1 or z 2 , another z 1 or z 2 is pushed into the stack, respectively. In state q 1 , if it gets the input ‘b’ with the stack top z 2 or z 1 , another z 2 or z 1 is pushed into the stack, respectively.

C is the symbol which differentiates W with W R . Before C, W is traversed. So, at the time of traversing C, the stack top symbol may be z 1 or z 2 . In state q 1 , if the PDA gets C as input and the stack top z 1 or z 2 , no operation is done on the stack, but only the state is changed from q 1 to q 2 . After C, the string W R is traversed. If the machine gets ‘a’ as input, the stack top must be z 1 . And that z 1 is popped from the stack top. If the machine gets ‘b’ as input, the stack top must be z 2 . And that z 2 is popped from the stack top. The state is not changed. By this process, the whole string WCW R is traversed. In state q 2 , if the machine gets no input but stack top z 0 , the machine goes to its final state q f .

The graphical notation for the PDA is as follows:

Equation

7.7  Two-stack PDA

Finite automata recognize regular languages such as {a n | n ≥ 0}. Adding one stack to a finite automata, it becomes PDA which can recognize context-free language {a n b n , n ≥ 0}. In the case of context-sensitive language such as {a n b n c n , n ≥ 0}, the PDA is helpless because of only one auxiliary storage. Now the question arises—if more than one stack is added in the form of auxiliary storage with PDA, does its power increase or not.

From this question, the concept of a two-stack PDA has come. Not only two stacks, but more than two stacks can be added to a PDA.

A PDA can be deterministic or non-deterministic, but two-stack PDA is deterministic and it accepts all context-free languages, which may be deterministic or non-deterministic, with context-sensitive language such as {a n b n c n , n ≥ 0}. In the Turing machine chapter, we shall learn that two-stack PDA is equivalent to the Turing machine. There, we shall also learn a theorem called the Minsky’s theorem.

Definition: A two-stack PDA consists of a 9-tuple

M = (Q, Σ, Γ, Γ′, δ, q 0 , z 1 , z 2 , F)

where

    Q denotes a finite set of states.

    Σ denotes a finite set of input symbols.

    Γ denotes a finite set of first stack symbols.

    Γ′ denotes a finite set of second stack symbols

    δ denotes the transitional functions.

    q 0 is the initial state of PDA [q 0 ∈ Q].

    z 1 is the stack bottom symbol of stack 1.

    z 2 is the stack bottom symbol of stack 2.

    F is the final state of PDA.

In PDA, the transitional function δ is in the form

Q × (Σ ∪ {λ}) × Γ × Γ′ → (Q, Γ, Γ′)

Example 7.31

Construct a two-stack PDA for the language L = {a n b n c n , n ≥ 0}.

Solution: While scanning ‘a’, push X into stack 1. While scanning ‘b’, push ‘Y’ into stack 2. While scanning ‘c’ with stack top X in 1 and stack top Y in 2, pop X and Y from stack 1 and 2, respectively. The transitional functions are as follows:

Equation

Theorem 7.2: Intersection of RE and CFL is CFL.

Proof: Let L is a CFL accepted by a PDA M1 = {Q 1 , Σ, Γ 1 , δ 1 , q 01 , z 0 , F 1 } and R be a regular expression accepted by a FA M 2 → {Q 2 , Σ, δ 2 , q 02 , F 2 }. A new PDA M 3 = {Q, Σ, λ, δ, q 0 , z 0 , F} is designed which performs computation of M 1 and M 2 in parallel and accepts a string accepted by both M 1 and M 2 . M 3 is designed as follows.

Equation

The transitional function of M 3 keeps track of transaction from S 1 to q 1 in PDA M 1 and S 2 to q 2 in FA M 2 for same input alphabet. Thus a string W accepted by M 3 if and only if, it is accepted by both M 1 and M 2 . Therefore W ∈ L(M 1 ) ∩ L(M 2 ). As W is accepted by a PDA, W is a CFL.

What We Have Learned So Far

  1. Pushdown automata (in short PDA) is the machine format of context-free language.
  2. The mechanical diagram of a pushdown automata contains the input tape, reading head, finite control, and a stack.
  3. A pushdown automata consists of a 7-tuple M = (Q, Σ, Γ, δ, q 0 , z 0 , F) where Q, Σ, q 0 , and F have their original meaning, Γ is finite set of stack symbols, and z 0 is the stack bottom symbol.
  4. In a PDA, the transitional function δ is in the form Q × (Σ ∪ {λ}) × Γ → (Q, Γ).
  5. Instantaneous description (ID) remembers the information of state and stack content at a given instance of time.
  6. There are two ways to declare a string to be accepted by pushdown automata: (a) accepted by the empty Stack (store) and (b) accepted by the final state.
  7. A string is declared accepted by a PDA by the empty stack if the string is totally traversed and the stack is empty.
  8. A string is declared accepted by a PDA by the final state if the string is totally traversed and the machine reaches its final state.
  9. A string is accepted by a PDA by the empty stack if and only if the language is accepted by that PDA by the final state.
  10. If a PDA being in a state with a single input and a single stack symbol gives a single move, then the PDA is called deterministic pushdown automata.
  11. If a PDA being in a state with a single input and a single stack symbol gives more than one move for any of its transitional functions, then the PDA is called non-deterministic pushdown automata.
  12. From context-free grammar, the NPDA can be directly constructed.

Solved Problems

  1. Design a PDA to accept the language of nested balanced parentheses (where the number of opening and closing parenthesis is greater than 0).

    Solution: A nested balanced parenthesis is in the form ((())). More precisely,

    Equation

    This type of nested balanced parenthesis has two types of symbols: open parenthesis ‘(‘ and close parenthesis ‘)’. As it is nested, first the PDA has to traverse the open parenthesis and then the close parenthesis.

    The transitional function for traversing the first open parenthesis is [the beginning state is q 0 , input symbol is ‘(‘ and stack top is z 0 .)

    δ(q 0 , (, z 0 ) → (q 0 , z 1 z 0 )

    From then on, the state is q 0 , the input symbol is ‘(‘ [if the number of open parenthesis is >1], and the stack top is z 0 . The transitional function for traversing the next open parenthesis is

    δ(q 0 , (, z 0 ) → (q 0 , z 1 z 1 )

    By using the previous transitional function, all the remaining open parentheses will be traversed.

    After traversing all open parentheses, the PDA will get the first close parenthesis. At that time the state is q 0 , the input symbol is ‘)’, and the stack top is z 1 . After getting the ‘)’ as an input symbol, the stack top (here z 1 ) will be popped from the stack and the state will be changed to q 1 . The transitional function is

    δ(q 0 , ), z 1 ) → (q 1 , λ)

    After that, the state is q 1 , the input symbol is ‘)’, and the stack top is z 1 (if the string contains multiple open and close parentheses). The transitional function is

    δ(q 1 , ), z 1 ) → (q 1 , λ)

    When all the input symbols will be traversed, the state is q 1 , the input symbol is λ, and the stack top is z 0 .

    If we have to design the PDA accepted by the empty stack, the δ function will be

    δ(q 1 , λ, z 0 ) → (q 1 , λ)

    If we have to design the PDA accepted by the final state, the δ function will be

    δ(q 1 , λ, z 0 ) → (q f , z 0 )

    The transitional functions for the PDA is

    Equation

  2. Design a PDA to accept the language of balanced parentheses (where the number of opening and closing parentheses is greater than 0).

    Solution: There are two types of parentheses—open parentheses and close parentheses. Balanced parenthesis means for each open parenthesis there is a close parenthesis. It may be nested like ((( ))) or may be non-nested like (( ) ( )) or ( )( )( ) or any other form. But for each open parenthesis, there is a close parenthesis. (The definition that a balanced parenthesis means equal number of open and close parentheses is wrong.)

    As an example, ) ( )( ) (is not a balanced parenthesis. The string must start with an open parenthesis and after that, open parenthesis or close parenthesis can appear, but for any position of the string, the number of open parenthesis is greater than or equal to the number of close parenthesis.

    The transitional function for traversing the first open parenthesis is [the beginning state is q 0 , the input symbol is ‘(‘, and the stack top is z 0 .]

    Equation

    After the first open parenthesis, there may be an open parenthesis or close parenthesis. If the open parenthesis is to be traversed, then a z 1 is added at the stack top. The transitional function is

    δ(q 1 , (, z 1 ) → (q 1 , z 1 z 1 )

    If a close parenthesis is to be traversed, then one z 1 is popped from the stack top. The transitional function is

    δ(q 1 , ), z 1 ) → (q 1 , λ)

    It may happen that the state is q 1 , the stack top is z 0 , and the input symbol is ‘(‘. [As an example, for the case (( ))( ).] The transitional function for the case is

    δ(q 1 , (, z 0 ) → (q 1 , z 1 z 0 )

    [But the type of case—where the state is q 1 , the stack top is z 0 , and the input symbol is ‘)’ cannot appear.]

    If we have to design the PDA accepted by the empty stack, the δ function is

    δ(q 1 , λ, z 0 ) → (q 1 , λ)

    If we have to design the PDA accepted by the final state, the δ function is

    δ(q 1 , λ, z 0 ) → (q f , z 0 )

    The transitional functions for the entire PDA are

    Equation

  3. Design a PDA to accept the following language L = 0 n 1 n | n > 1.

    [UPTU 2002]

    Solution: Already solved.

  4. Design a PDA to accept the language L = a m b n c m – n , where m > = n and m, n > 0

    Solution: The language consists of ‘a’, ‘b’, and ‘c’. Here, in every string, all ‘a’ will appear before ‘b’ and after ‘b’, ‘c’ will appear. The number of ‘c’ is the subtraction of the number of ‘a’ and the number of ‘b’. At the beginning, the machine is in state q 0 with the stack top z 0 and the input ‘a’. After traversing, the machine will add z 1 in the stack. The transitional function is

    δ(q 0 , a, z 0 ) → (q 0 , z 1 z 0 )

    If the number of ‘a’ is greater than one, then the machine has to traverse ‘a’ with state q 0 and stack top z 1 . Another z 1 is added to the stack top. The transitional function is

    δ(q 0 , a, z 1 ) → (q 0 , z 1 z 1 )

    After traversal of all ‘a’, ‘b’ will appear. When ‘b’ will come, at that time, the state is q 0 , and the stack top is z 1 . The stack top is popped from the top. The transitional function is

    δ(q 0 , b, z 1 ) → (q 1 , λ)

    If the number of ‘b’ is greater than one, then the machine has to traverse ‘b’ with state q 1 and stack top z 1 . (The number of ‘b’ greater than one means that the number of ‘a’ was greater than one.) The stack top is popped from the top. The transitional function is

    δ(q 1 , b, z 1 ) → (q 1 , λ)

    If the number of ‘b’ is less than the number of ‘a’, then ‘c’ will appear after full traversal of all the ‘b’s. At that time, the state is q 1 , and the stack top is z 1 . After traversal of ‘c’, the stack top is popped. The transitional function is

    δ(q 1 , c, z 1 ) → (q 2 , λ)

    If the number of ‘c’ is greater than one, then the machine have to traverse ‘c’ with state q 2 and stack top z 1 . (The number of ‘c’ greater than one means that the number of ‘a’ was greater than one.) The stack top is popped. The transitional function is

    δ(q 2 , c, z 1 ) → (q 2 , λ)

    If we have to design the PDA accepted by the empty stack, the δ function is

    δ(q 2 , λ, z 0 ) → (q 2 , λ)

    If we have to design the PDA accepted by the final state, the δ function is

    δ(q 2 , λ, z 0 ) → (q f , λ)

    It may also happen that m = n, i.e., the number of ‘a’ is equal to the number of ‘b’. At that case, there is no ‘c’ in the language. The string ends after full traversal of all ‘b’. After traversal of all ‘b’s, the state of the machine is q 1 . If we have to design the PDA accepted by the empty stack, the δ function is

    δ(q 1 , λ, z 0 ) → (q 1 , λ)

    If we have to design the PDA accepted by the final state, the δ function is

    δ(q 1 , λ, z 0 ) → (q f , λ)

    The transitional functions for the entire PDA are

    Equation

  5. Design a PDA to accept the language L = a n b m c m – n , where m > n and m, n > 0. Show an ID for the string aabbbbcc.

    Solution: The language consists of ‘a’, ‘b’, and ‘c’. Here, in every string all ‘a’ will appear before ‘b’, and after ‘b’, ‘c’ will appear. The number of ‘c’ is the subtraction of the number of ‘b’ and the number of ‘a’. In the string, the number of ‘b’ is the sum of the number of ‘a’ and the number of ‘c’. It can be designed as follows. For n number of ‘a’, n number of z 1 are added to the stack. For the next n number of b, those z 1 are popped from the stack and z 0 becomes the stack top. For the remaining (m – n) number of ‘b’, (m – n) number of z 2 are added to the stack. For (m – n) number of ‘c’, (m – n) number of z 2 are popped from the stack.

    The transitional functions are designed as follows.

    At the beginning, the machine is in state q 0 with the stack top z 0 and the input ‘a’. After traversing, the machine will add z 1 in the stack. The transitional function is

    δ(q 0 , a, z 0 ) → (q 0 , z 1 z 0 )

    If the number of ‘a’ is greater than one, then the machine has to traverse ‘a’ with state q 0 and the stack top z 1 . Another z 1 is added to the stack top. The transitional function is

    δ(q 0 , a, z 1 ) → (q 0 , z 1 z 1 )

    After traversal of all ‘a’, ‘b’ will appear. When ‘b’ will come, at that time the state is q 0 , and the stack top is z 1 . The stack top is popped from the top. The transitional function is

    δ(q 0 , b, z 1 ) → (q 1 , λ)

    If the number of ‘a’ is greater than one, then the number of ‘b’ is also greater than one because m = (m – n) + n. The machine has to traverse ‘b’ with the state q 1 and the stack top z 1 . The stack top is popped from the top. The transitional function is

    δ(q 1 , b, z 1 ) → (q 1 , λ)

    After some time, all z 1 are popped from the stack. The stack top becomes z 0 . As m is greater than n, the input symbol is still ‘b’ with the machine state q 1 . In this situation, z 2 is pushed into the stack. The transitional function is

    δ(q 1 , b, z 0 ) → (q 1 , z 2 z 0 )

    If m – n is greater than one, i.e., the number of ‘c’ is more than one, then the machine state is q 1 , the input symbol is ‘b’, and the stack top is z 2 . Another z 2 is pushed into the stack. The transitional function is

    δ(q 1 , b, z 2 ) → (q 1 , z 2 z 2 )

    After full traversal of all ‘b’s,‘c’ appears in the string. When ‘c’ appears, the machine state is q 1 and the stack top is z 2 . The stack top z 2 is popped from the stack. The transitional function is

    δ(q 1 , c, z 2 ) → (q 2 , λ)

    If m – n is greater than one, i.e., the number of ‘c’ is more than one, the machine has to traverse ‘c’ with state q 2 and stack top z 2 . The stack top z 2 is popped from the stack. The transitional function is

    δ(q 2 , c, z 2 ) → (q 2 , λ)

    If we have to design the PDA accepted by the empty stack, the δ function is

    δ(q 2 , λ, z 0 ) → (q 2 , λ)

    If we have to design the PDA accepted by the final state, the δ function is

    δ(q 2 , λ, z 0 ) → (q f , λ)

    The transitional functions for the entire PDA are

    Equation

    ID for the String aabbbc

    Equation

  6. Construct a PDA for the following L = {a n cb 2n /n ≥ 1} over alphabet {a, b, c}.

    [UPTU 2003]

    Solution: For each ‘a’, push two ‘X’ in the stack. Traverse ‘c’ with no action. Pop ‘X’ for each ‘b’.

    The transitional functions are

    Equation

  7. Design a PDA for hypertext markup language (HTML) consisting of all tags having immediate closing tags within the <BODY> </BODY> tag.

    Show an ID for the following language

    Equation

    Solution: Hypertext markup language or HTML is a language used for webpage designing. This language is an interpreted language and produces no error. The language has a basic structure in the following form.

    Equation

    The tags can be of capital letter, small letter, or a mixture of both. The tags within < > are called open tags and the tags within < / > are called closing tags. Most of the tags in HTML have closing tags, but some of the tags such as <BR>, <HR> have no closing tags.

    In the <BODY> </BODY> tag, all the other tags appear. The tags may appear in any order. But for all the opening tags, there is a closing tag except the tags which do not have any closing tag. For the line HTML </B> is an <I>interpreted language.</I>, the output is HTML is an interpreted language.

    If the line is in the form HTML is an <I>interpreted </B>language. </I>, the output is HTML is an interpreted language.

    In this section, we are interested in tags with immediate closing tags like the first example, i.e., the tag within the body which has opened first will close at last.

    Every HTML file starts with a <HTML> tag. At state q 0 , when the machine gets <HTML> as input, it pushes Z <HTML> in the stack. The transitional function is

    δ(q 0 , <HTML>, Z 0 ) → (q 1 , Z <HTML> Z 0 )

    In every HTML document after <HTML>, the <HEAD> tag comes. The transitional function for traversing <HEAD> is

    δ(q 1 , <HEAD>, Z <HTML> ) → (q 2 , Z <HEAD> Z <HTML> )

    In every HTML document after <HEAD>, the <TITLE> tag comes. The transitional function for traversing <TITLE> is

    δ(q 2 , <TITLE>, Z <HEAD> ) → (q 3 , Z <TITLE> Z <HEAD> )

    When the machine gets a closing </TITLE> tag, it pops the stack top symbol Z <TITLE> . The transitional function is

    δ(q 3 , </TITLE>, Z <title> ) → (q 3 , λ)

    When the machine gets a closing </HEAD> tag, it pops the stack top symbol Z <HEAD> . The transitional function is

    δ(q 3 , </HEAD>, Z <HEAD> ) → (q 3 , λ)

    Now, the stack top is Z <HTML> . The next symbol is <BODY>. The transitional function for traversing <BODY> tag is

    δ(q 3 , <BODY>, Z <HTML> ) → (q 4 , Z <BODY> Z <HTML> )

    Within the <BODY> tag, any tag can come. Let us assume that a tag named <tag j> has come. Let the state of the PDA be q i , where i is greater than or equal to 4. For traversing that tag, the transition function is

    δ(q i , <tag j>, Z <tag j′> ) → (q i + 1 , Z <tag j> Z <tag j′> )

    If the <tag j> appears with the immediate closing tags, then its closing tag will get the symbol Z <tag j> as the stack top. That stack top is popped.

    δ(q i , </tag j>, Z <tag j> ) → (q i , λ)

    The last two tags are </BODY> and </HTML>. When the </BODY> is traversed, the stack top is Z <BODY> . The stack top is popped by the following transitional function.

    δ(q i , </BODY>, Z <BODY> ) → (q i , λ)

    When </HTML> is traversed, the stack top is Z <HTML> . The stack top is popped by the following transitional function.

    δ(q i , </HTML>, Z <HTML> ) → (q i , λ)

    If we have to design the PDA accepted by the empty stack, the δ function is

    δ(q i , λ, z 0 ) → (q i , λ)

    If we have to design the PDA accepted by the final state, the δ function is

    δ(q i , λ, z 0 ) → (q f , λ)

    ID for the given HTML document: It is not possible to show the string in each phase. Only the state and the stack condition are shown in the description.

    Equation

    Equation

  8. Design a PDA for the language L = {a n b m a m b n , where m, n ≥ 1}.

    Solution: The language is a context-free language. The context-free grammar for the language is

    Equation

    The grammar is not in GNF. So, first we need to convert the grammar into GNF. Take two non-terminals C a and C b and two productions C a → a and C b → b. Replacing in appropriate positions, the modified context-free grammar is

    Equation

    The context-free grammar is in GNF.

    First, the start symbol S is pushed into the stack by the following production

    δ(q 0 , ∈, z 0 ) → (q 1 , Sz 0 )

    For the production S → aSC b , the transitional function is

    δ(q 1 , a, S) → (q 1 , SC b )

    For the production S → aAC b , the transitional function is

    δ(q 1 , a, S) → (q 1 , AC b )

    For the production A → bAC a , the transitional function is

    δ(q 1 , b, A) → (q 1 , AC a )

    For the production A → bC a , the transitional function is

    δ(q 1 , b, A) → (q 1 , C a )

    For the production C a → a, the transitional function is

    δ(q 1 , a, C a ) → (q 1 , λ)

    For the production C b → b, the transitional function is

    δ(q 1 , b, C b ) → (q 1 , λ)

    If we have to design the PDA accepted by the empty stack, the δ function is

    δ(q 1 , λ, z 0 ) → (q 1 , λ)

    If we have to design the PDA accepted by the final state, the δ function is

    δ(q 1 , λ, z 0 ) → (q f , λ)

  9. Construct a PDA for the language L = {(ab) n } ∪ {(ba) n } n ≥ 1.

    Solution: The given language is the union of two languages, (ab) n and (ba) n . The grammar for the first language is

    S 1 → abS 1 /ab

    The grammar for the second language is

    S 2 → baS 2 /ba

    Here, we have considered two start symbols S 1 and S 2 , respectively. As two languages are connected with the union symbol, consider another start symbol for the entire language as S. Make a production rule

    S → S 1 /S 2

    The production rule for the grammar satisfying the language is

    Equation

    The production rule after removing the unit productions and the useless symbols is

    Equation

    The grammar is not in GNF. Consider two non-terminals C a and C b and two productions C a → a and C b → b. The modified production rule becomes

    Equation

    The context-free grammar is in GNF.

    First, the start symbol S is pushed into the stack by the following production

    δ(q 0 , ∈, z 0 ) → (q 1 , Sz 0 )

    For the production S → aC b , the transitional function is

    δ(q 1 , a, S) → (q 1 , C b )

    For the production S → bC a , the transitional function is

    δ(q 1 , b, S) → (q 1 , C a )

    For the production S → aC b S 1 , the transitional function is

    δ(q 1 , a, S) → (q 1 , C b S 1 )

    For the production S → bC a S 2 , the transitional function is

    δ(q 1 , b, S) → (q 1 , C a S 2 )

    For the production S 1 → aC b , the transitional function is

    δ(q 1 , a, S 1 ) → (q 1 , C b )

    For the production S 1 → aC b S 1 , the transitional function is

    δ(q 1 , a, S 1 ) → (q 1 , C b S 1 )

    For the production S 2 → bC a , the transitional function is

    δ(q 1 , b, S 2 ) → (q 1 , C a )

    For the production S 2 → bC a S 2 , the transitional function is

    δ(q 1 , b, S 2 ) → (q 1 , C a S 2 )

    For the production C a → a, the transitional function is

    δ(q 1 , a, C a ) → (q 1 , λ)

    For the production C b → b, the transitional function is

    δ(q 1 , b, C b ) → (q 1 , λ)

    If we have to design the PDA accepted by the empty stack, the δ function is

    δ(q 1 , λ, z 0 ) → (q 1 , λ)

    If we have to design the PDA accepted by the final state, the δ function is

    δ(q 1 , λ, z 0 ) → (q f , λ)

  10. Construct a PDA for the language L = {a n b n } ∪ {a m b 2m } m, n > 0.

    [WBUT 2009 (IT)]

    Solution: The given language is the union of two languages, a n b n and a m b 2m . The grammar for the first language is

    A→ aAb and A → ab

    The grammar for the second language is

    B → aBbb and B → abb

    Here, we have considered two start symbols A and B, respectively. As two languages are connected with a union symbol, consider another start symbol for the entire language as S. Make a production rule

    S → A/B

    The production rule for the grammar satisfying the language is

    Equation

    The grammar contains two unit productions S → A and S→B. After removing the unit productions, the production rules become

    Equation

    The CFG is not in GNF. Consider two non-terminals, S a and S b , and two extra production rules, S a → a and S b → b. Replacing a and b by S a and S b , respectively, in suitable places, the modified production rules become

    Equation

    The context-free grammar is in GNF.

    First, the start symbol S is pushed into the stack by the following production

    δ(q 0 , ∈, z 0 ) → (q 1 , Sz 0 )

    For the production S → aAS b , the transitional function is

    δ(q 1 , a, S) → (q 1 , AS b )

    For the production S → aBS b S b , the transitional function is

    δ(q 1 , a, S) → (q 1 , BS b S b )

    For the production S → aS b S b , the transitional function is

    δ(q 1 , a, S) → (q 1 , S b S b )

    For the production S → aS b , the transitional function is

    δ(q 1 , a, S) → (q 1 , S b )

    For the production A → aAS b , the transitional function is

    δ(q 1 , a, A) → (q 1 , AS b )

    For the production A → aS b , the transitional function is

    δ(q 1 , a, A) → (q 1 , S b )

    For the production B → aBS b S b , the transitional function is

    δ(q 1 , a, B) → (q 1 , BS b S b )

    For the production B → aS b S b , the transitional function is

    δ(q 1 , a, B) → (q 1 , S b S b )

    If we have to design the PDA accepted by the empty stack, the δ function is

    δ(q 1 , λ, z 0 ) → (q 1 , λ)

    If we have to design the PDA accepted by the final state, the δ function is

    δ(q 1 , λ, z 0 ) → (q f , λ)

  11. Construct an NPDA that accepts the language generated by the productions S → aSa/bSb/c. Show an instantaneous description of this string abcba for this problem.

    [WBUT 2007]

    Solution: The production rules are not in GNF. So, we need to first convert it into GNF. The production rules are

    S → aSa/bSb/c

    Let us introduce two new productions, C a → a and C b → b

    The new production rules become

    Equation

    Now, all the productions are in GNF.

    Now, from these productions, a PDA can be easily constructed.

    First, the start symbol S is pushed into the stack by the following production

    δ(q 0 , ∈, z 0 ) → (q 1 , Sz 0 )

    For the production S → aSC a , the transitional function is

    δ(q 1 , a, S) → (q 1 , SC a )

    For the production S → bSC b , the transitional function is

    δ(q 1 , b, S) → (q 1 , SC b )

    For the production S → c, the transitional function is

    δ(q 1 , c, S) → (q 1 , λ)

    For the production C a → a, the transitional function is

    δ(q 1 , a, C a ) → (q 1 , λ)

    For the production C b → b, the transitional function is

    δ(q 1 , b, C b ) → (q 1 , λ)

    For acceptance, the transitional function is

    Equation

    ID for the String ‘abcba’

    Equation

  12. Construct a PDA, A, equivalent to the following context-free grammar

    S→ 0BB, B → 0S/1S/0

    Test whether 0104 is in N(A).

    Solution: The CFG is S→ 0BB, B→ 0S/1S/0

    All the production rules of the grammar are in GNF.

    First, the start symbol S is pushed into the stack by the following production

    δ(q 0 , ∈, z 0 ) → (q 1 , Sz 0 )

    For the production S → 0BB, the transitional function is

    δ(q 1 , 0, S) → (q 1 , BB)

    For the production B → 0S, the transitional function is

    δ(q 1 , 0, B) → (q 1 , S)

    For the production B → 1S, the transitional function is

    δ(q 1 , 1, B) → (q 1 , S)

    For the production B → 0, the transitional function is

    δ(q 1 , 0, B) → (q 1 , λ)

    For acceptance, the transitional functions are

    Equation

    The ID for the String 010000

    Equation

  13. Show that the language L = {0 n 1 n | n ≥ 1} ∪ {0 n 1 2n | n ≥ 1} is a context-free language that is not accepted by any DPDA.

    [UPTU 2005]

    Solution: The context-free grammar for the language is

    Equation

    The GNF equivalent to the grammar is

    Equation

    The transitional functions of the PDA equivalent to the grammar are

    Equation

    The PDA is an NPDA, as for the combination (q 1 , 0, S), there are four transitional functions.

  14. Convert the CFG into an equivalent PDA. [Cochin University 2006]

    Equation

    Solution: The grammar is in GNF.

    First, the start symbol S is pushed into the stack by the following production

    δ(q 0 , ∈, z 0 ) → (q 1 , Sz 0 )

    For the production S → aAA, the transitional function is

    δ(q 1 , a, S) → (q 1 , AA)

    For the production A → aS, the transitional function is

    δ(q 1 , a, A) → (q 1 , S)

    For the production S → bS, the transitional function is

    δ(q 1 , b, S) → (q 1 , S)

    For the production A → a the transitional function is

    δ(q 1 , a, A) → (q 1 , λ)

    For acceptance, the transitional functions are

    Equation

  15. Construct a PDA equivalent to the grammar S → aAA A → aS/b. [Andhra University 2007]

    Solution: The grammar is in GNF.

    First, the start symbol S is pushed into the stack by the following production

    δ(q 0 , ∈, z 0 ) → (q 1 , Sz 0 )

    For the production S → aAA, the transitional function is

    δ(q 1 , a, S) → (q 1 , AA)

    For the production A → aS, the transitional function is

    δ(q 1 , a, A) → (q 1 , S)

    For the production A → b, the transitional function is

    δ(q 1 , b, A) → (q 1 , λ)

    For acceptance, the transitional functions are

    Equation

  16. Construct a PDA equivalent to the following grammar.

    [JNTU 2008]

    Equation

    Solution: The grammar is not in GNF. The grammar is converted into GNF by replacing ‘c’ by C, adding the production D → b, and replacing b by D and replacing A of C → AB by aDC. The final grammar is

    Equation

    (Now convert it to an equivalent PDA.)

  17. Convert the PDA P = ({p, q}, {0, 1}, (x, z 0 ), δ, q, z 0 ) to a CFG, if δ is given as

    δ(q, 1, z 0 ) → (q, xz 0 )          [UPTU 2005]

    Solution: The PDA contains two states, p and q. Thus, the following two production rules are added to the grammar.

    S → (q z 0 q)/(q z 0 p)

    For the transitional function δ(q, 1, z 0 ) → (q, xz 0 ), the production rules are

    Equation

Multiple Choice Questions

  1. PDA is the machine format of

    1. Type 0 language
    2. Type 1 language
    3. Type 2 language
    4. Type 3 language
  2. Which is not true for mechanical diagram of PDA?

    1. PDA contains a stack
    2. The head reads as well as writes
    3. The head moves from left to right
    4. The input string is surrounded by an infinite number of blanks in both sides
  3. The difference between finite automata and pushdown automata is in _____________.

    1. Reading head
    2. Input tape
    3. Finite control
    4. Stack
  4. In the PDA, transitional function δ is in the form

    1. Q × (Σ ∪ {λ}) × Γ → (Q, Γ)

    2. Q × Σ → Q

    3. Q × Σ × Γ → Q

    4. Q × Γ → Q × Σ

      (Where Q is the finite set of states, Σ is the set of input alphabets, and Γ is the stack symbols.)

  5. Instantaneous description remembers

    1. The information of state and input tape content at a given instance of time.
    2. The information of state and stack content at a given instance of time.
    3. The information of input tape and stack content at a given instance of time.
    4. The information of state, input tape, and stack content at a given instance of time.
  6. Which of the following is not possible algorithmically?

    1. RE to CFG
    2. NFA to DFA
    3. CFG to PDA
    4. NPDA to DPDA

Answers:

  1. c
  2. b
  3. d
  4. a
  5. b
  6. d

GATE Questions

  1. Which of the following is not accepted by a DPDA but accepted by an NPDA?

    1. L = a n b n , where n > 0
    2. L = WCW R , where W ∈ (a, b)*
    3. L = WW R , where W ∈ (a, b) +
    4. L = a n b m c m d n , where m, n > 0
  2. Which of the followings cannot be designed by a PDA?

    1. a n b n c i , where n, i > 0
    2. a n b n c n , where n > 0
    3. a n c i b n , where n, i > 0
    4. c i a n b n , where n, i > 0
  3. The symbols belong to the stack of a PDA

    1. Terminals only
    2. Non-terminals only
    3. States
    4. Both terminals and non-terminals
  4. L is accepted by a PDA where no symbol is necessarily removed from the stack. L is in particular

    1. Context-sensitive
    2. Unrestricted
    3. Context-free
    4. Regular
  5. Which of the following languages is accepted by a non-deterministic pushdown automaton (PDA) but not by a deterministic PDA?

    1. Always regular
    2. Never regular
    3. Always a deterministic context-free language
    4. Always a context-free language
  6. Let L be a context-free language and M a regular language. Then, the language L∩M is

    1. {a n b n c n | n ≥ 0}
    2. {a l b m c n | l ≠ m or m = n}
    3. {a n b n | n ≥ 0}
    4. {a m b n | m, n ≥ 0}
  7. Which of the following language over {a, b, c} is accepted by a deterministic pushdown automata?

    1. {WCW R | w ∈ (a, b)*}
    2. {WW R | w ∈ (a, b)*}
    3. {a n b n c n | n ≥ 0}
    4. {w | w is a palindrome over {a, b, c}}
  8. The transitional functions of a pushdown automata are

    Equation

    What is the language accepted by the PDA by the empty store?

    1. 1 n 01 n
    2. 1 n 1 n
    3. 1 n 01 n ∪ ∈
    4. ∈
  9. Let L 0 be the set of all languages accepted by a PDA by the final state and L E the set of all languages accepted by the empty stack. Which of the following is true?

    1. L D = L E
    2. L D ⊃ L E
    3. L E = L D
    4. None of the above
  10. Let G = ({S},{a, b}, R, S) be a context-free grammar where the rule set R is

    S → a S b | S S | ∈

    Which of the following statements is true?

    1. G is not ambiguous
    2. There exists x, y ∈ L(G) such that xy ∉ L(G)
    3. There is a deterministic pushdown automaton that accepts L(G)
    4. We can find a deterministic finite state automaton that accepts L(G)
  11. Let N f and N p denote the classes of languages accepted by the non-deterministic finite automata and the non-deterministic push-down automata, respectively. Let D f and D p denote the classes of languages accepted by the deterministic finite automata and the deterministic push-down automata, respectively. Which one of the following is true?

    1. D f ⊂ N r and D P ⊂ N P
    2. D f ⊂ N r and D P = N P
    3. D f = N f and D P = N P
    4. D f = N f and D P ⊂ N P
  12. Consider the languages:

    Equation

    Which one of the following is true?

    1. L 1 is a deterministic CFL
    2. L 2 is a deterministic CFL
    3. L 3 is a CFL, but not a deterministic CFL
    4. L 3 is a deterministic CFL
  13. Which one of the following is false?

    1. There is a unique minimal DFA for every regular language
    2. Every NFA can be converted to an equivalent PDA
    3. The complement of every context-free language is recursive
    4. Every nondeterministic PDA can be converted to an equivalent deterministic PDA
  14. Let M = (K, ∑, Γ, Δ, s, F) be a pushdown automaton, where

    Equation

    Which one of the following strings is not a member of L(M)?

    1. aaa
    2. aabab
    3. baaba
    4. bab

Answers:

  1. c
  2. b
  3. d
  4. d
  5. b
  6. d
  7. a
  8. c
  9. a
  10. c
  11. d
  12. b
  13. d
  14. d

Hints:

10.  The language accepted by the grammar is a n b n a k b k .....a 1 b 1 .

11.  An NFA can be converted to an equivalent DFA but a DPDA is a subset of an NPDA.

13.  c is discussed in the recursive function chapter.

14.  This came in GATE 2004(IT). Unfortunately, no answer is correct.

Fill in the Blanks

  1. The full form of PDA is ____________.
  2. ____________ is the machine format of context-free language.
  3. The mechanical diagram of pushdown automata is similar to finite automata, but the difference is in ___________.
  4. ____________ of PDA describes the configuration of PDA at a given instance.
  5. There are two ways to declare a string accepted by a pushdown automata: (a) __________ and (b) _______.
  6. For directly constructing a PDA from a given grammar, we first need to convert the grammar into __________ normal form.
  7. If a PDA being in a state with a single input and a single stack symbol gives a single move, then the PDA is called ___________ pushdown automata.
  8. If a PDA being in a state with a single input and a single stack symbol gives more than one move for any of its transitional functions, then the PDA is called ____________ pushdown automata.
  9. The PDA for the string L = {(Set of all palindromes over a, b)} can be designed by __________ pushdown automata and not by ____________ pushdown automata.

Answers:

  1. pushdown automata
  2. Pushdown automata
  3. stack
  4. Instantaneous description (ID)
  5. accepted by the empty stack, accepted by the final state
  6. Greibach
  7. deterministic
  8. non-deterministic
  9. non-deterministic, deterministic

Exercise

  1. Construct a PDA to accept the following languages by the empty store and the final state.

    1. L = {a n , where n > 0}

    2. L = {a n , where n ≥ 0}

    3. L = {a n bc n , where n > 0}

    4. L = {a n b 2n , where n > 0}

    5. L = {a n b m c m + n , where m, n > 0}

    6. L = {a n ba n , where n > 0}

    7. L = {a n b n c i , where n, i > 0}

    8. L = {a m b m + n c n , where m, n > 0}

      (Hints: For m number of ‘a’, m number of Z 1 are pushed into the stack. For the first m number of ‘b’, m number of Z 1 are popped from the stack. For the next n number of ‘b’, n number of Z 2 are pushed into the stack, which will be popped for the next n number of ‘c’ .)

    9. L = {a m b m + n a n , where m, n > 0}

    10. L = {WCW, where W ∈ (a, b) + }

    11. L = {WCW, where W ∈ (a, b)*}

  2. Construct an equivalent PDA for the following context-free grammars.

    1. Equation
    2. Equation
    3. Equation
  3. Construct a PDA with graphical notation to accept the following languages by the graphical notation.

    1. L = {a n b n c m d m , where m, n ≥ 1}
    2. L = {a n b n c m , where n, m ≥ 1}