0% found this document useful (0 votes)
18 views145 pages

TOC Full Syllabus Notes

Uploaded by

Tanishka Sahay
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views145 pages

TOC Full Syllabus Notes

Uploaded by

Tanishka Sahay
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 145

TOC:-

Theory of Computation :-

Purpose of Toc

To introduce different type of language or feature of language or characteristics of


language

Language

Language is set of string.

Eg. L= {a,ab,aab}

Grammar

Set of Rules are called as Grammar. Grammar is a four tuple entity denoted by G
(N,T,P,S).

Those strings which are made by following given set of rules are said to be valid
and other are said to be invalid.

Consider a Grammar

S  aA
S  bB
A  aA/ a
B  bB /b

N  set of Non-Terminal/Capital letter/ variable.


T  set of terminal/Small letters
P  Production Rule
S  Starting Symbol

 In following grammar, some characters represented in capital and some in


non- capital, small characters are known as terminal and capital character
are known as non-terminal or variable.
Terminal

Terminal symbols are the part of string generate by grammar.

 Non-Terminal symbols are not a part of string but they help in generating
strings.
 Every grammar has starting symbol(non-terminal), usually we denote it by
‘S’.

S  aA
S  bB
A  aA/ a
B  bB /b

 Which strings are generating from above grammar.

S  aA
 aa  (1)

S  aA
 aaA
 aaa  (2)

S  aA
 aaA
 aaaA
 aaaa  (3)

S  bB
 bb  (4)

 bB
 bbB
 bbb  (5)
L= {aa, bb, aaa,bbb, aaaa,bbbb,……..}

This grammar generates either the String of ‘a’ or String of ‘b’ in which no. of a
should be atleast 2 and no. of b should be at least 2 in number.

# Consider a grammar: -

S  aSb

/epsilon  represent null string (lemda)

Language generated by this grammar will be –

S  aSb
 ab  ab (1)



 aSb
 a(aSb)b
 a (ab)b = aabb

 aSb
 a(aSb)b
 aaaSbbb
 aaabbb
 aaabbb

Language = { ,ab,aabb,aaabbb,------}

Or

an bn , n 0

 Something to the power 0 is  in TOC.


Means a0=  and 0 is treated as even in TOC.

Consider the following Grammar: -


S  aSa
S  bSb
Sa
Sb
S

L={,a,b,aa,bb,aba,bab,aaa,bbb,aaaa,bbbb,abba,baab, aabbaa…}

Length of lemda is zero


 Above grammar generates all the palindrome or all the palindrome of even
plus odd length.
 This rules are known as production rules of the grammar.

S  aSa Production rule of given grammar


S c

L={c,aca,……….}

CHOMSKY CLASSIFICATION OF GRAMMAR

Depending upon type of production rule Chomsky classify grammar into


four categories-
Unrestricted Grammar type 0
Context sensitive Grammar type 1
Context free Grammar type 2
Regular Grammar type 3

Unrestricted Grammar

This grammar is known by the name phrase structure grammar and most general
grammar.

Production rule is in the form: -

Where are the string of terminals and non-terminals.


 Only one restriction is there, left hand side should contain at least one
non-terminal.
 Language generated by unrestricted grammar is known as Unrestricted
language.

Example: -
(1) SaAa  B
(2) A  aB
(3) a AB (not type0)

Context-sensitive grammar

If production rule is in the form: -

Condition to satisfy this production rule in context-sensitive is


| length of | | length of |

Example: -
Aa bB
S Ab
Aba aA (not type 1,type 0)

 Language generated by context-sensitive grammar is context sensitive


language.

Context free-grammar: -

Condition:

Left hand side should contain only single non-terminal.

Example: - A

 Language generated by context free grammar is Context Free Language.

Regular grammar: -

Condition: -
Left hand side should contain only single non-terminal and right hand side should
contain a terminal or along with terminal we can use one non-
terminal or only signal terminal.

Example: -
A  B
A  
A  aaA
A  Aaa
A  aAa
A  aaaAb

 Non terminal never lies between two terminals.


 Language generated by regular grammar is Regular Language.

S  aS Not a regular grammar.


S  bS

Special points

 Every type 3 is type 2


 Every type 2 is type 1
 Every type 1 is type 0

But vice versa of above three statement may or may not be true.
Type 3  Type 2  Type 1  Type 0
Layout of different language

To accept regular language, we have finite state automata.


To accept context free language, we have push-down automata.
To accept context-sensitive language, we have linear bounded
automata.
To accept unrestricted language, we have turning machine.

When we said our language is regular: -

Case 1 When that language is generated by regular grammar.


Case 2 When we can design regular expression.
Case 3 When we can design DFA or NFA for that language.

Question: -

We have given a language anbn n 0, we have to check whether this language is


regular or not?

Answer

Here grammar is not given, here directly language is given, and they ask whether
this language is regular or not.

How to identify whether given language is regular or not?

With the help of regular expression, we can identify.

And second way is to generate grammar for given language which is difficult to
generate.

Regular symbols

1) *
2)
3) ab
4)
Regular expression

can have any value from 0 to


i.e. * = 0,1,2,---------

Regular expression a* can generate

When * = 0,  string will be generated

When * = 1, a string will be generated

When * = 2, aa string will be generated

Finally, in same manner: -

a* = { ,a, aa,aaa,aaaa,aaaaa------------------------ }.

a+: - (plus)
+ can we have any value from 1 to

a+ = {a, aa, aaa, aaaa,aaaaa------------------------ }.

a+b :-

This ‘+’ represent choice, either it should be b.

a + b = { a,b }
a + b  a b  a, b.

Exercise: - (a + b).(a + b) = ?

(a + b) . (a + b) = { aa, ab, ba, bb}


a a
a b
b a
b b

Precedence order:-

‘*’ > ‘.’ > ‘+’


concatenation

Any language consists of only two characters then how many two length string can
be generated by this regular expression: -

(a + b). (a + b)

2c1 * 2c1  22  4

Generally, in TOC, sigma ( ={a,b} ) represent set of alphabets.

n = 2

Meaning of this is in your alphabet set there exist 2 alphabet

Question

If cardinality of  is 2, then how many string of length n is possible?

Answer

2n

String generated by given regular expression are: -

(a + b) * =??

(a + b)0 = 

(a + b)1 = {a, b}

(a + b) . (a + b) = {aa, bb,ba,ab}

(a + b). (a + b). (a + b) = {all the possible string or a and b of length 3}


¦ ¦
¦ ¦
¦ ¦
so on
Given regular expression returns all the possible string over a and b.
Special point:

a* b* is in given regular expression can we have both * value different??


Yes we can have different values of * at a time.

String generated by given regular expression :-


a* b* = { , ab, aa, aaa, aaaa---------b, bb, bbb, abb, aab---------so on}

String generated by this regular expression having a speciality is that any
number of a’s followed by any number of b’s.

ba string can’t be generated by given regular expression (a* b*).

Generally, question come which two regular expressions are equivalent.

To answer this type of question, if we can find anyone one string with is
uncommon in between two regular expressions then surely we can say both regular
expression is not equal.

But systematic procedure says first draw the DFA for both the regular expression
then check whether both DFA are equivalent or not.

If both are equivalent it implies both the regular expression are equivalent
otherwise it will not be equivalent.

Exercise

a (a+b) * = (aa+ab) * check whether this two regular expression are equivalent??

Answer: -

 cannot be generated by a(a+b) * but (aa+ab) * will generate . Therefore, both are
not equivalent.

Exercise: -

(a* b*)* = (a+b)* check whether both the regular expression are equivalent or not??
Answer: -
Yes, they both are equivalent.

Property: (r* s* )* = (r + s)*

Where r and s both are regular expression.

Exercise: - a* b* = (a+b) *, check whether both the regular expression are


equivalent or not??

Answer: -

ba can’t be generated by a* b* but (a+b) * can generate ba

 both regular expression is not equivalent

Exercise:

a(a+b) * = (aa+ab) + check whether both the regular expression are equivalent or
not??

Answer: -

Single a can generated by a(a+b) * but single a can’t be generated by (aa+ab) +.


Therefore, both the regular expression is not equivalent.

Exercise

a (a*+b*) = aa*+ab* , check whether both the regular expression are equivalent or
not??

Answer:-

Yes, both the regular expression are equivalent.

Property

r (s*+q* ) = rs* + rq* .


Where r,s,q, they are considered to be regular expression.

Exercise

(a*) * = a*, is this two regular expression are equivalent

Answer

Yes, it is always true.

Regular symbol:
Some properties of this Regular Symbol

a.
a.  = a
{}
a+ a

 {} Empty language/set
  null string Empty string

 , a   are called Primitive Regular Expression and all other called


derived regular expression.

 In regular expression, there exist only finite symbol means regular


expression consist of only finite symbol

Try it: -

Gate-1996 ques. 1.8

Answer: -

(c) option

Gate-1997 ques. 6.4


Answer: -

(d) option

Question: -

Is given language is regular??

an bn, n 0

Answer

No, because we can’t design regular expression for it

Question

Is this given language is regular??

(ab)n, n 0

Answer: -

Yes, given language is regular because there exists regular expression for it i.e.
(ab)*. Therefore, it lies under regular language.

Now another way to check whether our language is regular or not. With the help of
finite automata.

If language is regular, then it is possible to design its DFA or NFA.

DFA:

DFA stands for deterministic finite automata. DFA consist of set of finite state, in
this finite automata we have one initial state and having zero or more than zero
final state.
DFA is a language acceptor, it only accepts the string, it can’t able to generate
string.

Abbb 1000 (translator )

DFA configuration: -

M ( q0, F)

DFA is a five tuple machine. Here


Q  set of finite state
 set of finite alphabet
q0  initial state
F  set of final state.

 transition (Total Function)


: Q  Q

Total Function

There is a transition for a from q0 to q1.


There are transition for b and a at q1 and q2 using self loop.

 A state with arrow is known as Initial state and a state with double circle is
known as Final state.
 Language generated by given NFA = {aa,bb,aba, bab,_ _ _ _ _ _ _ _so on}

Regular expression: (ab*a + ba*b )


Self-loop says, it may be there it may not be there.

Means b* not b+

If there exist cycle in our DFA, and there exist at least one final state,
which is reachable from initial state then language accepted by this
DFA is infinite.
Regular expression generated by given DFA:

There are transition for b and a at q1 and q2 using self loop.

(ab*a + ba*b) (a + b) *

