Lab 5 - DPDA

Lab Session #4 #

Agenda #

  • Deterministic Pushdown Automaton (DPDA): Notion, formal definition, configuration, transition, and acceptance.
  • Exercises on DPDAs

Pushdown Automata #

A Pushdown Automaton (PDA) is a way to implement a Context Free Grammar in a similar way we design Finite Automaton for Regular Grammar.

  • It is more powerful than FSA
  • FSA has a very limited memory but PDA has more memory
  • PDA = FSA + a Stack

A stack is a way we arrange elements one on top of another; it does two basic operations:

  • PUSH: A new element is added at the Top of the stack
  • POP: The Top element of the stack is read and removed

PDA-components #

A Pushdown Automaton has 3 components:

  • An input tape
  • A Finite Control Unit
  • A Stack of infinite size

Acceptance criteria: A string xx is accepted by a PDA if there is a path coherent with xx on the PDA that goes from the initial state to the final state. The input string has to be read completely.

When a PDA reads an input symbol, it will be able to save it (or save other symbols) in its memory.

  • For deciding if an input string is in the language AnBn A_nB_n , the PDA needs to remember the numbers of aa ’s.
  • Whenever the PDA reads the input symbol bb , two things should happen:
  1. it should change states: from now on the only legal input symbols are bb ’s.
  2. it should delete one a from its memory for every bb it reads.

A single move of a PDA will depend on:

  • the current state,
  • the next input (it could be no symbol: ε symbol), and
  • the symbol currently on top of the stack. PDA will be assumed to begin operation with an initial start symbol Z0 Z_0 on its stack
  • Z0 Z_0 is not essential, but useful to simplify definitions
  • Z0 Z_0 is on top means that the stack is effectively empty.

Formal Definition #

A Pushdown Automaton is a tuple \langle QQ , II , Γ\Gamma , δ\delta , q0q_0 , Z0Z_0 , FF \rangle , where:

  • QQ is a finite set of states.
  • II and Γ\Gamma are finite sets, the input and stack alphabets.
  • δ\delta is the transition function.
  • q0Qq_0 \in Q , the initial state.
  • Z0ΓZ_0 \in \Gamma , the initial stack symbol.
  • FQF \subseteq Q , the set of accepting states.

Configuration A configuration is a generalization of the notion of state. It shows:

  • the current state,
  • the portion of the input string that has not yet been read, and
  • the stack. It is a snapshot of the PDA.

Example #

Construct a PDA that accepts L={0n1nn0} L = \{0^n1^n | n \geq 0\}


Exercises #

Part I #

Build DPDAs that recognise the following languages:

  1. {anb2nn1} \{a^nb^{2n} \mid n \ge 1 \}
  2. P={xycyRxRx{a,b}y{d,e}x>0} P = \{xycy^Rx^R \mid x \in \{a, b\}^* \wedge y \in \{d, e\}^* \wedge \left\vert{x}\right\vert > 0 \} (where xRx^R , yRy^R are the reversed strings xx , yy ), the alphabet is I={a,b,c,d,e}I=\{a, b, c, d, e\}
  3. The language of nested and balanced brackets and parentheses. E.g. a string in the language: (([])())()(([])())() , a string that does not belong to the language: ([(]))()()([(]))()() – the alphabet is I={(,),[,]}I = \{(, ), [, ]\}

Part II #

Build DPDAs that recognise the following languages:

  1. L1={w{a,b}ϕ(w,a)=ϕ(w,b)}L_1 = \{w \in \{a, b\}^* \mid \phi(w, a) = \phi(w, b)\} where ϕ(s,c)\phi(s, c) is the number of occurrences of the character cc in the string ss
  2. L2={anbmambnn>0m>0}L_2 = \{a^nb^ma^mb^n \mid n > 0 \wedge m > 0\}
  3. L3=L2L_3 = L^*_2
  4. L4={an1bn1an2bn2an3bn3ankbnkk1ni11ik}L_4 = \{a^{n_1}b^{n_1}a^{n_2}b^{n_2}a^{n_3}b^{n_3} \ldots a^{n_k}b^{n_k} \mid k \ge 1 \wedge n_i \ge 1 \wedge 1 \le i \le k \}

Homework #

  1. Define a DPDA that recognises this language: L={anbnanb2nn0}L = \{a^nb^n \cup a^nb^{2n} \mid n \ge 0\}
  2. Construct a DPDA that recognises the language of well-formed parentheses of the arithmetic expressions (binary operations).

For simplicity, consider the alphabet I={a,(,),+}I = \{a, (, ), +\} - a single symbol aa that represents terms a,b,c,a, b, c, \ldots and a single operator ++ .

Examples of strings belonging to the language are:

  • (a+a)(a + a)
  • ((a)+(a+a))((a) + (a + a))
  • ((a+a))((a + a))