0% found this document useful (0 votes)
27 views13 pages

Toc Cae 2

Uploaded by

ajtrish19062005
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
0% found this document useful (0 votes)
27 views13 pages

Toc Cae 2

Uploaded by

ajtrish19062005
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 13

TOC

2M
1)Define PDA
The PDA can be defined as a collection of 7 tuples: M= (Q, ∑, δ, Γ, q0, Z, F)

Q: the finite set of states

∑: the finite set of input symbols

δ: Transition function which is used for moving from current state to next state.

Γ: a tape symbol which can be pushed and popped from the stack

q0: the initial state

Z: a start symbol which is in Γ.

F: a set of final states

Ex: δ(q,a,x)=(p,α)

from state ‘q’ with a input ‘a’, with stack symbol ‘z’, goes to state ‘p’, x is replaced by string ‘α’.

2)Advantages of PDA
• PDA can remember an infinite amount of information.

• Memory used – Stack

• A PDA is more powerful than FA

• Any language which can be acceptable by FA can also be acceptable by PDA.

• PDA also accepts a class of language which even cannot be accepted by FA

3)Define PDA Acceptance


1. Acceptance by Final State:

Let P =(Q, ∑, Γ, δ, q0, Z, F) be a PDA. The language acceptable by the final state can be defined as:

L(PDA) = {(q0, e, Z) ⊢ (q1, Z )}

2. Acceptance by Empty Stack:

Let P =(Q, ∑, Γ, δ, q0, Z, F) be a PDA. The language acceptable by empty stack can be defined as:

N(PDA) = {(q0, e, Z) ⊢ (q1, e )}


4)Explain Parsing
Parsing:

• To derive a string using the production rules for a grammar.


• It is used to check whether or not a string is syntactically correct.
• Parser takes the inputs and builds a parse tree.

Two types of parser:

• Top down Parser- Parsing starts from the top with the start symbol and derives a string using
a parse tree.

• Bottom up parser- Starts from the bottom with the string and comes to the start symbol
using a parse tree.

5) Define Pumping Lemma for Cfl:


• Pumping Lemma is used to prove that a language is not CFL.

• It should never be used to show a language is regular.

• For any language L, we break its strings into five parts and pump second and fourth
substring.

Procedure:

• Assume that L is context free.

• It has to have a pumping length(say n)

• Find a string ‘z’ in L such that |z]>=n.

• Divide z into uvwxy.

• Show that uviwxiy∉ L

6)Define Turing Machine


A TM can be formally described as a 7-tuple

(Q, ∑, δ, Γ, q0, B, F)

where –
7)Define Universal Turing Machine
A UTM is a TM, whose input consists of 2 parts

– A string specifying some other (special purpose) TM- T1

– A string Z(input to the TM- T1)

– The TM, Tu then simulates the processing of Z by T1

8)Advantages of TM
• A PDA can only access the top of its stack, whereas a TM can access any position on an
infinite tape.
• The infinite tape cannot be simulated with a single stack, so a PDA is less computationally
powerful.
• There are algorithms that can be programmed with a TM that cannot be programmed with
a PDA.

9) Validations in TM
• Storage in finite control
• Multiple track TM
• Multitape TM
• Multihead TM
• Multitape Multihead TM

10) Perform string concatenation for TM


12M
1)PDA- Construction
Design a PDA for accepting a language by empty stack {anbn | n>=1}.
Solution:
• In this language, n number of a's should be followed by n number of b’s.
• If we read single 'a', we will push a onto the stack.
• As soon as we read 'b' then for every single 'b' only one 'a' should get popped from the
stack.
Defining states:
q0 – push all a’s on to the stack.

q1 – when a ‘b’ encounters, pop ‘a’ from stack.

q2 – accepting state.

• Push Operation:

– δ(q0, a, Z) = (q0, aZ)

– δ(q0, a, a) = (q0, aa)

• Pop Operation:

– δ(q0, b, a) = (q1, ε)

– δ(q1, b, a) = (q1, ε)

• Accept

δ(q1, ε, Z) = (q2, Z)

Ip string validation: -aaabbb


δ(q0, aaabbb, Z) ⊢ δ(q0, aabbb, aZ)

⊢ δ(q0, abbb, aaZ)

⊢ δ(q0, bbb, aaaZ)

⊢ δ(q1, bb, aaZ)

⊢ δ(q1, b, aZ)

⊢ δ(q1, ε, Z)

⊢ δ(q2, ε) ACCEPTED
Design PDA to accept L={xCxr / x = {a, b}*}
Solution:
• Starts with a or b.
• The values before c will be reversed after c.
• For every a's and b's push them into STACK
• When 'c' comes no operations.
• Pop STACK for 'a' for 'a' and 'b' for 'b' after c.
Transition Diagram:

Transition function:
δ(q0, a, Z) = (q0, aZ)
δ(q0, a, a) = (q0, aa)
δ(q0, b, Z) = (q0, bZ)
δ(q0, b, b) = (q0, bb)
δ(q0, a, b) = (q0, ab)
δ(q0, b, a) = (q0, ba)
δ(q0, c, a) = (q1, a)
δ(q0, c, b) = (q1, b)
δ(q1, b, b) = (q1, ε)
δ(q1, a, a) = (q1, ε)
δ(q1, ε, Z) = (qf, Z)