If there exist no cycle in our DFA, then that DFA accept finite language , it will
never accept infinite language.

Every finite language is regular. But infinite language may or may not be
regular.

Question

Design a minimize DFA for a language over a and b contain at least one a

L={a , aa, ab, ba, aba,abb,bba,bab,abba,…….}

Solution: -

Question
Design a DFA for a language over a and b contain at least two a’s

Solution

Property of DFA

For every input, there exist exactly one transaction in all-state of finite automata,
then that finite automata are considered to be Deterministic Finite Automata.

Concept of trap state/ sink state/ dead state

L= a(a+b)*

Consider the following machine: -

Question

Is given figure is DFA?

Answer
No, because there exists no transaction for b in initial state i.e. in DFA for every
state there should be exactly one transaction for every input.

L= a(a+b)*

If in any state there is no transaction for any symbol, then from that symbol
we will go to the invalid state / dead state / Trap state / sink state.

Question: -

Design a DFA for a language over a and b contains exactly two a’s?

Solution: -

At q2 there is only transition for b.


L={aa,aba,baa,baba,….}
Question:

Design a DFA for a language over a and b contains at most two a’s?

Answer :-
L={lemda,a,b,ab,ba,aa,bb,…….}
If our initial state is final state, then only our language generates 
string in DFA.
There exists no transaction for  in DFA, but in NFA, there can exist
transaction for  also.

Special Points

Every DFA is NFA but every NFA is not necessary to be DFA.

• Try it:-

Question:-3 IT – 2006 Ans - d


Question:-5 IT – 2006 Ans - a

Question: -

Design a DFA for a language containing at least one a and at least one b?

Answer: -
L={ab,ba,abb,baa,aba,bab,abababab,abbbbbba.…..}
Question: -

Design a DFA for a language containing at least one a and two b’s?

Answer: -

Remove self loop from q2.


Question:

Design a DFA for a language containing


L = {na(w) mod 2 = 0, w  (a,b)*}

Answer :-

The statement means, number of a’s in w string is divisible of 2.

In other words our language , accept those string in which number of a’s is
divisible by 2.
Question:

Design a DFA for a language over a and b where language is given by

L = {w | na(w) mod 3 = 1 or na(w) mod 3 = 2, w  *}

Solution:-

q0 state  mod 3 = 0
q1 state  mod 3 = 1
q2 state  mod 3 = 2

Special point

Here in this L = na(w) mod 2 = 0, there are two states in our minimized DFA.
• In general, if our language is

L = na(w) mod n = 0
Then

In our minimized DFA, there will be n states, with one final states and (n-1) states
as non-final State.
• Suppose we have following state: -

L = na(w) mod 2 = 1

It means that w is a string which generate odd number of a’s.


For even number of a’s, we will write our language as

Leven = na(w) mod 2 = 0

Question: -

Design a DFA for a language over a, b where language is given by:-

L = na(w) mod 2 = 0
And
nb(w) mod 2 = 0

O1 at q1 and q0 is final state.

DFA for given language

Question

Design a DFA for a language over a and b where language is given by:-

L = na(w) mod 2 = 0
And
L = nb(w) mod 3 = 0
Solution
 q0 is final state
 Total number of states we get ( 2*3 ) = 6.

Special point

na(w) mod n = k1
or/and
nb(w) mod m = k2

Then number of states = n*m, in our minimized DFA.

Question: -

Design a DFA for a language over (a, b) where language is given by:-

(na) mod 2 = 0
L= or
(nb) mod 3 = 0

Answer :-
Here total state is 6 with four final state and two non-final state.

DFA v/s NFA

DFA: -
For every input there is exactly one transaction.

NFA: -
More than one or zero transaction for every input.

?? Which one is more powerful?? Powerful in the sense, which finite automata
generate more language then other, NFA or DFA.

 Every machine has two variants in TOC

Non-Deterministic Deterministic

 NFA and DFA both are equivalent in power means every NFA can be
converted into DFA, and every DFA can be converted into NFA.

 NPDA is more powerful than DPDA, means NPDA can accept more
language then DPDA. In other words, there are some language for which
only NPDA can be design but PDA can’t be design.
 Power between NLBA and DLBA is open question.

 NTM and DTM both are equivalent in power.

Further classification of language

Classification of Language
Closure property

Closure means for example, addition of two natural number are closured under
natural number it means that addition of two natural number are always be under
natural number.

But subtraction of two natural number is not closured under natural number it
means that subtraction of two natural number may be natural number or may not
be natural number.

Closure properties of language: -

Union
Intersection
Concatenation
Kleen’s closure
Complement
Transpose
Subset operation
Prefix
Suffix
Reversal
Union

All five categories of language are closured under union property.

Intersection:

Context-free languages are not closured under intersection.


Intersection of two context-free languages may or may not be context-free.
But other than context free language, other all language are closured under
intersection.

Concatenation

All five categories are closured under concatenation.

Complement
 Context-free languages are closured under complement. Complement of
context-free language may or may not be context-free.
 Complement of recursive enumerable language is definitely non-recursive
enumerable.
 Except this two, all other languages are closured under complement.
 There are some language which are not accepted by turning machine.
 Finite automata is memory-less-device.

Transpose

All five categories are closured under Transpose.

Question:

Is this language is regular??

L = an bn, n < 3
Answer

Yes, it is a regular language because it is a finite language.

• Every finite language is regular but every regular language is not necessary
to be finite.

Closure’s properties of regular language.

Union

Let us say we have two languages which are given by

L1 = { ab, ba }
L2 = {bab, aba }

L1L2 = { ab, ba, bab, aba }

and if
L1 = a* b*
L2 = b* a*
L1L2 = L1 + L2 = a* b* + b* a*

 Regular language is closured under union.

Case 1:

Union of regular language and non-regular language is regular or non-regular??

Answer:-

It may be regular it may not be regular.

L1 L2 = may be regular may not be regular.

Regular non-Regular

For example

L1 is   Regular because  is finite and every finite set /language is regular and
say

L2 = an bn  non-regular

 an bn = an bn

non-Regular

Next example:

L1 = ( a+b)*  Regular
L2 = an bn  Non-Regular

L1L2 = ( a+b)*

Regular

Question:

Is regular language is closured under infinite union??


Answer:

Regular language is not closured under infinite union.


It means that infinite union of regular language may be regular may not be regular.

i.e. L1 L2 L3 L4------------------

Example:

{ } { ab } { aabb } { aaabbb } { aaaabbbb }



L = an bn , n 0

Non-Regular

How to design NFA for a union of two regular language.

Let us say two regular languages are given by

L1 = a* b*
L2 = b* a*

Draw DFA for both languages individually: -

L1 = a* b*

L2 = b* a*
 There exist  transaction means without reading input we can change our
state. But if your FA contain  transaction then it is NFA not DFA.

 To design union of two regular languages we introduce  transaction.

NFA for L1L2

Special point

If DFA/NFA of L1 contain = n states

And if NFA/DFA of L2 contain = m states

Then NFA of L1L2 have = n+m+1 states

 If in any NFA, contain n states then corresponding minimized DFA almost


contain 2n states.
 If
DFA of L1 = m states
DFA of L2 = n states
Then L1L2, max states contain 2^n+m+1

NFA configuration

NFA is a five type machine.

M ( q0, F)
Here
Q  set of finite state
 set of finite alphabet
 Total Function
q0  initial state
F  set of finite final state.

: Q ()  2Q

Intersection

Regular language is closured under interaction.


For example: -

L1 = a* b*

L2 = b* a*

L1L2 = a*+ b*

Regular

Regular language are closed under intersection.

L1 L2 L3 L4 L5 _ _ _ _ _ _ _ _ _

Result may be regular may not be regular.


Question

Intersection of Regular language and non – regular language is regular or non-


regular??

Answer: -

It may be regular; it may not be regular. For Example: -

L1 = 
L2 = anbn

L1L2 =  = Regular

L1 = (a+b)*

L2 = anbn ,

L1 L2 = anbn (non regular)

So, intersection of Regular and non-Regular language may not be regular.

Concatenation: -

Question: -

How to concatenate two regular languages?

Answer: -

Let us say we have two languages:-


L1 = {ab, ba}
L2 = {aba,bb}

L1.L2 = {ababa, abbb, baaba, babb}


It is same as catersion product concept in DBMS.

 All the string of L1 will be join to L2.


 Regular language/expression is closured under concatenation.

L1. L2 = regular

Regular Regular

Question

Concatenation of Regular Language and non – regular language is regular or not


regular?

Answer:

It may be regular; it may not be regular.


For Example:-
L1 = 
L2 = a*b*
L1.L2 = . a*b* =   Regular
Says, L1 = 
L2 = anbn
L1.L2 = . an bn =   Regular
L1 = anbn
L2 = a*b*
L1L2 = a*b*  Regular

How to design NFA for concatenation of two Regular language.

L1 = a*b*
L2 = b*a*

Draw DFA for L1 and L2 both –


Put  transaction from the final state of 1st NFA to the initial state of 2nd NFA and
then make the final states of 1st NFA to be non – final.

At last the automata obtained will be the concatenation of L1 and L2. Here we are
excluding trap states assume NFA for both regular language.

NFA for a*b* b*a* = a*b*a*

KLEEN’S CLOSURE

If L =m {a,b} then what L* will contain? Here L* represent Kleen’s Closure.

L* = L0 L1 L2 L3_ _ _ _ _ _ so on
L0 = {}
L1 = {a,b}

L.L L2 = {aa,ab,ba,bb}


L* = (a+b)*
L!=L*
 Kleen’s Closure of regular language is always regular.
 It is possible that L* = L ?
Yes it is possible, For Example:

L = a*b*

L* = (a*b*)* = (a+b)*

Here L L*
But here L = {}
L* = {} = L = L*.

Here in this example L and L* both are equivalent.

 If Language contain itself * then its Kleen’s closure is equivalent to the


Language.

How to draw NFA for Kleen’s Closure??

First of draw NFA for the Language, then merge all the final state & make it one,
draw  transaction from final to initial state and also make  transaction from
initial to final state.

Let L = {ab}

NFA for L1

Now NFA for L1*


Lemda transition from q0 to q2 is not required.

Complement

• If  = {a,b} then * = (a+b)*


And
If  = {a,b,c} then * = (a+b+c)*

What does * returns?

* returns set of all possible strings our alphabets.

Now complement of language L will be

Lc = * - L

