Tcs Paper Soln

Embed Size (px)

Citation preview

  • TCS Sem V Computer Paper Solution By Prof Sameer Y Velankar (9324793514)

    Glorious Academy www.gloriousacademy.org

    Q1 a) Define the following terms

    1) Undecidability:

    An undecidable problem is a problemleads to a correct yes-or-no answer.

    Examples of undecidable problem

    the halting problem is a decision problem

    Given the description of an arbitrary

    running or will run forever.

    Determining if a context-free grammarundecidable problem.

    ii) Unrestricted Grammar :

    Unrestricted grammar is a formal grammargrammar's productions. This is the most general class of grammars in the

    An unrestricted grammar is a formal grammar

    symbols, is a set of terminal symbols

    are strings of symbols in andsymbol. As the name implies, there are no real restrictions on the types of production rules that grammars can have.

    iii) Pumping Lemma

    Pumping Lemma is used for proving that a language is

    L = {anbn / n >=1 } is not regular can be proved by using pumping lemma. The formal statement of pumping lemma is as follows :

    Let L be a regular language. Then there exists an integer

    called the "pumping length") can be written as

    following conditions:

    1. |y| 1;2. |xy| p3. for all i 0, xyiz L

    y is the substring that can be pumped (removed or repeated any number of times, and the resulting

    always in L). (1) means the loop y to be pumped must be of length at least one; (2) means the loop must occur

    within the first p characters. |x| must be smaller than

    restriction on x and z.

    TCS Sem V Computer Paper Solution By Prof Sameer Y Velankar (9324793514)

    www.gloriousacademy.org (Ph 9920030136 , 25621515)

    May 2013

    problem for which it is impossible to construct a single algorithm

    decision problem which can be stated as follows:

    Given the description of an arbitrary program and a finite input, decide whether the program finishes

    free grammar generates all possible strings, or if it is ambiguous.

    formal grammar on which no restrictions are made on the left and right sides grammar's productions. This is the most general class of grammars in the Chomsky hierarchy

    formal grammar , where is a set of nonterminal

    terminal symbols. is a set of production rules of the form

    and is not the empty string, and is a specially designated start symbol. As the name implies, there are no real restrictions on the types of production rules that

    Pumping Lemma is used for proving that a language is not regular. For example the language

    =1 } is not regular can be proved by using pumping lemma. The formal statement of pumping

    be a regular language. Then there exists an integer p such that every string w in L of length at least

    h") can be written as w = xyz (i.e., w can be divided into three substrings), satisfying the

    is the substring that can be pumped (removed or repeated any number of times, and the resulting

    to be pumped must be of length at least one; (2) means the loop must occur

    | must be smaller than p (conclusion of (1) and (2)), apart from that there is no

    TCS Sem V Computer Paper Solution By Prof Sameer Y Velankar (9324793514)

    Page 1

    algorithm that always

    and a finite input, decide whether the program finishes

    if it is ambiguous. Is

    on which no restrictions are made on the left and right sides of the Chomsky hierarchy,

    is a set of nonterminal

    where and

    is a specially designated start symbol. As the name implies, there are no real restrictions on the types of production rules that unrestricted

    . For example the language

    =1 } is not regular can be proved by using pumping lemma. The formal statement of pumping

    of length at least p (p is

    can be divided into three substrings), satisfying the

    is the substring that can be pumped (removed or repeated any number of times, and the resulting string is

    to be pumped must be of length at least one; (2) means the loop must occur

    (conclusion of (1) and (2)), apart from that there is no

  • TCS Sem V Computer Paper Solution By Prof Sameer Y Velankar (9324793514)

    Glorious Academy www.gloriousacademy.org (Ph 9920030136 , 25621515) Page 2

    In simple words, for any regular language L, any sufficiently long word w (in L) can be split into 3 parts. i.e. w =

    xyz , such that all the strings xykz for k0 are also in L.Q1 b) Define TM and its variants

    Definition

    Conceptually a Turing machine, like finite automata, consists of a finite control and a tape. At any time it is in one of the finite number of states. The tape has the left end but it extends infinitely to the right. It is also divided into squares and a symbol can be written in each square. However, tape of the turing machine has a read-write head and it can move left, right or stay at the same square after a read or write.

    Working of Turing machine

    Given a string of symbols on the tape, a Turing machine starts at the initial state. At any state it reads the symbol under the head, either erases it or replaces it with a symbol (possibly the same symbol). It then moves the head to left or right or does not move it and goes to the next state which may be the same as the current state. One of its states is the halt state and when the Turing machine goes into the halt state, it stops its operation.

    Formally

  • TCS Sem V Computer Paper Solution By Prof Sameer Y Velankar (9324793514)

    Glorious Academy www.gloriousacademy.org (Ph 9920030136 , 25621515) Page 3

    A Turing machine is a 5-tuple T = < Q, , , q0, > , whereQ is a finite set of states, which is assumed not to contain the symbol h. The symbol h is used to denote the halt state.

    is a finite set of symbols and it is the input alphabet.is a finite set of symbols containing as its subset and it is the set of tape

    symbols.q0 is the initial state.

    is the transition function but its value may not be defined for certain points.It is a mapping from

    Q X ( ) to ( Q ) X ( ) X { R , L , S } .

    Here R, L and S denote move the head right, left and do not move it, respectively. A transition diagram can also be drawn for a Turing machine. The states are represented by vertices and for a transition ( q, X ) = ( r, Y, D ) , where D represents R, L or S , an arc from q to r is drawn with label ( X/Y , D ) indicating that the state is changed from q to r, the symbol X currently being read is changed to Y and the tape head is moved as directed by D.

    Variants of Turing machine

    Variations of TM

    1) Stay option turing machine

    2) Semi infinite tape turing machine

    3) Off Line turing machine

    4) Multi tape turing machine

    5) Multidimensional turing machine

    6) Nondeterministic turing

    Q1 c) Chomsky hierarchy for formal languages

    The Chomsky hierarchy is a way of classifying formal grammars into four types

    The Chomsky hierarchy consists of the following levels:

    Type-0 grammars (unrestricted grammars) include all formal grammars. They generate exactly all languages that can be recognized by a Turing machine.

  • TCS Sem V Computer Paper Solution By Prof Sameer Y Velankar (9324793514)

    Glorious Academy www.gloriousacademy.org

    These languages are also known as theNote that this is different from the be decided by an always-

    Type-1 grammars (contextlanguages. These grammars have rules of the formnonterminal and , andstrings and may be empty, butallowed if does not appear on the right side of any rule. The languages described by these grammars are exactly all languages that can be recognized by a linear bounded automatontape is bounded by a constant times the length of the input.)

    Type-2 grammars (contextlanguages. These are defined by rules of the formnonterminal and a string of terminals and nonterminals. These are exactly all languages that can be recognized by a nondeterministic pushdown automatontheoretical basis for the syntax of m

    Type-3 grammars (regular grammarsgrammar restricts its rules to a single nonterminal on the leftright-hand side consisting of a single terminal, possibly followed (or precedebut not both in the same grammar) by a single nonterminal. The rulealso allowed here if does not appear on the right side of any rule. These languages are exactly all languages that can be decided by aautomaton. Additionally, this family of formal languages can be obtained by regular expressions. Regularpatterns and the lexical structure of programming languages.

    TCS Sem V Computer Paper Solution By Prof Sameer Y Velankar (9324793514)

    www.gloriousacademy.org (Ph 9920030136 , 25621515)

    These languages are also known as the recursively enumerable languagesNote that this is different from the recursive languages which can

    -halting Turing machine.context-sensitive grammars) generate the context

    . These grammars have rules of the formand strings of terminals and nonterminals. The

    may be empty, but must be nonempty. The ruledoes not appear on the right side of any rule. The languages

    described by these grammars are exactly all languages that can be recognized linear bounded automaton (a nondeterministic Turing machine whose

    tape is bounded by a constant times the length of the input.)context-free grammars) generate the context-

    . These are defined by rules of the form witha string of terminals and nonterminals. These

    are exactly all languages that can be recognized by a non-pushdown automaton. Context-free languages are the

    theoretical basis for the syntax of most programming languages.regular grammars) generate the regular languages

    grammar restricts its rules to a single nonterminal on the left-hand side and a hand side consisting of a single terminal, possibly followed (or precede

    but not both in the same grammar) by a single nonterminal. The ruledoes not appear on the right side of any rule. These

    languages are exactly all languages that can be decided by a finite state . Additionally, this family of formal languages can be obtained

    . Regular languages are commonly used to define search patterns and the lexical structure of programming languages.

    TCS Sem V Computer Paper Solution By Prof Sameer Y Velankar (9324793514)

    Page 4

    recursively enumerable languages. which can

    context-sensitive with a

    strings of terminals and nonterminals. The ule is

    does not appear on the right side of any rule. The languages described by these grammars are exactly all languages that can be recognized

    (a nondeterministic Turing machine whose

    -free a

    a string of terminals and nonterminals. These languages

    free languages are the .

    regular languages. Such a hand side and a

    hand side consisting of a single terminal, possibly followed (or preceded, but not both in the same grammar) by a single nonterminal. The rule is

    does not appear on the right side of any rule. These finite state

    . Additionally, this family of formal languages can be obtained languages are commonly used to define search

  • TCS Sem V Computer Paper Solution By Prof Sameer Y Velankar (9324793514)

    Glorious Academy www.gloriousacademy.org

    Grammar Languages

    Type-0 Recursively enumerableTuring machine

    Type-1 Context-sensitive Linear-bounded non

    Type-2 Context-free Non-deterministic

    Type-3 Regular Finite state automaton

    Q1 d) Closure properties of Regular

    If L1 and L2 are two different regular languages then

    a) Union of the two languages L1 and L2 (L1 U L2) is also regular.

    b) Intersection of two languages L1 and L2 (L1

    c) Complement of both the languages (~L1 and ~L2 ) i

    d) Reversal of a regular language is also regular.

    TCS Sem V Computer Paper Solution By Prof Sameer Y Velankar (9324793514)

    www.gloriousacademy.org (Ph 9920030136 , 25621515)

    Automaton Production rules (constraints)

    Turing machine (no restrictions)

    bounded non-deterministic Turing machine

    deterministic pushdown automaton

    Finite state automaton and

    Q1 d) Closure properties of Regular languages.

    If L1 and L2 are two different regular languages then

    a) Union of the two languages L1 and L2 (L1 U L2) is also regular.

    b) Intersection of two languages L1 and L2 (L1 L2) is also regular.c) Complement of both the languages (~L1 and ~L2 ) is also regular.

    d) Reversal of a regular language is also regular.

    TCS Sem V Computer Paper Solution By Prof Sameer Y Velankar (9324793514)

    Page 5

    Production rules (constraints)

  • TCS Sem V Computer Paper Solution By Prof Sameer Y Velankar (9324793514)

    Glorious Academy www.gloriousacademy.org (Ph 9920030136 , 25621515) Page 6

    For example

    let L1 = {a,aa,aaa,aaaa,aaaaa,} Clearly L1 is regular language and can be written as

    L1 = {an / n>=1 }

    Let L2 = {b,bb,bbb,bbbb,bbbbb,..} Clearly L2 is regular language and can be written as

    L2 = {bn / n>=1 }

    Then

    L1 U L2 = {a,aa,aaa,aaa, , b,bb,bbb,bbbb, } is union of both languages and is written as

    L1 U L2 = {an | bn / n>=1}

    Q2 a) What is ambiguous CFG. Give one example of ambiguous CFG

    An ambiguous grammar is a formal grammar for which there exists a string that can have more than one leftmost derivation, while an unambiguous grammar is a formal grammar for which every valid string has a unique leftmost derivation.

    The context free grammar

    A A + A | A A | a

    is ambiguous since there are two leftmost derivations for the string a + a + a:

    LeftMost Derivation 1

    A -> A + A

    a + A a + A + A a + a + A a + a + a which is the required string

    LeftMost Derivation 2

    A -> A + A

    A + A + A a + A + A a + a + A a + a + a which is the required string

  • TCS Sem V Computer Paper Solution By Prof Sameer Y Velankar (9324793514)

    Glorious Academy www.gloriousacademy.org (Ph 9920030136 , 25621515) Page 7

    Clearly there are 2 leftmost derivations for the string a+a+a. Hence the grammar is ambiguous.

    As another example, the grammar is ambiguous since there are two parse trees for the string a + a a:

    Q 2 b) Let G be a CFG, find leftmost, rightmost derivations and parse tree for a string 00110101

    S -> 0B | 1A

    A -> 0 | 0S | 1AA

    B -> 1 | 1S | 0BB

    Leftmost Derivation of 00110101

    S -> 0B

    00BB using rule B->0BB 001B using rule B->1 0011S using rule B->1S 00110B using rule S->0B 001101S using rule B->1S 0011010B using rule S->0B 00110101 using rule B->1

    Rightmost Derivation of 00110101

    S -> 0B

    00BB using rule B -> 0BB 00B1 using rule B->1 001S1 using rule B->1S 0011A1 using rule S->1A 00110S1 using rule A->0S 001101A1 using rule A->1A 00110101 using rule A->0

  • TCS Sem V Computer Paper Solution By Prof Sameer Y Velankar (9324793514)

    Glorious Academy www.gloriousacademy.org (Ph 9920030136 , 25621515) Page 8

    Parse Tree for derivation of 00110101

    S

    0 B

    0 B B

    1 1 S

    0 B

    1 S

    0 B

    1

    Q3 a) Explain CNF and GNF with examplesChomsky Normal Form : A context free grammar is in Chomsky Normal Form (CNF) if every rule is of the form

    A -> BC or

    A -> a

    Where a is a terminal and A,B,C are nonterminals.

    For example : The given grammar is in CNF

    S -> AB | BC rule 1

    A -> AB | a rule 2

    B -> BA | b rule 3

    C -> c rule 4

    Greibach Normal Form : A context free grammar is in Greibach Normal Form (GNF) if every rule is of the form

    A -> a orA -> a

  • TCS Sem V Computer Paper Solution By Prof Sameer Y Velankar (9324793514)

    Glorious Academy www.gloriousacademy.org (Ph 9920030136 , 25621515) Page 9

    Where a is a terminal and A is a nonterminal and is list of nonterminals . = (N)*For example : The given grammar is in GNF

    S -> aAB | bBC rule 1

    A -> aAB | a rule 2

    B -> bBA | b rule 3

    C -> c rule 4

    Q 3 b) Give formal definition of RE and design DFA for regular expression (a+b)* aba (a+b)*

    Formal definition of RE

    Regular expression is a method used to specify Regular Language. Regular expression over an alphabet can be defined asa) every symbol a of is a regular expressionb) (empty string) is a regular expressionc) if r1 and r2 are regular expressions than

    r1 + r2 is a regular expression (ORing)

    r1 . r2 is a regular expression (Concatenation)

    r1* is a regular expression (Kleenes closure)

    Given RE is

    (a + b)* aba (a+b)*

    To construct DFA we need 2 steps Step 1 : Draw NFA for given REStep 2 : Convert NFA into equivalent DFAStep 1 : Draw NFA for given RE

    This NFA has following transition tableQ\ a bq0 { q0, q1 } { q0}q1 { } { q2}q2 { q3} { }q3 { q3} { q3}

    q q q qa b a

    a, ba, b

    q3

  • TCS Sem V Computer Paper Solution By Prof Sameer Y Velankar (9324793514)

    Glorious Academy www.gloriousacademy.org (Ph 9920030136 , 25621515) Page 10

    Step 2 : Convert NFA to DFA

    (a) Initial state of DFA is same as initial state of NFA q0

    (b) Find out transitions for symbol a and b for state q. (q, a) = { q, q} This is a new state of DFA (q, b) = { q}

    (c) Find out transitions for symbols a & b for state qq

    ( qqa) = ( q, a) U ( qa) ( qqa) = ( q, q) U { }

    ( qqa) = { q, q}AND

    ( qqb) = ( q, b) U ( qb) ( qqb) = {q} U { q2 }

    ( qqb) = { q, q} Now state of DFA

    (d) Find out transitions for state qqfor symbols a & b

    ( qq2a) = ( q, a) U ( q2a) ( qq2a) = {q, q1} U { q3}

    ( qq2a) = { q, q1, q3} Now state of DFAAND

    ( qq2b) = ( q, b) U ( q2b) ( qq2b) = {q} U { }

    ( qq2b) = { q}

    q

    q qqa

    b

    q qq qqa b

    b a

  • TCS Sem V Computer Paper Solution By Prof Sameer Y Velankar (9324793514)

    Glorious Academy www.gloriousacademy.org (Ph 9920030136 , 25621515) Page 11

    (e) Find out transitions for state qqq3 for symbols a and b

    ( qq1q3, a) = ( q, a) U ( q1a) U ( q3a) ( qq1q3, a) = { q, q U {} U { q3}

    ( qq1q3, a) = { q, q1, q3} AND

    ( qq1q3, b) = ( q, b) U ( q1b) U ( q3b) ( qq1q3, b) = { q U { q2} U { q3}

    ( qq1q3, b) = { q, q2, q3} New state

    (f) Find out transitions for state qq2q3 for symbols a and b

    ( qq2q3, a) = ( q, a) U ( q2a) U ( q3a) ( qq2q3, a) = { q, q U {q3 } U { q3}

    ( qq2q3, a) = { q, q1, q3}

    q qq qq q

    a

    b a

    b

    qqq

    b

    a

    q qq qq qa b a qqq

    b

    qqq

    b

    ba

  • TCS Sem V Computer Paper Solution By Prof Sameer Y Velankar (9324793514)

    Glorious Academy www.gloriousacademy.org (Ph 9920030136 , 25621515) Page 12

    AND

    ( qq2q3, b) = ( q, b) U ( q2b) U ( q3b) ( qq2q3, b) = { q U { } U { q3}

    ( qq2q3, b) = { q, q3} New state of DFA(g) Find out transitions for state qq3

    ( qq3, a) = ( q, a) U ( q3a) ( qq3, a) = { q, q} U ( q3)

    ( qq3, a) = { q, q1, q3} AND

    ( qq3, b) = ( q, b) U ( q3b) ( qq3, b) = { q} U {q3}

    ( qq3, b) = { q, q3} Now there are no more new states. Hence the final NFA.

    The final states of DFA are those states which contain q3 state of NFA.

    a

    ab

    q qq qq qa b a

    b

    b

    a

    qqq

    qqq

    qq

    b

    a

    b

  • TCS Sem V Computer Paper Solution By Prof Sameer Y Velankar (9324793514)

    Glorious Academy www.gloriousacademy.org (Ph 9920030136 , 25621515) Page 13

    Q 3 c) Using pumping Lemma prove that following language is not regular

    L = {anbn / n >= 1}

    1. Let L be regular. Then there exists a DFA which will accept this language. Let P be the pumping length

    2. Choose a string w = apbp . Clearly |w| >= p 3. Decompose w into xyz, but since |xy|

  • TCS Sem V Computer Paper Solution By Prof Sameer Y Velankar (9324793514)

    Glorious Academy www.gloriousacademy.org (Ph 9920030136 , 25621515) Page 14

    Step c : NFA for (a + bb)* will be

    Step d : Now consider (ba* + ) NFA for b NFA for a*

    NFA for (b a*) with be concatenation of NFA of b & NFA of a*

    b

    a

    ab

    a

    b b

  • TCS Sem V Computer Paper Solution By Prof Sameer Y Velankar (9324793514)

    Glorious Academy www.gloriousacademy.org (Ph 9920030136 , 25621515) Page 15

    Step e : NFA for (ba* + ) is

    Step f : Finally NFA for entire RE (a + bb*) (ba* + ) will be concatenation of step c & step e.

    Q5 a) Find out the languages defined by the following grammar

    The grammar recoginizes all strings with even number of 1s and odd number of 0s.

    The derivation of any string must start at start symbol S. This symbol can derive 0A or 1C. Note that only A can be substituted with E symbol. Hence smallest string that can be derived from the above grammar is 0.

    S -> 0A

    0Clearly this string has odd 0s.

    ab

    a

    b b

    b a

  • TCS Sem V Computer Paper Solution By Prof Sameer Y Velankar (9324793514)

    Glorious Academy www.gloriousacademy.org (Ph 9920030136 , 25621515) Page 16

    On the other hand , suppose we use S -> 1C as the first point in the derivation. Then there is no way to terminate the derivation except by bringing A into our derivation which necessarily brings odd number of 0s.

    As other Example :

    consider derivation of string 1111011

    S -> 1C

    11S 111C 1111S 11110A 111101B 1111011A 1111011 Clearly this string has even number of 1s and odd number of 0s.

    ii)

    S -> 0A | 1C

    A -> 0S | 1B

    B -> 0C | 1A | C -> 0B | 1S

    This grammar accepts all strings with odd number of 1s and odd number of 0s.

    (Left as exercise to prove)

    Q 5 b) Design PDA to accept language

    L = {an bm an | m,n >= 1}

    The push Down automata M is 7 tuple

    M = ( Q, , , , q0, z0, F )For the language L = n m na b a |m,n 1We have

    = { a, b }The stack of PDA will store X for every a. The initial stack symbol is z0.

    Hence = { X, z0 }The idea = To recognize the language L = n m na b a |m,n 1We will push one X in the stack when ever PDA reads a.

  • TCS Sem V Computer Paper Solution By Prof Sameer Y Velankar (9324793514)

    Glorious Academy www.gloriousacademy.org (Ph 9920030136 , 25621515) Page 17

    For example if the string w = aabbbaa. Then after reading first 2 a s the stack will be

    X 2 X for 2 as

    X

    Z0 initial stack symbol

    Now for the next 3 bs our PDA will not change the stack. In other words we will ignore or skip all bs.

    Finally for last 2 as we will pop one X for every a

    Hence the stack will contain only Z0 at the end of process. Which means that number of as In the begining are equal to number of as at the end.

    The state diagram for PDA is

    The PDA M has

    Q = { q0, q1, q2, q3 }

    q0 = initial state

    = { a, b } = { X, Z0 }

    Z0 = initial stack symbol.

    F = { q3 } final state

    : transition function is : ( q0, a, Z0 ) = ( q0, XZ0 )

    : ( q0, a, X ) = ( q0, XX ) : ( q0, b, X ) = ( q1, X ) : ( q1, b, X ) = ( q1, X ) : ( q1, a, X) = ( q0, ) : ( q2, a, X) = ( q2, ) : ( q2, , Z0) = ( q3, Z0 )

    a, X / q q q

    b, X / X a, X / a, Z0 / XZ0

    b, X / X

    q

    , Z0 / Z0a, X / XX

  • TCS Sem V Computer Paper Solution By Prof Sameer Y Velankar (9324793514)

    Glorious Academy www.gloriousacademy.org (Ph 9920030136 , 25621515) Page 18

    Working of this PDA can be shown by considering string w = aabbbaa. The initial state of PDA is q0 and initial stack symbol is

    ( q0 aabbbaa, Z0)

    ( q0 aabbbaa, XZ0)

    ( q0 aabbbaa, XXZ0)

    ( q1 aabbbaa, XXZ0)

    ( q1 aabbbaa, XXZ0)

    ( q1 aabbbaa, XXZ0)

    ( q2 aabbbaa, XZ0)

    ( q2 aabbbaa_, Z0)

    ( q3 aabbbaa_, Z0)

    q3 is the, final state & the i/p is over. Therefore string aabbbaa is valid & accepted.

    Q 6 a) Differentiate between Mealy and Moore machine with proper example. Carry out conversion of Moore MIC to Mealy MIC

    Difference between Mealy and Moore Machine

    Moore Machine Mealy Machine

    1 It is FSM in which output depends only on the current state.

    It is FSM in which output depends on thecurrent state, and current input

    2. For a Moore Machine M=(QqWhere Q= finite set of states. =Finite set of i/p symbol = Transfer function: Q x Q

    =output function: Q q0 = Initial State

    = finite set of output symbols

    For a Mealy Machine M=(QqWhere Q= finite set of states. =Finite set of i/p symbol = Transfer function: Q x Q

    =output function: Q x

    q0 = Initial State

    = finite set of output symbols

    3. If the input given to Moore machine has n symbols, then output of Moore machine has n+1 symbols. Therefore length of output is one more then length of input

    If the input given to mealy machine has n symbols, then output of mealy machine has n symbols. Therefore length of output equal to length of the input.

  • TCS Sem V Computer Paper Solution By Prof Sameer Y Velankar (9324793514)

    Glorious Academy www.gloriousacademy.org (Ph 9920030136 , 25621515) Page 19

    Following Moore machine which with output A if input ends 11, output B if input ends with 10 output C otherwise.

    The equivalent Mealy machine is

    Q 6 b) Design a Turing machine that accepts the language L = {anbn | n >= 1}

    TM = ( Q , , , B, F )Where = { a, b } = { X, , B, a, b } ( tape symbols)

    The idea : every a will be over written as X and every b will be over written as .The TM will do multiple scans of the input (from left to right and right to left) as follows

    B a a b b B

    | X

    Replace first a with X and move forward till we get first b

    1/A

    1

  • TCS Sem V Computer Paper Solution By Prof Sameer Y Velankar (9324793514)

    Glorious Academy www.gloriousacademy.org (Ph 9920030136 , 25621515) Page 20

    B X a b b B

    | y

    Replace b with y & move backward till we get X. On reaching X move one symbol right & change a to X.

    B X a y b B | X

    This process goes on till all as are changed to X & b s are changed to y. finally the TM will check if there are any pending a or bs.

    Q7 Write short note on ant four

    a) Recursive and Recursively enumerable language

    Recursive and Recursively enumerable languages

    Recursively Enumerable Languages

    A TM accepts a string w if the TM halts in a final state. A TM rejects a string w if the TM halts in a nonfinal state or the TM never halts.

    A language L is recursively enumerable if some TM accepts it.

    A language L is recursive if some TM accepts it and halts on every input. Note: the complement of a recursive language is also recursive.

    L is recursive implies L is recursively enumerable.

    q q qa / XR b/ YL

    q q

    Y / YR

    a / aR

    Y/YRa / aL

    Y / YL

    Y / YR

    B / BS

    X/ XR

  • TCS Sem V Computer Paper Solution By Prof Sameer Y Velankar (9324793514)

    Glorious Academy www.gloriousacademy.org (Ph 9920030136 , 25621515) Page 21

    The Halting problem is r.e. but not recursive. Indeed one can run the Turing Machine and accept if the machine halts, hence it is r.e. On the other hand the problem is undecidable.

    Some other r.e. language that are not recursive :

    post correspondance problem Travelling salesman problem Satisfiability problem

    b) Intractable ProblemA problem is called Intractable if all algorithms to solve it take exponential time instead of polynomial time.Example: the Towers of HanoiConsider the following problem:

    Move the three rings, which are piled up in descending order of magnitude, from peg A to peg C, possibly using peg B in the process, moving rings one at a time, and at no time allowing a larger ring to rest on top of a smaller one

    The puzzle above has the solution:move topmost ring from A to C;move topmost ring from A to B;move topmost ring from C to B;move topmost ring from A to C;move topmost ring from B to A;move topmost ring from B to C;move topmost ring from A to C;

    Note that for number of rings = 3 , the total number of moves necessary = 7Which can be written as 2rings-1.

  • TCS Sem V Computer Paper Solution By Prof Sameer Y Velankar (9324793514)

    Glorious Academy www.gloriousacademy.org (Ph 9920030136 , 25621515) Page 22

    We cant just imagine solving this puzzle if number of rings were in a large number. for example if number of rings = 64 then the number of moves = 264 - 1.

    c) Simplication of CFG

    CFG can be simplified by

    i) Eliminating useless symbols

    ii) Eliminating E-productions

    iii) Eliminating Unit-productions

    Eliminating Useless Symbols from a CFG

    A symbol X is useful for a CFG if there is a derivation of the form S * X * w for some string of terminals w. In other words we say that X is useful if we can derive some terminal string w from X.

    If X is not useful, then we say X is useless. Such useless symbols can be removed from CFG. The modified CFG will also generate the same language as the original CFG.

    Symbol X is useful if 1. X can be used to derive some string of terminals.2. X must be reachable; that is, there needs to be a derivation of the form S * X

    where and are strings of nonterminals and terminals. To eliminate useless symbols from a grammar, we

    1. identify the non generating symbols (that is symbols which do not generate terminal string w) and eliminate all productions containing one or more of these symbols, and then

    2. eliminate all productions containing symbols that are not reachable from the start symbol.

    In the grammar

    S AB | aA b

    We see that S a. So S is a generating symbol because S derives terminal a.We see that A b. So A is a generating symbol because A derives terminal b.But B does not derive any terminal string directly or indirectly.

    S, A are generating. B is not generating.

    Eliminating the productions containing the nongenerating symbols we getS aA bNow we see A is not reachable from S, so we can eliminate the second production to getS a This is final Simplified CFG

  • TCS Sem V Computer Paper Solution By Prof Sameer Y Velankar (9324793514)

    Glorious Academy www.gloriousacademy.org (Ph 9920030136 , 25621515) Page 23

    Eliminating -productions from a CFG

    Consider a CFG given as S aA ; A a | . Note that this CFG will generate a language of strings that begin with a. The empty string cannot be part of the language generated by this CFG. Hence if L is the language generated by the above given CFG, then we see that L does not have although there is a production rule A . Such productions can be removed from the original CFG without changing the Language generated.

    A nonterminal A in a grammar is nullable if A * . The nullable nonterminals can be determined iteratively. We can eliminate all -productions in a grammar as follows:

    o Eliminate all productions with bodies.o Suppose A X1X2 ... Xk is a production and m of the k Xi's are nullable. Then add

    the 2m versions of this production where the nullable Xi's are present or absent. (But if all symbols are nullable, do not add an -production.)

    Let us eliminate the -productions from the grammar G

    S ABA aAA | B bBB | S, A and B are nullable.

    For the production S AB we add the productions S A | BFor the production A aAA we add the productions A aA | aFor the production B bBB we add the productions B bB | bThe resulting grammar H with no -productions isS AB | A | BA aAA | aA | aB bBB | bB | b

    Eliminating Unit Productions from a CFG

    A unit production is one of the form A B where both A and B are nonterminals. Let us assume we are given a grammar G with no -productions. From G we can create an equivalent grammar H with no unit productions as follows.

    Removal of Unit Productions

    If we have a production A B (which is a unit production) and B is not a unit production then add a production A .

    Consider one example which is the standard grammar G for arithmetic expressions:

  • TCS Sem V Computer Paper Solution By Prof Sameer Y Velankar (9324793514)

    Glorious Academy www.gloriousacademy.org (Ph 9920030136 , 25621515) Page 24

    E E + T | TT T * F | FF ( E ) | aThe unit productions in this CFG are

    E TT FTo remove these unit productions we can replace T on the right side of production E T with E T * F | F (because T T * F | F)But now we have added one more unit production E F which can be written as E ( E ) | a because F ( E ) | a.Similar process can be done on the unit production T F The equivalent grammar H with no unit productions is:E E + T | T * F | ( E ) | aT T * F | ( E ) | aF ( E ) | a

    d) Decision properties of regular languages

    Decision Properties of Regular languages

    Given regular languages, specified in any one of the four methods (regular expression, DFA, NFA , NFA with E-moves) , can we develop algorithms that answer the following questions:1. Is the language empty?2. Is the language finite?3. Is a given string in the language?

    The term Decision property means what we can conclude from regular expression OR DFA. In other words If regular expression OR DFA is given what can we know about the language accepted

    For example if R is the regular expression. We want to find out

    i) Membership : Is the string w in Language recognized by regular expression R.

    ii) Emptiness : Is the language recognized by regular expression empty.

    iii) Finiteness : Is the language recognized by regular expression finite.

  • TCS Sem V Computer Paper Solution By Prof Sameer Y Velankar (9324793514)

    Glorious Academy www.gloriousacademy.org (Ph 9920030136 , 25621515) Page 25

    e) Rice theorem

    Rice's theorem states any nontrivial property about the language recognized by a Turing machine is undecidable.

    An example of a property of Turing-recognizable languages could be, say, the property of being a regular language.

    The following problems are all undecidable. Given Turing machine M,1. does M accept the empty string?2. does M accept no inputs at all?3. does M accept all inputs?

    4. is L(M) regular ? Context-free ? Turing-decidable?

    Dec 2012

    Q1 (a) What is finite Automata? Give the finite automata M for accepting (a, b)* (b aaa)

    Finite Automata M is defined as a machine with finite number of states. Such a machine reads input string and recognizes whether the string is ACCEPTED or REJECTED by the language or not.

    Eg : We can design finite automata which will accept string over {0, 1} only if the strings begin with 0 and end with 1.

    In general finite automata M is defined as 5 tuple.

    M = { Q , , q0, F }where Q = finite set of states

    = finite set of i/p symbols = transition function = Q x Qq0 = initial state

    F = set of final states.

    FA can be any of following types

    (a) DFA (Deterministic finite automata)

    (b) NFA (Non deterministic finite automata)

    (c) NFA with moves

  • TCS Sem V Computer Paper Solution By Prof Sameer Y Velankar (9324793514)

    Glorious Academy www.gloriousacademy.org

    NFA for the language (a, b)* (baaa) is

    Q1 (b) xplain Chomsky Heivarchy with language used forms of productions in grammer & accepting devices.

    The Chomsky hierarchy is a way of classifying formal grammars into four types

    The Chomsky hierarchy consists of the following levels:

    Type-0 grammars (unrestricted grammarsexactly all languages that can be recognized by aknown as the recursively enumerable languagesrecursive languages which can be

    Type-1 grammars (context-sensitive grammarsThese grammars have rules of the formand strings of terminals and nonterminals. The stringsmust be nonempty. The ruleany rule. The languages described by these grammars are exactly all languages that can be recognized by a linear bounded automatonis bounded by a constant times the length of the input.)

    Type-2 grammars (context-free grammarsdefined by rules of the formnonterminals. These languages are exactly all languages deterministic pushdown automatonthe syntax of most programming languages

    Type-3 grammars (regular grammarsrestricts its rules to a single nonterminal on the leftconsisting of a single terminal, possibly followed (or preceded, but not both in the same grammar) by a single nonterminal. The ruleappear on the right side of any rule. These languages are exactly all languages that can be decided by a finite state automatonobtained by regular expressionspatterns and the lexical structure of programming languages.

    bq0

    TCS Sem V Computer Paper Solution By Prof Sameer Y Velankar (9324793514)

    www.gloriousacademy.org (Ph 9920030136 , 25621515)

    NFA for the language (a, b)* (baaa) is

    xplain Chomsky Heivarchy with language used forms of productions in grammer

    is a way of classifying formal grammars into four types

    The Chomsky hierarchy consists of the following levels:

    unrestricted grammars) include all formal grammars. They generate exactly all languages that can be recognized by a Turing machine. These languages are also

    recursively enumerable languages. Note that this is different frwhich can be decided by an always-halting Turing machine

    sensitive grammars) generate the context-sensitive languagesThese grammars have rules of the form with a nonterminal and

    strings of terminals and nonterminals. The strings and may be empty, butmust be nonempty. The rule is allowed if does not appear on the right side of any rule. The languages described by these grammars are exactly all languages that can be

    linear bounded automaton (a nondeterministic Turing machine whose tape is bounded by a constant times the length of the input.)

    free grammars) generate the context-free languageswith a nonterminal and a string of terminals and

    nonterminals. These languages are exactly all languages that can be recognized by a nonpushdown automaton. Context-free languages are the theoretical basis for

    programming languages.regular grammars) generate the regular languages. Such a grammar

    restricts its rules to a single nonterminal on the left-hand side and a right-hand side consisting of a single terminal, possibly followed (or preceded, but not both in the same

    by a single nonterminal. The rule is also allowed here ifappear on the right side of any rule. These languages are exactly all languages that can be

    finite state automaton. Additionally, this family of formal languages can be regular expressions. Regular languages are commonly used to define search

    patterns and the lexical structure of programming languages.

    a a aq1 q2 q3

    TCS Sem V Computer Paper Solution By Prof Sameer Y Velankar (9324793514)

    Page 26

    xplain Chomsky Heivarchy with language used forms of productions in grammer

    ) include all formal grammars. They generate . These languages are also

    . Note that this is different from the uring machine.

    sensitive languages. a nonterminal and ,may be empty, but

    appear on the right side of any rule. The languages described by these grammars are exactly all languages that can be

    (a nondeterministic Turing machine whose tape

    free languages. These are a string of terminals and

    that can be recognized by a non-free languages are the theoretical basis for

    . Such a grammar hand side

    consisting of a single terminal, possibly followed (or preceded, but not both in the same does not

    appear on the right side of any rule. These languages are exactly all languages that can be . Additionally, this family of formal languages can be

    define search

    q4

  • TCS Sem V Computer Paper Solution By Prof Sameer Y Velankar (9324793514)

    Glorious Academy www.gloriousacademy.org

    Grammar Languages

    Type-0 Recursively enumerable Turing machine

    Type-1 Context-sensitive Linearmachine

    Type-2 Context-free Non

    Type-3 Regular Finite state automaton

    Q1 (c) Differential between mealy & moore Moore Machine

    1 It is FSM in which output depends only on the current state.

    2. For a Moore Machine M=(QWhere

    TCS Sem V Computer Paper Solution By Prof Sameer Y Velankar (9324793514)

    www.gloriousacademy.org (Ph 9920030136 , 25621515)

    Automaton Production rules (constraints)

    Turing machine

    Linear-bounded non-deterministic Turing machine

    Non-deterministic pushdown automaton

    Finite state automaton and

    Differential between mealy & moore machines.Mealy Machine

    It is FSM in which output depends only on It is FSM in which output depends on thcurrent state, and current input

    q For a Mealy Machine M=(QWhere

    TCS Sem V Computer Paper Solution By Prof Sameer Y Velankar (9324793514)

    Page 27

    Production rules (constraints)

    (no restrictions)

    It is FSM in which output depends on thecurrent state, and current inputFor a Mealy Machine M=(Qq

  • TCS Sem V Computer Paper Solution By Prof Sameer Y Velankar (9324793514)

    Glorious Academy www.gloriousacademy.org (Ph 9920030136 , 25621515) Page 28

    Q= finite set of states. =Finite set of i/p symbol = Transfer function: Q x Q

    =output function: Q q0 = Initial State

    = finite set of output symbols

    Q= finite set of states. =Finite set of i/p symbol = Transfer function: Q x Q

    =output function: Q x

    q0 = Initial State

    = finite set of output symbols

    3. If the input given to Moore machine has n symbols, then output of Moore machine has n+1 symbols. Therefore length of output is one more then length of input

    If the input given to mealy machine has n symbols, then output of mealy machine has n symbols. Therefore length of output equal to length of the input.

    Q1 (d) Give example & explain ambiguous context free grammer.

    An ambiguous grammar is a formal grammar for which there exists a string that can have more than one leftmost derivation, while an unambiguous grammar is a formal grammar for which every valid string has a unique leftmost derivation.

    The context free grammar

    A A + A | A A | a

    is ambiguous since there are two leftmost derivations for the string a + a + a:

    LeftMost Derivation 1

    A -> A + A

    a + A a + A + A a + a + A a + a + a which is the required string

    LeftMost Derivation 2

    A -> A + A

  • TCS Sem V Computer Paper Solution By Prof Sameer Y Velankar (9324793514)

    Glorious Academy www.gloriousacademy.org (Ph 9920030136 , 25621515) Page 29

    A + A + A a + A + A a + a + A a + a + a which is the required string

    As another example, the grammar is ambiguous since there are two parse trees for the string a + a a:

    Q2 a) Design a finite state machine that adds 2 binary numbers of equal length

    We want to construct a finite state machine that will add two numbers.

    The input is two binary numbers, (xnx1x0)2 and (yny1y0)2

    At each step, we can compute (xi+yi) starting with (x0+y0).

    If (xi+yi)=0, we output 0.

    If (xi+yi)=1, we output 1.

    If (xi+yi)=2, we have a problem.

    The problem is we need a carry bit.

    In fact, our computation needs to know the carry bit at each step (so we compute xi+yi+ci at each step), and be able to give it to the next step.

    We can take care of this by using states to represent the carry bit.

    We will use the following states

    State S0 occurs if the carry bit is 0

    State S1 occurs if the carry bit is 1

    Since when we begin the computation, there is no carry, we can use S0 as the start state,

    So, how does which state we are in affect the output?

    If we are in state S0 (we have a carry of 0)

    If (xi+yi)=0, we output 0, and stay in state S0

    If (xi+yi)=1, we output 1, and stay in state S0

  • TCS Sem V Computer Paper Solution By Prof Sameer Y Velankar (9324793514)

    Glorious Academy www.gloriousacademy.org (Ph 9920030136 , 25621515) Page 30

    If (xi+yi)=2, we output 0, and go to state S1

    If we are in state S1 (we have a carry of 1)

    If (xi+yi +1)=1, we output 1, and go to state S0

    If (xi+yi +1)=2, we output 0, and stay in state S1

    If (xi+yi +1)=3, we output 1, and stay in state S1

    From the previous observations, we can construct the state table and state diagrams

    for the binary adder

    Next State Output

    Input Input

    State 00 01 10 11 00 01 10 11

    S0 S0 S0 S0 S1 0 1 1 0

    S1 S0 S1 S1 S1 1 0 0 1

  • TCS Sem V Computer Paper Solution By Prof Sameer Y Velankar (9324793514)

    Glorious Academy www.gloriousacademy.org (Ph 9920030136 , 25621515) Page 31

    Q2 (b) Give rules for defining languages associated with any regular expression.

    Let L1 = all words beginning with a

    Let L2 = all words ending with a

    What is L1 intersection L2?

    Q3 (a) Give the statement for pumping lemma for regular langauages.

    Q3 (b) Construct NFA with moves for (i) (00 + 1 )* (10)*

    (ii) (( 0 + 1 )* 10 + ( 00 )* ( 11 )* )*

    (i) (00 + 1 )* (10)*

    0 0

    1 1 0

    0

  • TCS Sem V Computer Paper Solution By Prof Sameer Y Velankar (9324793514)

    Glorious Academy www.gloriousacademy.org (Ph 9920030136 , 25621515) Page 32

    (ii) (( 0 + 1 )* 10 + ( 00 )* ( 11 )* )*

    Q5 a) Explain basic complexity classes

    P problems are questions that have a yes/no answer and can be easily solved by a computer. For example, determining whether a number is prime is a relatively easy problem to solve.

    Problems with solution times bound by a polynomial of a small degree are called P problems Most searching and sorting algorithms are P problems P problems are also called tractable algorithms For example, Binary search performs in O(lgn) , Quick sorting performs in O(nlogn)

    NP problems are questions that have yes/no answers that are easy to verify, but are hard to solve. And by hard, we mean it would take years, decades or centuries for our computer to come up with an answer.

    0

    1 1

    1 0

    0

    1

    0

  • TCS Sem V Computer Paper Solution By Prof Sameer Y Velankar (9324793514)

    Glorious Academy www.gloriousacademy.org (Ph 9920030136 , 25621515) Page 33

    Problems with best known algorithms not bound by a polynomial Hard, or intractable problems Traveling salesperson , knapsack problem None of the problems in this group has been solved by any polynomial time algorithm

    For example, the travelling salesman problem is trying to figure out the shortest trip through a bunch of cities, visiting each city only once.

    Let's say we have a question, can we visit these 500 cities in the state and spend less than 3000 miles on the road? If we magically show an itinerary that takes us to all those 500 cities, you can easily verify whether that itinerary is less than 3000 miles. BUT, trying to come up with that itinerary in the first place is really hard for computers.

    NP-complete problems are special kinds of NP problems. You can take any kind of NP problem and twist and convert it until it looks like an NP-complete problem.

    For example, the knapsack problem is NP. It can ask what's the best way to fill a knapsack if you had n number of objects and that you can't carry all of them in the bag.

    We can convert Knapsack problem into a travelling salesman problem. In fact, any NP problem can be made into a travelling salesman problem, which makes travelling salesman NP-complete.

    A problem that is NP-complete can be solved in polynomial time if all other NP-complete problems can also be solved in polynomial time

    NP-Hard problems are worst than NP problems. Even if someone suggested you a solution to a NP-Hard problem, it'd still take forever to verify if they were right.

    If an NP-hard problem can be solved in polynomial time then all NP-complete problems can also be solved in polynomial time

    Q 5 b) Explain NP hard and NP complete language

    Q 5 c) Using pumping lemma prove that anbn is regular or not.

    Prove that L = {anbn: n 0} is not regular.

    5. Let L be regular. Then there exists a DFA which will accept this language. Let P be the pumping length

    6. Choose a string w = apbp . Clearly |w| >= p

  • TCS Sem V Computer Paper Solution By Prof Sameer Y Velankar (9324793514)

    Glorious Academy www.gloriousacademy.org (Ph 9920030136 , 25621515) Page 34

    7. Decompose w into xyz, but since |xy|

  • TCS Sem V Computer Paper Solution By Prof Sameer Y Velankar (9324793514)

    Glorious Academy www.gloriousacademy.org (Ph 9920030136 , 25621515) Page 35

    The next step is to convert a NFA to a DFA (called subset construction). Suppose that you assign a number to each NFA state. The DFA states generated by subset construction have sets of numbers, instead of just one number. For example, a DFA state may have been assigned the set {5,6,8}. This indicates that arriving to the state labeled {5,6,8} in the DFA is the same as arriving to the state 5, the state 6, or the state 8 in the NFA when parsing the same input.

    First we need to handle transitions that lead to other states for free (without consuming any input). These are the transitions. We define the closure of a NFA node as the set of all the nodes reachable by this node using only transitions. For example, The closure of node 1 in the left figure below

    is the set {1,2}. The start state of the constructed DFA is labeled by the closure of the NFA start

    state. For every DFA state labeled by some set and for every character c in the language alphabet, you find all the states reachable by s1, s2, ..., or sn using c arrows and you union together the closures of these nodes. If this set is not the label of any other node in the DFA constructed so far, you create a new DFA node with this label. For example, node {1,2} in the DFA above has an arrow to a {3,4,5} for the character a since the NFA node 3 can be reached by 1 on a and nodes 4 and 5 can be reached by 2. The b arrow for node {1,2} goes to the error node which is associated with an empty set of NFA nodes.

    The following NFA recognizes , even though it wasn't constructed with the 5 RE-to-NFA rules. It has the following DFA:

  • TCS Sem V Computer Paper Solution By Prof Sameer Y Velankar (9324793514)

    Glorious Academy www.gloriousacademy.org

    Q7 d) Closure properties of CFL

    Context-free languages are closedfree languages, the following languages are context

    the union of L and the reversal of L is also context free language the concatenation of the Kleene star of L is also context free language

    Context-free languages are not closed under L is a context-free language and D

    their difference are context

    Q7 e) Application areas of RE, FA, PDA, CFG, TMApplication of RELexical analysis : RE is used for performing Lexical analysis. Lexical analysis is the process of tokenizing a sequence of symbols to eventually parse a string. The Java compiler will separate out each token (variable , constants , keywords and so on). This is done in the first step of compiling any Java program.

    Application areas of FA

    Pattern Matching : Finding an occurrence of short string in the long string is called pattern matching and this is done by using FA. For example finding whether mat appears in the word mathematics.Lexical analysis : FA is used for performing process of tokenizing a sequence of symbols

    TCS Sem V Computer Paper Solution By Prof Sameer Y Velankar (9324793514)

    www.gloriousacademy.org (Ph 9920030136 , 25621515)

    Q7 d) Closure properties of CFL

    closed under the following operations. That is, if L and free languages, the following languages are context-free as well:

    and P is also context free languageis also context free language

    of L and P is also context free languageis also context free language

    free languages are not closed under complement, intersection, or differenceD is a regular language then both their intersection

    are context-free languages.

    Q7 e) Application areas of RE, FA, PDA, CFG, TM

    RE is used for performing Lexical analysis. Lexical analysis is the process of tokenizing a sequence of symbols to eventually parse a string. The Java compiler will separate out each token (variable , constants , keywords and so on).

    rst step of compiling any Java program.

    Pattern Matching : Finding an occurrence of short string in the long string is called pattern matching and this is done by using FA. For example finding whether mat

    athematics.Lexical analysis : FA is used for performing Lexical analysis. Lexical analysis is the process of tokenizing a sequence of symbols to eventually parse a string

    TCS Sem V Computer Paper Solution By Prof Sameer Y Velankar (9324793514)

    Page 36

    and P are context-

    difference. However, if is a regular language then both their intersection and

    RE is used for performing Lexical analysis. Lexical analysis is the process of tokenizing a sequence of symbols to eventually parse a string. The Java compiler will separate out each token (variable , constants , keywords and so on).

    Pattern Matching : Finding an occurrence of short string in the long string is called pattern matching and this is done by using FA. For example finding whether mat

    Lexical analysis is the to eventually parse a string. The Java

  • TCS Sem V Computer Paper Solution By Prof Sameer Y Velankar (9324793514)

    Glorious Academy www.gloriousacademy.org (Ph 9920030136 , 25621515) Page 37

    compiler will separate out each token (variable , constants , keywords and so on). This is done in the first step of compiling any Java program.

    Application areas of PDA

    PDA is used for recognizing Context free Language (which is also defined by Context free Grammar). For example the Language L = {anbn | n >= 1} can be recognized by PDA.

    Actually PDA is used in the second phase of compilation which is syntax check. Example

    a) Check whether expression has balanced parenthesis.

    b) Check whether number of curly braces open are matching corresponding curly braces close in a Java program.

    Application areas of Turing machine

    Turing machine is a hypothetical computer defined by Alan Turing which can be used for

    a) Lexical analysis (which can also be done by RE or FA)

    b) Syntax check (which can also be done by PDA)

    c) Computing a mathematical expression and writing output on the tape. For example multiplying 2 unary numbers and storing the result on the tape. This can be done only by Turing machine and not by FA or PDA.

    Hence Turing machine is the most powerful machine (in terms of problem solving ability) as compared to FA or PDA.