ip string validation: Derive : abCba


δ(q0, abCba, Z) ⊢ δ(q0, bCba, aZ)
⊢ δ(q0, Cba, baZ)
⊢ δ(q1, ba, baZ)
⊢ δ(q1, a, aZ)
⊢ δ(q1, ε, Z)
⊢ δ(qf, ε) Accepted
2) Convert CFG TO PDA

Step 1: Convert the given productions of CFG into GNF.

Step 2: The PDA will only have one state {q}.

Step 3: The initial symbol of CFG will be the initial symbol in the PDA.

Step 4: For non-terminal symbol, add the following rule:

1. δ(q, ε, A) = (q, α) where α is productions of A

Step 5: For each terminal symbols, add the following rule:

1. δ(q, a, a) = (q, ε) for every terminal symbol


Step 1: Convert the given productions of CFG into GNF.

Step 2: The PDA will only have one state {q}.

Step 3: The initial symbol of CFG will be the initial symbol in the PDA.

Step 4: For non-terminal symbol, add the following rule:

1. δ(q, ε, A) = (q, α) where α is productions of A

Step 5: For each terminal symbols, add the following rule:

2. δ(q, a, a) = (q, ε) for every terminal symbol


3)Non- Deterministic PDA
• The Non-deterministic Push down Automata (NPDAs) are like finite automata (FA), except
they also have a stack memory where they can store an arbitrary amount of information.
• Have no transition or several transitions defined for input symbol.

NPDA can be described as the following −

• A finite set Q of states (& the start state & the set of accepting/final states).
• A finite set ∑ which is called the input alphabet.
• A finite set Γ which is called the stack alphabet (& the initial stack symbol $).
• A finite set of transition instructions (or a transition function T).

Design a non-deterministic PDA for accepting the language


L = {a^n b^n |* n>=1}
L= L = {ab, aabb, aaabbb, aaaabbbb, ......}
In each of the string, the number of a’s are followed by equal number of b’s.
Explanation – Here, we maintain the order of a’s and b’s. All a’s are followed by all b’s. Thus, we
need a stack along with the state diagram. The count of a’s and b’s is maintained by the stack.
We will take 2 stack alphabets:
T = { a, z }
Where, T= set of all the stack alphabet z = stack start symbol
Every time ‘a’ comes before ‘b’. When ‘a’ comes then push it in stack and if again ‘a’ comes then
also push it. After that, when ‘b’ comes then pop one ‘a’ from the stack each time. So, at the end if
the stack becomes empty then we can say that the string is accepted by the PDA.

Stack transition functions –


(q0, a, z) = (q0, az) (q0, a, a) = (q0, aa) (q0, b, a) = (q1, e ) = (q1, b, a) = (q1, e ) (q1, e, z) = (qf, z)
Where, q0 = Initial state qf = Final state e= indicates pop
4)Deterministic PDA
A deterministic pushdown automaton (DPDA) is a five-tuple M = (Q, σ, δ, q0, F) that is a DFA
augmented with a stack.
The main change from the DPDA to the PDA is, of course, the addition of non-determinism.
Design a deterministic PDA for accepting the language
L = {a^n b^n |* n>=1}
L= L = {ab, aabb, aaabbb, aaaabbbb, ......}
In each of the string, the number of a’s are followed by equal number of b’s.
So in the end of the strings if nothing is left in the STACK then we can say that language is accepted
in the PDA.
Steps:

1. Scan string from left to right


2. First input is 'a' and follow the rule:
3. on input 'a' and STACK alphabet Z, push the input 'a' into STACK as : (a,Z/aZ) and state will be
q0
4. Second input is 'a' and so follow the rule:
5. on input 'a' and STACK alphabet 'a', push the input 'a' into STACK as : (a,a/aa) and state will
be q0
6. Third input is 'b' and so follow the rule:
7. on input 'b' and STACK alphabet 'a', pop STACK with one 'a' as : (b,a/&epsiloon;) and state
will be now q1
8. Fourth input is 'b' and so follow the rule:
9. on input 'b' and STACK alphabet 'a' and state is q1, pop STACK with one 'a' as :
(b,a/&epsiloon;) and state will be q1
10. We reached end of the string, so follow the rule:
11. on input ε and STACK alphabet Z, go to final state(qf) as : (ε, Z/Z)

Transition Function
5)Construct TM
Construct TM for the language L ={anbn} where n>=1
Each ‘a' should convert to X and then move along with the input tape and convert b to Y. Now,
repeat this process for all a's and b’s.

q0 is the control

When qo meets a it changes to q1 and a is converted to X.

When q1 meets b it changes to q2 and b is converted to Y.

Steps:

Transition table:
Construct TM for the language L ={anb2n} where n>=1
6) Construct Universal Turning Machine
Steps:

• Write Directions as L =0 and R=00


• Write the states in asc order assign 0’s
• Write the table symbols in asc order 0 is 1st and B is last.
Steps:

• Write Directions as L =0 and R=00


• Write the states in asc order assign 0’s
• Write the table symbols in asc order 0 is 1st and B is last.

You might also like