All those string which are the part of * but not a language. In other words, all
those string which are not a part of our language but are the part of its complement.

If L = (a+b)*
then
L =
c

How to find complement of any Regular Language?

L = a*b*

Now converting the final state of DFA of L into non – final state and non – final
state, then we get desirable complement of language L.
DFA for LC

Remember this step is only and only can be applied to DFA can’t be
applicable to NFA, it may or may not give desirable complement of language.

# Try this GATE question -


CS- 2003, question : 54
Answer:- b

Question

Is it is possible that complement of non – regular language is regular?


Answer: -

 No, because suppose L is regular language, then Lc is also regular language,


if complement of Language Lc is regular then L should be regular
compulsory, if it is not there then above property will be invalid that all
regular languages are closured under complement.
That’s why complement of non – regular language is non – regular.

SUBSET

Regular expressions are not closured under subset. Subset means for example a* is
a subset of a*b*

a* a*b*

Regular language Regular language

an bn a*b*

Non- Regular Regular language


language

 All five categories are not closured under subset.

Question

Is every non-regular language having a regular subset??


Answer

Yes, every non-regular language has a regular subset.


For example: -
an bn a*b*

Transpose

How to find transpose of any regular grammar??

To find transpose of any grammar just reverse its production rule.

Right-linear grammar And Left linear grammar.

Example:-
A  a A  Right-linear grammar
B bB 
A a All the non-terminal should be in right side.

Next Example: -

A  Aa  Left-linear grammar
B  Ba 
A a All the non-terminal should be in left side.

One more Example: -

A  aA
B  Ba  linear grammar
C c 

Combination of both right & Left-linear grammar is known as Linear


Grammar.

• Linear grammar, is not necessary that would be regular grammar.


• If your grammar is either right-linear or left-linear then language generate by
that grammar will definitely a regular grammar
• A linear grammar may or may not generate regular language.
Question: - How to find transpose of any grammar??

Answer :- To find transpose of any grammar, then reverse the production rule of
grammar.

For example: -
If our production rule of grammar is as follows: -
A  aA
B  bB
A c

Then transpose of above grammar become: -


A  Aa
B  Bb
A c

 If our grammar is right-linear grammar, then its transpose will be left-linear


grammar and vice-versa.
 All five categories are closured under transpose.
 Regular grammar are acts as generator.
 Power of left-linear grammar is equivalent to power of right-linear grammar.

Question:

Design a minimized DFA for the language which accept the binary string whose
decimal equivalent is divisible by 5??

Answer
q0  initial state
q4  final state

Total states in minimized DFA = 6.

Question

Why we don’t make 0 as a final state??

Answer

Because there is no binary equivalent exist for .

Question

How many states are exist in minimized DFA for the language accepted by binary
string whose decimal equivalent is divisible by n

Answer

Minimum number of states = n + 1.

Question

Design a minimized DFA which accept the language over  ( a, b) is an bm , n, m 1


Answer

Regular expression:- a+ b+

Question:

Design a minimized DFA which accept the language over  ( a, b) is an bm , n, m 0

Answer

Regular expression: - a* b*

Question

Design a minimized DFA which accept an bm ck n, m, k 1  ( a, b, c )

Answer
DFA for L = an bm ck.

Question

Design a minimized DFA which accept the language an bm ck n, m, k 0

Answer

Question:

Design a minimized DFA which accept all the string over a and b.
Answer

Question:

Design a minimized DFA which accept empty language.


L={}
Answer

Invalid
Remove a and b and make it non final state.
Question:

Design a minimized DFA which accept only empty string.

Answer

Invalid
Regular expression of above DFA = (a+b)*
Question

Design a minimized DFA whose string start and end with same symbol?? With
atleast two character or also accept empty string.

Answer

L = { , aa, bb, aba, aaa, bab, bbb------------------ }

 initial state will be our final state.


Total = 5 state with two final state and three non-final state.

Question

Design a minimized DFA whose string start and end with same symbol??

Answer

Total 5 state with


3 final state and 2
states as non-final

Question

Design a minimized DFA whose string start and end with different symbol??
Answer

L = { ab, ba, aab,abb, baa, bba ------------------ so on}


• See carefully, it is the
complement of previous DFA,
that we drawed.
• Total states = 5 with 2 final
and 3 non-final state.

Question

Design a minimized DFA which end with ab


L=(a+b)*ab

Answer

Way, to draw minimized DFA directly, find out minimum length string which can
be accepted our language, and think how to make in general.

L = { ab, aab, bab----------------- }

Question

Design a minimized DFA which starts with ab


Answer

Total states = 4 with


one final state and
three non-final
states including one
trap state.

Conclusion: -

 Start with aba, number of minimized state in dfa = count (aba) + 2


=5
 End with abc, number of minimized states in dfa = count (abc) + 1
=4

Question

Construct a dfa which accept set of all string over { a,b } such that second symbol
from LHS is b

Solution
Question

Construct a DFA which in which last two symbol are same

Answer

Regular expression = ( a+b )* aa + ( a+b )* bb

Question

Design a minimized DFA which accept set of all string over { a,b } such that
length of string should be divisible by 2
Answer
Question

Design a minimized DFA whose string contain almost length of 2

Answer

Question

Design a minimized DFA whose string contain atleast length of 2

Answer

Question

Design a minimized DFA whose string contain exactly length of 2

Answer
Question

L = | an | n 0 and n! = 3 and n! = 5

Answer

First of draw complement of this language DFA

Now complement this DFA we get our desired DFA


Question

Construct a minimized DFA whose all string contain ab.

Answer

Question

Construct a minimized DFA whose all string contain aaa as a substring.

Answer
In general, number of states = count (aaa) + 1
=4

Question

Construct a minimized DFA whose all string have following property.

Answer

Every a is followed by b

Question

Construct a minimized DFA whose all string have following property.

Every a is followed by exactly one b

Answer
Question

Design a minimized DFA whose all string have following property.

Answer

‘a’ never followed by b’

Question

Design a minimized DFA whose all string have following property

Every a is followed by bb

Answer
Question

Design a minimized DFA whose all string have following property.


‘ Every a should never followed by bb’

Answer

Question

Design a minimized DFA for a3bwa3 where w (a+b)*

Solution

DFA for a3bwa3


Question

Design a minimized DFA for ab5wb2


w (a,b)+

Answer

Total 10 states.

Question

Design a minimized DFA in which all string should have following property
All string containing 00 but does not contain 000.

Answer
Question

Design a minimized DFA for the following language.


L = |w| mod 2 = 0 and w 4.

Answer

Question:

Design a DFA over (0,1) whose decimal equivalent is divisible by 3

Answer
 By default decimal equivalent is divisible by = n+1 .

Question

Design a DFA, for the regular expression

a* b* + b* a*
Answer

Question

Design a DFA for the regular expression


(01)*
Answer

Question

Find out how many states exist in minimized DFA for the regular expression.
( ab + b )*
Answer

Question

How many number of states are there in the minimize DFA that accepts the
following language??
L = { a3(n+1) | n 0 }

Solution
L = { a3 ,a6, a9 -------------------}

Total states will be 4 in our minimized DFA

Question

Find the number of states are there in the minimize DFA for the regular expression.
a+ b+ + b+ a+
Solution

Question

Design a minimized DFA with exactly two a’s and more than two b’s.

Answer
1
 Total number of states = 13

Question

Design a minimized DFA with at least one a and exactly two b’s.

Answer

Question
Construct a DFA which accept set of all string over {a,b} such that second symbol
from RHS is ‘a’.

Solution

No. of states = 2n

No. of Final state = 2n-1

No. of Non-Final state = 2n-1

Some non-standard operation

Prefix:

Suppose L = {ab, bba, aba}

What prefix (L) should contain??

L = { , a, b, bb, ab, bba, aba}

 In every string, first prefix of that string is .


 Regular languages are closured under prefix.
 All five categories are closured under prefix.

How to find NFSA for prefix (L)??

Draw NFSA for prefix of language


L = { ab, bba, aba }
NFA for L.
Now how to draw NFA for prefix

If we have drawn NFA then make all state as final state and if we drawn DFA then
make all states as final states except dead state.

Question

If all the states of DFA over {a, b} are final state then string accepted by this DFA
is

Answer

(a+b) *, but it is not necessary in NFA

Special point:-
dfa

 Minimum state required to draw dfa is 1.


 In minimized dfa of there will be no final state, but in non-minimized dfa
of there will be many final state

Regular language is closured under prefix.

Suffix

Suppose L = {ab, bab, abb}


Then what suffix (L) will contains??

Suffix (L) = { , b, ab, bab, bb, abb}

• Every string, first suffix is . Write in right to left fashion but read it in left to
right fashion.

L ={ abb }
Suffix (L) = { , b, bb, abb}

How to find NFA for Suffix(L)

First of all draw NFA or DFA given language L.

L = {ab, bab, abb}


NFA for L = {ab, bab, abb }

Converting this NFA to suffix (L)

Draw  transaction from initial state to every remaining state of DFA, other than
trap state if we have drawn DFA.

Try this

Question:- CS-2010 41)

Answer
C

Reversal

If L is the language, then it reversal is denoted by LR.

L = {w | w  L}

LR = {wR | w  L}
For example: -
If L = {a+ b+}
LR = {b+ a+}
Regular Language are closured under reversal.

How to draw nfa for LR if L dfa or nfa is given-

Step 1

Draw dfa or nfa for language L

Suppose language L = a* b*

To draw reversal of nfa change the direction of all transaction and make initial
state as final state and final state as initial

If there are multiple initial or final states, make them one by  transaction.
One more example

Suppose {L= an bm, n, m  1}

Regular sets are closured under reversal.

Right quotient: -

Let L1 and L2 be language on the same alphabet, then right quotient of L1 with L2
is defined as

L1/L2 = {x | xyL1 and yL2 |

To form right quotient of L1 and L2, we take all the strings in L1 that have a suffix
belonging to L2.

Every such string after removal of this suffix belongs to L1/L2

Example
L1 = {an bm | n  1, m  0} {ba}
L2 = { bm : m  1 }

L1 /L2 = {an bm | n  1, m  0 }

If L1 is regular and L2 is regular, then L1/L2 is also regular.

Left quotient: -

L1 and L2 be language on the same alphabet then left-quotient of L1 with respect


to L2 is defined as –

L1/L2 = {y: x  L2, xy  L1}

Regular language is closured under left quotient.

Some grammar is given check whether it is a regular or not.

I. L = an bn , n 0

It is not a regular language because FA can’t able to check equivalent. In this


language, we have to calculate, no. of a’s as well as number of b’s. So above
language is non-regular.

II. L = am bn , n, m 0

It is regular language, corresponding regular expression is a* b*

III. L = am bn , m! = 2n

It is non-regular language

If relationship is there and if that relationship is valid for infinite, then that
language will not be Regular Language.

IV. L = wcwr | w (a+b) *

It is non-regular language.
w  Set of string

wr  Reversal of w

aabcba  L
abbacabba  L

because to justify it, requires memory.

V. L = wxwr | w *

Answer

Above Language is regular language.

Explanation: -

String generated by above language is in the form: -


abaababa

Now putting w =  then wr =  Then, X can be produce any string over a, b so


given language, regular expression become (a+b)*

VI. L = wxwr , w +
, = (a,b)
x *
Answer

Language can accept string like


abc
aabb bbaa
w x wr
or

a abb abc bba a


w x wr

Here we didn’t need to insure equality, here we only want to insure that starting
symbol & ending symbol should be same, this feature can be insuring by finite
automata
Regular expression for above grammar look like this: -

R = a(a+b) + a + b(a+b) * b

VII. L = an c bn , n 0

Answer

It is non-regular language.

VIII. L = an x bn , x *
n 1

Answer

Regular language, corresponding regular expression = a(a+b) * b

IX. L = an x bn , x (c, d)*

Answer

Non-regular language

X. L = 0n 0n , n 0

Answer:

L = 02n

It means that string accepted by given language are even number of 0’s.
It’s corresponding regular expression is (00) *, because there is a pattern
which easily can be seen in dfa/nfa.
If length of string is in AP, then language will be regular.

XI. L = xwwr y | x, y,w (a+b)+

Answer

(a+b)+ aa (a+b)+ + (a+b)+ bb (a+b)+.


XII. L = xwwr | x, w (a+b) *

Answer: -

Non-regular language.

XIII. L = wwr x | x, w (a+b)+

Answer

Non-regular language.

XIV. L = { aþ | Þ is any prime number }

Answer

In above language there is no fix pattern between strings of this language. Now
finding Kleen’s closure of above language: -

L = { aþ | Þ is any prime number }

Kleene closure of L is L*

i.e. L* = L0 L1 L2 L3 L4------------------ L8
L0 = {  }
L = {aa, aaa, aaaaa, a7 ,a11 ---------------- }
1

L.L = { a4, a5, a6 , a7 , a8 , a9 -------------------}

Kleene closure of this language will, will not contain single a but contain all the
strings over a except single a.

R =  + aa+

XV. L = xwwr , x, w +
, (a+b)

Non-regular.

XVI. L = 02 | i 0
Above language is non-regular language, because distance between two
consecutive strings is not in A.P, it is in GP. Therefore above language is
non-regular.

XVII. L = ai bj | i + j = 5

Above language is regular language, because given language is finite.

i+j 5
i+j 5
ai bj | i+j 5  all are regular
i+j5
i+j 5

XVIII. L = ai bj | i - j = 5

Answer
Non-regular language because above language is producing infinite string and
having equality
 non-regular language.

i+j 5
i+j 5
ai bj i+j 5  all are non-regular.
i+j5
i+j 5

Try this:-
Question no. 53, CS-2008
Answer  (a)

 Question no. 35, IT-2008


Answer  (d)

 Question no. 31 CS-2007


Answer  (c)

 Question no. 29, CS-2006


Answer  (c)

Question no. 30, CS-2006


Answer  (d)

 Question no. 32, IT-2008


Answer  (a)

Question

How many different DFA’s are possible with two states and two inputs??

Answer

Here, there are two possibility of a

a’s self-loop or change the state when a come and same situation for b.

Total = 4  4 = 16

Total DFA with two input and two output

16 + 16 + 16 + 16 = 64

Initial state II state No All are


Is our final is final final Final state
State state state state

Question
How many different DFA’s are possible with three inputs and two states??

Answer

Total = 64

Total DFA = 644  26  22 = 28 = 256.

Question

How many different NFA are possible with two states and two inputs??

Answer

How many transactions for a in a single state


(1)

(2)

(3)

(4)

Same 4 possibilities for b


Without  Transaction: - 256  4 = 1024

1024 + 1024 + 1024 + 1024

No,  Initial to final Final to initial In both direction


Transaction  Transaction  Transaction  Transaction

Total = 1024  4 = 21022212=4096

ALGORITHM FOR CONVERTING AN NFA INTO DFA

Step I: To kill or to remove all  transaction.

 If there exist  transaction from state qi to qj then copy all transaction of qj to


qi and if qj is final state, then make qi also final state.
a
a a
b
qi qj
b
b

Step II: Removing  transaction from q0 to q1.

a
a
a b
q0 qj
b

b
One more Example:

a b a


q1 q2 q2


a

b a
b 
q1 q2
q3

a
b
a b
a
b

b b

b
a

a
b a
b
b

bb
b
b

NFA without transaction

Step II : Draw transaction table for NFA consider the following NFA:

a
b
b
a
q0
q1 a,b
q2

Transaction table for given nfa.

a b

q0 q0 q1

q1 q2 q1, q2

q2 q2 q0
Now corresponding transaction table for dfa.
a b

q0 q0 q1

q1 q2 q12

q22
q2 q0

q1222
q2 q012

q01222
q02 q012

q02 q02 q01

q01 q02 q12

How to perform merging?

q1, q2 q12, merge the subscript and order should be maintained in subscript

(sorted).

 Means q12 and q21 both are same.


 q12 status for transaction merge the transaction of q1 and q2 state.
 q22 state will never be there, for transaction.
 In given example there exist 3 state in NFA but corresponding DFA consist
of 7 states.
 If there exist n status in our NFA then corresponding DFA consist of 2n
status (minimized DFA).

How many states are possible in DFA with n states to NFA, maximum
number of status in our DFA will be-

(a) 3n (b) 2n

(c) 4n (d) 5n

{Bigger option will be our answer}

Convert the following NFA into deterministic finite automata.

Ans. 0

q0
0 q1 0 q2
1

1
q3 q4

Step I: Remove  transaction from NFA.

 Since here there is no  transaction therefore above step can be ignored.


Step II:

Make transaction table for above NFA.

a/0 b/1

q0 {q0, q1} {q0, q3}


q1 {q2} 

q2  

q3  q4

q4  

Now converting this transaction table for corresponding DFA :

DFA transaction Table:

0
1

q0 q01 q03

q01 q012 q03

q03 q01 q034

q012 q012 q03

q034 q01 q034

Special Point:
(i)  represent trap state.

Minimization of Deterministic Finite Automata:

 Representation of an automaton for the purpose of computation requires


space proportional to the number of states.
 For storage efficiency it is desirable to reduce the number of status as for as
possible.
Algorithm using Myphill-Nerode Theorem

Input: DFA
Output: Minimized DFA
Step 1 Draw a table for all pairs of states (Qi, Qj) not necessarily connected
directly [All are unmarked initially]
Step 2 Consider every state pair (Qi, Qj) in the DFA where Qi ∈ F and Qj ∉ F or
vice versa and mark them. [Here F is the set of final states].
Step 3 Repeat this step until we cannot mark anymore states −

If there is an unmarked pair (Qi, Qj), mark it if the pair {δ(Qi, A), δ (Qi,
A)} is marked for some input alphabet.

Step 4 Combine all the unmarked pair (Qi, Qj) and make them a single state in
the reduced DFA.

Example

Let us use above algorithm to minimize the DFA shown below.

Step 1 − We draw a table for all pair of states.


a b c d e f

Step 2 − We mark the state pairs −

a b c D e f

b
c ✔ ✔

d ✔ ✔

e ✔ ✔

f ✔ ✔ ✔

Step 3 − We will try to mark the state pairs, with green colored check mark,
transitively. If we input 1 to state ‘a’ and ‘f’, it will go to state ‘c’ and ‘f’
respectively. (c, f) is already marked, hence we will mark pair (a, f). Now, we
input 1 to state ‘b’ and ‘f’; it will go to state ‘d’ and ‘f’ respectively. (d, f) is
already marked, hence we will mark pair (b, f).

a b c D e f

c ✔ ✔

d ✔ ✔

e ✔ ✔
f ✔ ✔ ✔ ✔ ✔

After step 3, we have got state combinations {a, b} {c, d} {c, e} {d, e} that are
unmarked.

We can recombine {c, d} {c, e} {d, e} into {c, d, e}

Hence we got two combined states as − {a, b} and {c, d, e}

So the final minimized DFA will contain three states {f}, {a, b} and {c, d, e}

DFA Minimization using Equivalence Theorem

If X and Y are two states in a DFA, we can combine these two states into {X, Y}
if they are not distinguishable.

Two states are distinguishable, if there is at least one string S, such that one of δ
(X, S) and δ (Y, S) is accepting and another is not accepting.

Hence, a DFA is minimal if and only if all the states are distinguishable.

Algorithm
Step 1 All the states Q are divided in two partitions − final states and non-final
states and are denoted by P0. All the states in a partition are 0thequivalent.
Take a counter k and initialize it with 0.
Step 2 Increment k by 1. For each partition in Pk, divide the states in Pk into two
partitions if they are k-distinguishable. Two states within this partition X
and Y are k-distinguishable if there is an input S such that δ(X,
S) and δ(Y, S)are (k-1)-distinguishable.
Step 3 If Pk ≠ Pk-1, repeat Step 2, otherwise go to Step 4.
Combine kth equivalent sets and make them the new states of the reduced
Step 4
DFA.

Example

Let us consider the following DFA −

Q δ(q,0) δ(q,1)

a b c

b a d

c e f

d e f

e e f

f f f
Let us apply above algorithm to the above DFA −

P0 = {c,d,e}, {a,b,f}
// check for states a,f for input 1, output is c,f which are not belonging in same set in P0
b,f for input 1,output is d,f which are not belonging in same set in P0 //

P1 = {c,d,e}, {a,b},{f}

P2 = {c,d,e}, {a,b},{f}.

Hence, P1 = P2.
There are three states in the reduced DFA. The reduced DFA is as follows −

The State table of DFA is as follows −

Q δ(q,0) δ(q,1)

(a, b) (a, b) (c,d,e)

(c,d,e) (c,d,e) (f)

(f) (f) (f)


Its graphical representation would be as follows −

Try This

Qus. CS-2007

74.

Ans. (c)

75.

Ans. (b)

DFA and NFA are language acceptor.

Finite automata may have outputs corresponding to each transition. There are two
types of finite state machines that generate output −

 Mealy Machine
 Moore Machine

Mealy Machine
A Mealy Machine is an FSM whose output depends on the present state as well as
the present input.

It can be described by a 6 tuple (Q, ∑, O, δ, X, q0) where −


 Q is a finite set of states.

 ∑ is a finite set of symbols called the input alphabet.

 O is a finite set of symbols called the output alphabet.

 δ is the input transition function where δ: Q × ∑ → Q

 X is the output transition function where X: Q → O

 q0 is the initial state from where any input is processed (q0 ∈ Q).

The state diagram of a Mealy Machine is shown below –

Output is associated with each transition for each input .

Moore Machine

Moore machine is an FSM whose outputs depend on only the present state.

A Moore machine can be described by a 6 tuple (Q, ∑, O, δ, X, q0) where −

 Q is a finite set of states.

 ∑ is a finite set of symbols called the input alphabet.

 O is a finite set of symbols called the output alphabet.


 δ is the input transition function where δ: Q × Σ → Q

 X is the output transition function where X: Q × Σ → O

 q0 is the initial state from where any input is processed (q0 ∈ Q).

The state diagram of a Moore Machine is shown below −

Mealy Machine vs. Moore Machine


The following table highlights the points that differentiate a Mealy Machine from
a Moore Machine.

Mealy Machine Moore Machine

Output depends both upon Output depends only upon the present state.
present state and present
input.

Generally, it has fewer states Generally, it has more states than Mealy
than Moore Machine. Machine.

Output changes at the clock Input change can cause change in output
edges. change as soon as logic is done.
Mealy machines react faster In Moore machines, more logic is needed to
to inputs. decode the outputs since it has more circuit
delays.

Moore Machine to Mealy Machine

Algorithm
Input: Moore Machine
Output: Mealy Machine
Step 1 Take a blank Mealy Machine transition table format.
Step 2 Copy all the Moore Machine transition states into this table format..
Step 3 Check the present states and their corresponding outputs in the Moore
Machine state table; if for a state Qi output is m, copy it into the output
columns of the Mealy Machine state table wherever Qi appears in the
next state..

Example
Let us consider the following Moore machine −

Next State
Present State Output
a=0 a=1

→a d b 1

b a d 0

c c c 0
d b a 1

Now we apply Algorithm 4 to convert it to Mealy Machine.

Step 1 & 2

Next State

Present State a=0 a=1

State Output State Output

→a D b

B A d

c C c

d B a

Step 3
Next State

Present State a=0 a=1

State Output State Output

⇒a D 1 b 0
b A 1 d 1

c C 0 c 0

d B 0 a 1

Mealy Machine to Moore Machine


Algorithm 5
Input: Mealy Machine
Output: Moore Machine
Step 1 Calculate the number of different outputs for each state (Qi) that are
available in the state table of the Mealy machine.
Step 2 If all the outputs of Qi are same, copy state Qi. If it has n distinct
outputs, break Qi into n states as Qin where n = 0, 1, 2.......
Step 3 If the output of the initial state is 1, insert a new initial state at the
beginning which gives 0 output.

Example
Let us consider the following Mealy Machine −

Next State

Present State a=0 a=1

Next State Output Next State Output

→a D 0 b 1

b A 1 d 0
c C 1 c 0

d b 0 a 1

Here, states ‘a’ and ‘d’ give only 1 and 0 outputs respectively, so we retain states
‘a’ and ‘d’. But states ‘b’ and ‘c’ produce different outputs (1 and 0). So, we
divide b into b0, b1 and c into c0, c1.

Next State
Present State Output
a=0 a=1

→a d b1 1

b0 a d 0

b1 a d 1

c0 c1 C0 0

c1 c1 C0 1

d b0 a 0

Is Mealy Machine and Moore Machine both are equivalent in power?

Yes, they both are equivalent in power.


 Conversion of Mealy to Moore is somehow trick but conversion of Moore to
Mealy is easy.
 Conversion of Moore to Mealy, no. of states remain same.
 But in conversion of Mealy to Moore, number of states may increase.
Maximum state = N * M

N  No. of states in Mealy Machine

M  No. of output symbol.

 If we have n bit input string then


n bit output we get in Mealy Machine and (n + 1) bits output we get in
Moore Machine.

HOW TO DRAW A GRAMMAR FOR A GIVEN REGULAR


LANGUAGE/DFA

Ans. Given following DFA.

a a b
b
b
q0 q1 q2

a B
S A

First Step :

 Assign a unique non-terminal to every state.


 For every state, there will be a non-terminal and non-terminal corresponding
to initial state will be S.
S  aS | bA

A aA |bB

BbB|aB|

 There will be 3 states, why states? Because there are three non-terminal in
our grammar.
 All those state which generates terminals, after visiting that terminal go to
the final state.

b
a
a a
q0 b

S A B
b

One more example :

S  aA

S  bB

A  aA

A  bB

B  aB

B  bB/Lemda

b
a
a a
S
A B
S b B
A

B
Try This :

IT-2004

Solution :

a
a
A b B

A b B

A  aA | bB

B  aB

B  bA | 

Ans. (b) option

Context-Free Language :

When a language is said to be context free language?

Ans. When it is accepted by some push-down automata.


What do you meant by push-down automata?

PDA is nothing but FA with a memory called stack.

 There is no restriction on the length of a stack i.e. there is length of stack.


If there is restriction on length of size then what happen to the PDA?

Ans. PDA acts like finite automata, means it will accepts only regular
language.

 Any language which can be accepted by logic of stack is context free.

Given a language L, L = anbn | n 0 is this language is regular?

If we are capable to accept this language with the help of stack logic, then this
language lies under context-free.

 Here in this language we have to ensure that, number of a's is equal to


number of b's.
 Whenever a comes push into stack and whenever b comes pop one a.
 If input set is empty, then your stack should be empty.

Given a language L, L = {anbmcmdn | n, m 0} is this language is context-free?

Yes it is context-free language.

Given a language L, L = anbmcndm | n, m 0 is this language is context free


language?

No, this language is not context free language.

Given a language L, L = anbmck | n = m + k is this language is context-free


language?
Yes, given language is context-free language can insure one equality on one
variable.

Given a language L, L = {wcwr | w€ *


} is this language is context free
language?

Yes, it is context-free language.

Stack Logic :

For example, consider one string of this language say aabcbaa.

Push w onto the stack, then do nothing when c come, then after this if input contain
b then stack should also contain 'b'. Then pop the b by doing this if string is empty
then our stack should also be empty.

Qus. 19 Qus.40

CS-2006 CS-2010

 Non-deterministic push-down automaton is more powerful then


deterministic push-down automata.
 Till now whatever we see is deterministic push down automaton.

Given a language L, L = wwr is this language is context-free language?

abbbba

When to push & when to pop there is a confusion and if someone till that length of
w is 3 then we can insure, therefore this language is context free 0.
L = wwr

It is non-deterministic context-free language.

Context-free language
DCFL NCFL

(For deterministic CFL, (For non-deterministic

there exist DPDA) CFL, there exist NDPA)

 Where it is clear from where is to pop and from where to push, then that
language lies under DCFL.

If L = anbmck | n = m or n = k is this language is DCFL or NCFL?

Ans. L = anbmck | n = m or n = k

NCFL because where to pop and where to push is not clear

If L = anbmck, n = m and n = k, is this language is context-free language?

Non-context-free language because PDA can check one equality on one


variable.

If L = ww, is this language is context-free or not?

abbabb

Given language is not a context free language because we can't insure this by stack
logic.
abb abb
w | w

 PDA with finite capacity of stack length, it is will accept only regular
language.
How to Design PDA for A Context Free Language:

Design a PDA for the language anbn?

When we design actual PDA, stack never be empty, it contain special symbol i.e.
z0.

 In anbn, firstly a will come then push the a.


a, z0 | az0 Push the input symbol on the top of stack.

Input contain 'a' Stack top contain z0

a, z0|az0 b, a/

q0 a, a/ , z0|z0

, z0|z0

 PDA do not have any trap state and there is no concept of minimum state
of PDA.

a a b b 

a a a
z0 z0 z0 z0 z0
Stack Implementation

Design a PDA for the language L, L = anb2n, n 0.


a, z0|az0 b, a/

b, a/ q1 q
, z0|z0 2

q0

a, a | aaa , z0|z0

Design a PDA for the language L, L = a2nbn | n 0.

a, z0|az0
b, a/ q1 , a/ q2 , z0|z0
q0 q
3

a, a | aaa

, a/

, z0|z0
 Language of palindrome is NCFL and its complement is also NCFL.

Design PDA for wcwr | wE* (a + b)

Ans.

a, z0|az0 b, a/

b, z0/bz0 a, b|
q0 , z0|z0
c, a|a
a, a | aa c, z0|z0
a, b | ab c, b|b
b, a | ba

Push-down Automata

Generally, in books transition is given, not in diagram form PDA.

How to write transition with respect to PDA state diagram?

1)  (q0, a, z0)  (q0, az0)

2)  (q0, b, z0)  (q0, bz0)

3)  (q0, a, a)  (q0, aa)

4)  (q0, b, b)  (q0, bb)

5)  (q0, a, b)  (q0, ab)

6)  (q0, b, a)  (q0, ba)

7)  (q0, c, z0)  (q1, z0)

8)  (q0, c, a)  (q1, a)

9)  (q0, c, b)  (q1, b)

10)  (q1, b, b)  (q0, )

11)  (q1, a, a)  (q1, )

12)  (q1, , z0)  (q2, )

 (q1, a, z0)  (q0, az0)


You are on Stack top contain z0. Top of the stack

stateq1 Input contain a after pushing

where u reached

Qus. IT-2006

Ans. (c)

Initially why we have initial symbol in the stack z0?

Ans. There exist two types of PDA

 Basically there are two type of PDA,

Acceptance by final state Acceptance by empty stack

 Power of both the PDA are equal.


 To ensure that our stack will not empty in between we put z0 in the stack.

Design a PDA, for the language L = wwr WE (a + b)

Solution :
a, a/
a, z0|az0

a, a|aa , z0|z0
a, a|
b, b|bb
b, b| b, b|
b,a|ba

a, b|ab

NDPA FOR wwr

So above language is non-deterministic context free language.

CONTEXT-FREE-GRAMMAR:

S  aAB

Exactly one No restriction on R.H.S.

non-terminal

and nothing else

E  E+E

E  E*E

E  id
Here T = {+, *, id} [Terminal]

N = {E} [Non-Terminals]

S = {E}

Starting symbol

Above grammar is context-free grammar, now we want to check whether


id + id * id can be generated by our grammar or not.

E  E+E

 id + E
Left-Most 5 steps are required to drive
 id + E * E string from this grammar.
Derivation
 id + id * E

 id + id * id

Sentential form

 Intermediate form is known as sentential form.


 Left- most derivation sentential form is known as left-most sentential form.
 Right-most derivation sentential form is known as right-most sentential
form.

RIGHT-MOST DERIVATION:

E  E+E

 E+E*E
5 steps
 E + E * id

 E + id * id

 id + id * id

 There can be multiple right/left most derivation for a single string.

Parse Tree (RMD):

E  E+E E

 E+E*E
E + E
 E + E * id

 E + id * id E * E
id
 id + id * id  
id id

Parse Tree

We can't have discussed from parse-tree, that it is derivate from right


derivation or left-derivation.
 From one parse tree we can how many derivations.
 But for a single derivation there will be exactly one parse tree.
 A context-free grammar is said to be ambiguous if there exist more than one
left or right derivation or more than one parse tree (different) for a string.
Regular grammar can also be ambiguous,

 We discuss ambiguity with context-free grammar because programming


language cannot be ambiguous.
Consider the following grammar;

E  E+E

E  E*E

E  id

id + id * id, with this string, we have two parse tree (different).

 If u want to evaluate 2 + 3 * 4 from above grammar then this grammar give


u two result
I parse tree : - 14
Problem Occur
II parse tree : 10

Special Points :

 C's main function is consider to be library function.


 C's grammar is consider to be context-sensitive grammar.

Check whether given grammar is ambiguous or not?


Ans. S  aSb

S  SS

S  

String
S
S

S S
S
S
| |
|
S S  

| |
(1) (2)

Ambiguous Grammar :

Because we have created two parse tree for '' string.

 The term 'ambiguous' is used only for grammar, not for the language,
because there exists multiple grammar for a single language.
 But for some language there exist no unambiguous grammar, that language
is known as inherently ambiguous language.

Is regular language can be inherently ambiguous language?

No, because for every regular language, there exist a DFA & every grammar
which are designed by DFA will never be ambiguous.

But this law is not true for context free-language.

Check whether given grammar is ambiguous or not?

Ans. S  aSbS

S  bSaS

S  E0
S
S

a S b a S b S
S
|

E0
E0
b S a S a b S
S
| | |
|
E0 E0 E0
E0

abab abab

Ambiguous Grammar

Inherently Ambiguous Context Free Language:

L = anbkcm | n = k or n = m n 0, m, k 0.

Ambiguous of any grammar except regular grammar is undecidable. Means there


is no algorithm, to check whether given grammar is decidable or not.

DIFFERENT NORMAL OF CONTEXT FREE GRAMMAR:

Chomsky Normal Form Greibach Normal


(Always there will be Form

creation of Binary Tree)

CHOMSKY NORMAL FORM :

When a grammar is said to be in CNF?


When there exist a production rule of the form :
ABC

Aa

Chomsky normal form never contain  production


if there exist  production then that  should only be generate by starting symbol &
that starting symbol cannot be appear in right side of any production rule.

For example: (I example)


SAB

Aa
It is in Chomsky Normal Form
Bb

S

II EXAMPLE:

SAB

S S A
S
S

Aa

Ab

Above grammar is not in Chomsky Normal Form because starting symbol contains
, no problem but S occurs in R.H.S. in some production rule, that’s why our
grammar is not in Chomsky Normal Form.

III EXAMPLE:

SAB

Aa | 
Bb

Above grammar is not in CNF.

HOW TO CONVERT GIVEN GRAMMAR INTO CHOMSKY NORMAL


FORM:

Why to convert given grammar into Chomsky Normal Form?

There is some algorithm which can be applied on the grammar when your
grammar is in CNF.

Step I : Remove all the  production from the production set.

Step II: Remove all unit production from the production set. {A->B}

Step III: Remove all the production rule involving the redundant non-
terminal.

When a non-terminal is said to be redundant?


Case I: When that non-terminal is not generating string directly
or indirectly.

Case II: When that symbol is not reachable from starting symbol.

Step IV: Introduce a new non-terminal for every terminal.

Step V : If some production rule is of the form.

SAXY

then we can break into this way.

SAS1

S1XY

Consider the following grammar.


SaAa

SbBb

AaA

Aa

BbB

Bb

Convert above context free grammar into Chomsky Normal Form?

Step I : No need to apply.

Step II: No need to apply.

Step III: Case 1

Case 2

Step IV: SaAa

SbBb

AaA

Aa

BbB

Bb

Introducing new-non-terminal for every terminal.

Fa

Eb

Those production rule which are already in Chomsky Normal Form write as its-

Aa
Bb

This two production rule is already is in Chomsky Normal Form so don't change
anything in that production rules.
SFAF

SEBE

AFA (Chomsky Normal Form)

Aa (Chomsky Normal Form)

Bb (Chomsky Normal Form)

Now apply step V :

SFS1

S1AF

SEB1

B1BE

AFA

Aa

Bb

Finally, we have converted our grammar into Chomsky Normal Form.

Greibach Normal Form :

Aa$*

a belongs T , $ belongs V*

T Set of Terminals.

V Set of Non-Terminals.
A-aBB, A-> aBCC….., B->b…..

A->aBc (not in GNF)

means one terminal followed by zero or more than zero non-terminal.

MEMBERSHIP OR CKY OR CYK ALGORITHM:

 It is applicable only if our grammar is in Chomsky Normal Form.


 Membership algorithm checks whether our string can be generated by our
grammar or not.
 Membership algorithm is decidable because algorithm exist for that
algorithm.
 Membership algorithm till recursive language are decidable but membership
for recursive enumerable is not decidable (partially decidable).
 We can convert every context-free grammar into Chomsky Normal Form (
free grammar)
Consider a grammar which is in CNF

SAB

SBB

Aa

Bb

 We have to check whether the string aabbb can be generated by our


grammar or not by using membership algorithm (CYK Algorithm).
 To check this, first of all we have to make cyK algorithm pyramid.
 What is the length of string 5, so pyramid consist of 5 rows?
 In first row there will be five columns and in second row there will be four
columns & so on and in last row there will be only one columns.
a a b b b
A A B B B

(aa) S S S
(ab) (bb) (bb)

(aab
)

aabb
b (S)

 It uses dynamic paradigm to solve the problem. Its complexity is 0(n3) where
n is the length of string.

How to design a PDA for a context-free grammar :

To draw PDA for any context-free grammar there will be exactly three states in it
(It is fixed).

 It is not necessary that to draw PDA for a grammar,


 grammar should be in Chomsky Normal Form.
 In first state we will push starting symbol and in Second state, all other
transition will be there and in third state is our final state.
Consider the following context free grammar.

SAB

ABB

Aa
BAB

Bb

Step I : Push starting symbol S on the top of the stack. When there is a non-
terminal, we will do not read any input ,we will push that non-terminal in
Stack.

 (q0, , z0)  (q1, S Z0)

 (q1, , S)  (q1, AB)

 (q1, , A) (q1, BB)

(q1, a)

 (q1, , B) (q1, AB)

(q1, b)

 Whenever there are two option for any non-terminal, there exist NPDA for
it.
 If top of the stack contain terminal then to pop that terminal, input should
also contain that terminal.
 If top of stack contain a then input should contain a, then we can pop that
terminal from the stack.
 (q1, a, a)  (q1, )

 (q1, b, b)  (q1, )

 (q1, , z0)  (qf, z0)


a, a|

b, b|
, z0|SZ0 , z0|z0 qf
q1
q0

a, a | aaa
, A|BBA

, A/a
Non -deterministic push-down automation
We have to check whether 'ab' string can be generate or not.

Initially stack will contain z0.

ab

z0

Now, starting symbol S will be pushed without reading any input.



ab
z0 S

Pop the S, and push AB.


z0 B A

Now pop the A and push a


ab

z0 B a

Stack top contain a and input also contain a then  a.


a b pop
z0 B 

Pop B and push b:


z0 b ab

Finally stack will contain

z0

String will be accepted

In this way, string will be accepted by our push-down automata.

Try this questions :

 CS-2003
51 (c)

 CS-2006
32 (d)
PUMPING LEMMA FOR REGULAR LANGUAGES:

 It is a negative list for checking regular language and context-free language.


 This lemma will not comment about whether language is regular.
 This lemma is based on pigeon hole principle.
 This lemma is applicable only for infinite language because finite languages
are regular and given lemma, can't comment on regular language.
 If our language is regular then for every string W€L, it is possible to divide
W in three parts x, y, z such that.
xyz €L

Then xynz € L should hold n  0 where |y| > 0 and |xy|  K.

For every string having greater than or equal to K where K is some limit it is
possible to divide that string into three parts x, y, z and if.

xynz E L will also be hold.

Where K is equal to number of states in minimized dfa of that regular language.

For example:

a*b* is a regular language, we will take one string of that language aabb.

aabb €L

 Now we will divide this string into three parts we get-


a a bb

  

x y z

xyz EL

a (a)n bb

n=1 aabb
 Putting different value of n, we are pumping different string.
a a b b

x y z a (ab)n b  L

 If string can be pump by pumping lemma then language may be regular may
not be regular.
 If string is not pumped, then definitely our language is non-regular.

Show that anbn | n 0 is not a regular language using pumping lemma?

Ans. anbn | n  0, take one string of this language let us say we take aabb.

a a bb a (a)nbb  L (G)

x y z

Here string is not pumping string so pumping string so pumping lemma says above
language is non-regular language.

Why we are saying, if strings are pumped then we can't say about regularity?

Let us take a language of equal numbers of a’sn and equal number of b's.

Suppose string is aabb € L

a ab b

x y z

x (y)nz L
a (ab)n b  L

n=1 aabb L

n=2 aababb L

n=3 aababb L

Strings are pump but given language is not regular


language.

If pumping lemma is satisfied then what we can say?

No Comments on regularity.

PUMPING LEMMA FOR CONTEXT-FREE LANGUAGE:

It is possible to divide the string in five parts :


uvwxy L

then,

uvnwxn y L

|v x| > 0, |u v w|  p

anbncn will not be pump so given language is not context free language.

Special Points :

1. Complement of context-free language must be recursive.


2. DCFL is never inherently ambiguous language.
3. Parikh Theorem can be used to show whether certain languages are not
context free language.
4. My hill NE rode Theorem is used to show whether language is regular or not
(positive list).
 If finite number of equivalence classes are found then language is regular
otherwise non-regular.
5. DCFL LR (1)
LL(1) DCFL

CLOSURE PROPERTIES OF CONTEXT FREE-LANGUAGE:

 We can divide context-free language into two types.

NCFL DCFL

(Non-Deterministic (Deterministic

context-free language) context-free language)

 Context-free languages are closured under union and concatenation but it is


not closured under intersection and complement.

IS DCFL's are closured under union or not?

L1 = anbn  DCFL

L2 = anb2n  DCFL

L1 U L2 = anbm | n = m or m = 2n

NCFL

 By this counter example we can say that DCFL are not closured under
union.
 Union of two DCFL, it may be DCFL it may not be DCFL, but it never go
outside context-free language.
Regular U DCFL = DCFL
INTERSECTION:

 Context free are not closured under intersection.


 Now what about intersection of two deterministic context-free language
(DCFL)?
DCFL  DCFL = ?

Suppose

L1 = anbncm , n,m>=1  DCFL

L2 = ambncn , n,m>=1  DCFL

L1  L2 = Not a CFL

= anbncn

Context-Free Language

 DCFL are not closured under intersection.

Regular  DCFL = DCFL

Regular  CFL = CFL

Regular  Recursive= Recursive (my be it is wrong)

CONCATENATION:

Context free languages are closured under concatenation.

Whether two DCFL are closured under difference or not?

No, two DCFL are not closured under concatenation



L1 - L2 = L1  L 2

Try This Questions :

Qus.31 IT-2006

Ans. (b)

Qus.33 CS-2006

Ans. (b)

Qus.1CS-2011

Ans. (c)

P-=P

Qus. 17 CS-2010

Ans. (b)

Qus. 13 CS-2008

Ans. (d)

Chart for DCFL

PROPERTY CLOSED NOT CLOSED

1) UNION 

2) CONCATINATION 

3) INTERSECTION 

4) KLEEN'S PLUS 
5) KLEEN'S STAR 

6) COMPLEMENT 

7) REVERSAL 

8) PREFIX 

9) SUFFIX 

10) MIN 

11) MAX 

12) DIFFERENCE 

13) INVERSE HOMORPHISM 

Operator Grammar :

 Operator grammar lies under DCFL and all DCFL can be parse in 0 (n)
where n is the length of string.
 There are two rules for grammar to be operator grammar.
1) No  production

2) No two non-terminal be adjacent

Example S Not allowed

S  AB

S  AbB

S  AaaB
All this production rules are allowed.
Sa

S  ba
SIMPLE GRAMMAR :

 Simple grammar also generates only DCFL. This grammar will never be
ambiguous grammar.
 This grammar also known as LL (1) grammar.

PROPERTY :

S  av*

a  T, V  Non-terminal

and combination of (s, a) occurs at most once in P.

 By using S-grammar, string can be parse in 0 (n) time, where n is the length
of our string.

Special Point :

1) Number of sets required to derive a string of length n is :

for CNF : 2n - 1

for GNF : n

 Some languages whose complements are context-free language but original


language are not context free language.
1) ww

2) anbncn

3) wwr complement is also context-free language.

Some languages are there which are context free :


1) L = |xR # y| x, y  (0 + 1)* and x is a substring of y.

2) L = |x # y| x, y  (0 + 1)* and x! = y

3) L = |w1 c w2| w1, w2  (0 + 1)* , w1 # w2R

4) L = |anbm| n  m  3 n

Some Languages are there which is not context free.

(i) wwrw (ii) x  y and x is a substring of y.

Some Important Properties :

 If G is CFG then there exist an equivalent grammar that does not contain any
useless symbol.
 If G be any context-free grammar with   L (G) then there exist an
equivalent grammar G having no  production.
 If G be any context-free-grammar without  production, then there exist a
CFG G' such that does not have any unit production and that is equivalent to
G.
 Any context-free grammar with   L (G) has an equivalent grammar in
Chomsky Normal Form.
 For every context free grammar G with   L (G) there exist an equivalent
grammar G in GNF.
 Context-free language are not closured under left and right quotient but
under RE it will be closured.

Context-Free-Language are closured under the following property :


1) UNION

2) CONCATINATION

3) KLEEN STAR

4) KLEEN PLUS

5) PREFIX

6) SUFFIX

7) REVERSAL

8) HOMOMORPHIC

9) INVERSE HOMOMORPHIC

10) SUBSTITUATION

11) CYCLE

1. Ambiguity of CFG as well as CFL are undecidable.


2. Whether CFG generates * (Universality) is undecidable.
3. Containership for context-free language is undecidable.
L (G2)  L (G1)

G1 and G2 are context free grammar.

4. We have given CSG (Context Sensitive Grammar) and they ask you whether
this grammar generates context-free language or not, this property is
undecidable.

DECIDABLE PROBLEMS (CONTEXT-FREE LANGUAGE) :

1. DPDA equality is decidable.


2. L = 
L = finite
3. L * decidable only for DCFL not for NCFL.

4. L (G1)  L (G2)

If G2  Regular Grammar

G1  Context Free Grammar

5. Membership is decidable.
Whether there is any
6. G1 = Regular Grammar common word in between
this two grammar is
G2 = Context Free Grammar decidable

TURNING MACHINE:

 Turning machine is a machine with a memory known as tap.


 Tap consists of infinite cell.
 Inputs are encoded into cell already.
 Suppose your input is aabb. One all can occupy one symbol only:
a a b b   

, ,  they are called blank spaces, after input remaining all contain blank spaces.
 There exist a read/write head in turning machine, read/write head can move
in any direction but one all at a time.
 Reading or writing can be performed on the all with read/write head.
 For our convenience, we can assume any initial position of read/write head.

Design a turning machine for the language L = anbn|n 0.


Initially we assume, read/write head is at left-most end.
In turning machine, logic of tape is important.

Read/write head

We have to insure here that number of a's = number of b's.


Initially read/write head is on the left most end as soon as we get a it is converted
to blank space and new also b into blank space corresponding to a.
After input terminates we should get blank space on the both sides of read/write
head only then TM will
 a a b b   

 a b b

 a b 

 b

Convert a into blank space and move read/write head towards right.
Now move read/write head to the right until we don't get right most b.

a a b b 


Now how we know that right most 'b' we have encountered?

Until we don't get blank space in right most and when we encountered first
blank space right most then take one left at that position we go get right most 'b'.

Now convert that b into blank space and move read head to left and repeat this
procedure again till we get this situation.

Turning Machine (TM) for the language L = anbn , n 0

Left to the read/write head & right to the read/write blank space (symbol).

a, a|R b, b|R

a, /R
q1 b, b/R q2 , /L q3
q0

, /hault

b, /L
, /R

q
5 q4 a, a/L

b, b/L

 Turning machine halt means, at that point onwards, turning machine will
stop.
 For input 'ba' turning machine read/write will be crash.
 Crash is the form of halting (Halting on some non-final state).
 If turning machine is crashed means string is rejected by turning machine.
 And if turning machine is halting on some final state, it means string is
accepted by turning machine.
 a, /R

Input Conver After conversion


t that move to the right
Contain input
into 

Design a turning machine for ab (a + b)*

Ans.
a, a|R
b, b/h

Design a turning machine for ab

Ans.
a, a|R , /H
b, b/R

TM for ab string

Design a turning machine for at least two a's?

Ans. b, b|R b, b|R

q0 a, a/R q1 a, a/H
q 2
TM (Turning Machine)

Design a turning machine for a*b*?

Ans.
a, a/R b, b|R

b, b|R

, /h

, /h

Design a turning machine for almost two a's?

Ans. b, b|R b, b|R


b, b|R

q0 a, a/R a, a/R q , |H


q
2 q
3
1

, |h
, |h
TM for almost two a's

LBA

A linear bounded automaton is a multi-track non-deterministic Turing machine


with a tape of some bounded finite length.

Length = function (Length of the initial input string, constant c)


Here,

Memory information ≤ c × Input information

The computation is restricted to the constant bounded area. The input alphabet
contains two special symbols which serve as left end markers and right end
markers which mean the transitions neither move to the left of the left end marker
nor to the right of the right end marker of the tape.

A linear bounded automaton can be defined as an 8-tuple (Q, X, ∑, q0, ML, MR, δ,
F) where −

 Q is a finite set of states

 X is the tape alphabet

 ∑ is the input alphabet

 q0 is the initial state

 ML is the left end marker

 MR is the right end marker where MR≠ ML

 δ is a transition function which maps each pair (state, tape symbol) to (state,
tape symbol, Constant ‘c’) where c can be 0 or +1 or -1

 F is the set of final states


A deterministic linear bounded automaton is always context-sensitive and the
linear bounded automaton with empty language is undecidable.

Configuration of TM

TM is a 7-tuple machine

L (Q, ∑, ┌, δ, q0, □, F)

 ┌ tape alphabet
 □ blank symbol
In TM and PDA, atleast two states are necessary, atleast one is accepting and other
is non-accepting

L= a2^i | i>=0 is also a context sensitive language because there exist a LBA for that
language.

Special point

 This turning machine will not be half for the input 01.
 Whether turning machine halt or not is undecidable problem. Halting
problem of turning machine is undecidable.
 With some constraints whether turning machine will halt is decidable.
 Ever halt is undecidable.
How to identity given problem of TM is decidable or not??
Those properties for which we have to run TM provide that there is no constraints
is given, all such properties are undecidable and remaining all other are decidable.

How many states are there in TM, is this property of TM is decidable or


undecidable?

Given property of TM is decidable because we can justify by seeing the TM


configuration to verify this property.

 Whether turning machine goes to State 6 or not?


Undecidable because to verify this property we have to run TM.

 Language accepted by TM is Φ is this property is decidable or


undecidable??
Undecidable because to check/ verify this property we have to run turning
machine.
 Regular language related all properties are decidable.
 Some property of context -free language are decidable and some are
undecidable.

Concept of infinite set

We can divide infinite set into two categories

 Countably infinite set


 Uncountable infinite set
Countably infinite set

A set is said to be countably infinite set if there exist one to one correspondence
between the set and the set of natural number.

In better words there exist a bijection between the set and set of natural number. Is
set of odd number is countably infinite set?
 Bijection insures that fixed positon of element when arrange elements in
specific order.
 Set of natural number is countably infinite
 Set of even as well as odd number is countable infinite set.
 Set of prime number and rational umber is countably infinite
 Set of non-decreasing function are countably infinite.
Set of real number is uncountable infinite set.

Explanation

Between in 0 and 0.1 there are infinite number therefore we cannot justify exact
position of 0.1 therefore it is uncountable infinite set.

 Set of irrational number is uncountable infinite set.


What is the use of countable infinite set? Whatever model we have study they all
are language acceptor i.e. they check whether our string is accepted or belongs to
our language or not.

 Turning machine can also generate the language or acts as a enumerate.


When TM acts as a acceptor we have input tape and when TM acts a
generator we use output tape.

 TM can enumerate all countable infinite set.


If set of DFA is countable infinite then there exist a TM which can generate or
enumerates all DFA.

 Unrestricted grammar
 Recursive
 Recursively enumerable
 Recursive language

A language is said to be recursive if there exist a TM which can accept the


language and rejects its complement. Reject means it halt on some non-final state.

 It means if our language is recursive then there exist a TM that will halt on
every input.
 If string belongs to the language it halts on some final state. If string doesn’t
belong to the language it will halt on some non -final state.
Recursive language is also known as turning decidable language and recursive
enumerable is also known as Turning recognizable language.

Recursive enumerable language

A language is said to be reclusively enumerable if there exist a turning machine


which accept the language and reject or loop forever for its complement

Membership algorithm is decidable till recursive language but membership for


recursively enumerable language is undecidable.

Set of all possible string over a and b is countably or uncountable?

When we say it is countable when we have a particular order in which we can


arrange the strings

Generally, we follow alphabet order i.e. lexicographical order

{, a ,aa ,aaa ,aaaaa,-------------- - ----------------}

Finite set is lexicographic enumerable. Yes, all finite set are lexicographical
enumerable. Some infinite set are also enumerating lexicographical

For example

a*= {, a, aa, aaa, aaaa, --------------------}

we can justify any string position


How to write string in canonical order? Arrange the string length wise and within
the same length follows alphabet order.

(a+b) * = {, a, b, aa, ab, ----------}. Now someone ask where four a’s will be
present, at what position. 1+2+4+8= 15 position +1 =16 position. According to this
way we can justify the position of any string by this way.

So set of all possible string over a and b is canonical enumerable or in other words
we can say set of all possible string over a and b is countable infinite set.

Countable means there exist a TM which can generate set of all possible string
over a and b.

Try this

Cs-2003 15 ans d

Power set of countably infinite set is countable or uncountable infinite set?

Example set of natural number

{, {1},{2},{3},---------------infinite}

Here we cannot say where 1st element sets will be terminal and from where second
element will be started.

So power set of countably infinite set is uncountable set.

Learn all the following results.

 Set of all regular language are countably infinite set


 Set of all context free langue are countably infinite,
 Set of all context sensitive language are countable infinite.
 Set of all recursive as well as recursive enumerable language are countably
infinite
 Set of all NFA , DFA , PDA ,DLBA, NPDA , NLBA , DTM ,NTM are
countably infinite set.
If our set is countable means it can enumerable by a TM.
Set of regular language is countable means there exist a tm which can generate all
regular language.

 Set of all possible language over a and b are countable?


Uncountable infinite

Means power set of (a+b) * and as (a+b) * is countably infinite and we know that
power set of countably infinite is uncountable.

Set of TM is countable it means we can design a TM which can generate all the
TM and such TM is known as Universal Turning Machine.

Set of Language containing the complement of recursively language is uncountable


infinite set.

Different type of TM

Multi-tape Turing Machines have multiple tapes where each tape is accessed
with a separate head. Each head can move independently of the other heads.
Initially the input is on tape 1 and others are blank. At first, the first tape is
occupied by the input and the other tapes are kept blank. Next, the machine reads
consecutive symbols under its heads and the TM prints a symbol on each tape and
moves its heads.
A Multi-tape Turing machine can be formally described as a 6-tuple (Q, X, B, δ,
q0, F) where −

 Q is a finite set of states

 X is the tape alphabet

 B is the blank symbol

 δ is a relation on states and symbols where

δ: Q × Xk → Q × (X × {Left_shift, Right_shift, No_shift })k

where there is k number of tapes

 q0 is the initial state

 F is the set of final states

Note − Every Multi-tape Turing machine has an equivalent single-tape Turing


machine.

Multi-track Turing machines

Multi-track Turing machines, a specific type of Multi-tape Turing machine,


contain multiple tracks but just one tape head reads and writes on all tracks. Here,
a single tape head reads n symbols from n tracks at one step. It accepts recursively
enumerable languages like a normal single-track single-tape Turing Machine
accepts.

A Multi-track Turing machine can be formally described as a 6-tuple (Q, X, ∑, δ,


q0, F) where −

 Q is a finite set of states


 X is the tape alphabet

 ∑ is the input alphabet

 δ is a relation on states and symbols where

δ(Qi, [a1, a2, a3,....]) = (Qj, [b1, b2, b3,....], Left_shift or Right_shift)

 q0 is the initial state

 F is the set of final states

Note − For every single-track Turing Machine S, there is an equivalent multi-


track Turing Machine M such that L(S) = L(M).

In a Non-Deterministic Turing Machine, for every state and symbol, there are a
group of actions the TM can have. So, here the transitions are not deterministic.

The computation of a non-deterministic Turing Machine is a tree of configurations


that can be reached from the start configuration.

An input is accepted if there is at least one node of the tree which is an accept
configuration, otherwise it is not accepted.

If all branches of the computational tree halt on all inputs, the non-deterministic
Turing Machine is called a Decider and if for some input, all branches are
rejected, the input is also rejected.

A non-deterministic Turing machine can be formally defined as a 6-tuple (Q, X,


∑, δ, q0, B, F) where −

 Q is a finite set of states

 X is the tape alphabet

 ∑ is the input alphabet

 δ is a transition function;

δ : Q × X → P(Q × X × {Left_shift, Right_shift}).


 q0 is the initial state

 B is the blank symbol

 F is the set of final states

A Turing Machine with a semi-infinite tape has a left end but no right end. The
left end is limited with an end marker.

It is a two-track tape −

 Upper track − It represents the cells to the right of the initial head position.

 Lower track − It represents the cells to the left of the initial head position
in reverse order.

The infinite length input string is initially written on the tape in contiguous tape
cells.

The machine starts from the initial state q0 and the head scans from the left end
marker ‘End’. In each step, it reads the symbol on the tape under its head. It writes
a new symbol on that tape cell and then it moves the head either into left or right
one tape cell.

A transition function determines the actions to be taken.

It has two special states called accept state and reject state. If at any point of
time it enters into the accepted state, the input is accepted and if it enters into the
reject state, the input is rejected by the TM. In some cases, it continues to run
infinitely without being accepted or rejected for some certain input symbols.
Note − Turing machines with semi-infinite tape are equivalent to standard Turing
machines.
Cs -2011

Special point

 We have discussed PDA with single stack but there exist two stack PDA, 2
stack PDA can accept all the language which can be accepted by TM.
 If string is in the form of a and b that language go till context sensitive.
 Turing machine will involve where function type language is given.
Co-Re

Those languages which are not recursive enumerable but their complement are
recursive enumerable.

Example

L = {w | w belongs L(Ti)}

Given language is recursively enumerable i.e. partially decidable

L = {w | M halts on w}

Given language is recursively enumerable (partially decidable)

Example

We have taken string and run on one TM it halts and in other turning machine it
goes into the loop means we can say this property is partially decidable. So given
language is recursively enumerable language.

L= {w| M does not halt on w}

Non recursive language

L ={<M> | L(M) = Φ}

Purely undecidable(RE)

Some important points


 Recursive language is TM decidable and recursive enumerable is TM
recognizable.
A∝B

If A is undecidable then B is also undecidable and if B is decidable then A is


decidable and if B is recursive enumerable then A is also recursive enumerable.

 Transitive property holds in reduction

A ∝ B and B ∝ C A ∝ C

 Post correspondence problem is undecidable problem except over single


symbol and modified correspondence problem is undecidable except over
single symbol.
 Rank of non-terminal of infinite grammar string is infinite
 X AB
Rank(X)>rank (A) and rank(X)>rank(B)

Rank of non-terminal means longest path from any non-terminal

Example

S AB

A B

Rank(S)=2

 Rank(A)=1
 Rank(B)= 0
Language shown below is neither RE nor Co-RE

 Whether L is regular language


 Whether L is finite
 Whether L(M1)=L(M2)
 Whether L =∑*
 Whether L is recursive
 L has only one string
Language shown below are some language which is RE but not Co-RE

 L ≠Φ
 L(M1) ≠ L(M2)
 L halts on w
 L contain at least eight members.
POST CORRESPONDENCE PROBLEM

The Post Correspondence Problem (PCP), introduce, is an undecidable decision


problem. The PCP problem over an alphabet ∑ is stated as follows −

Given the following two lists, M and N of non-empty strings over ∑ −

M= (x1, x2, x3,………, xn)

N= (y1, y2, y3,………, yn)

We can say that there is a Post Correspondence Solution, if for some i1,
i2,………… ik, where 1 ≤ ij≤ n, the condition xi1…….xik = yi1....yik satisfies.

Example
Find whether the lists

M = (abb, aa, aaa) and N = (bba, aaa, aa)

have a Post Correspondence Solution?

Solution
x1 x2 x3

M Abb aa aaa

N Bba aaa aa

Here,

x2x1x3 = ‘aaabbaaa’

and y2y1y3 = ‘aaabbaaa’

We can see that

x2x1x3 = y2y1y3

Hence, the solution is i=2, j =1, and k=3.

Example 2
Find whether the lists M = (ab, bab, bbaaa) and N = (a, ba, bab) have a Post
Correspondence Solution?

Solution

x1 x2 x3

M ab bab bbaaa

N a ba bab

In this case, there is no solution because −

| x2x1x3 | ≠ | y2y1y3 | (Lengths are not same)

Hence, it can be said that this Post Correspondence Problem is undecidable.


Important table

 If at most word exist, then it will never be RE and if atleast word exist it will
be RE.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy