automata theory, languages and computation · web viewautomata theory, languages and computation 7...

74
CONTENTS Chapter -1 P, NP, Exponential time complexity 2 Chapter-2 Automata Theory, Languages and computation 7 Chapter-3 Push-Down Automata and Turing Machine 29 Chapter-4 SAT Problems 44 Chapter-5 Some Applications 52 1

Upload: others

Post on 18-Mar-2021

11 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Automata Theory, Languages and computation · Web viewAutomata Theory, Languages and computation 7 Chapter-3 Push-Down Automata and Turing Machine 29 Chapter-4 SAT Problems 44 Chapter-5

CONTENTS

Chapter -1 P, NP, Exponential time complexity 2

Chapter-2Automata Theory, Languages and computation 7

Chapter-3Push-Down Automata and Turing Machine 29

Chapter-4SAT Problems 44

Chapter-5Some Applications 52

1

Page 2: Automata Theory, Languages and computation · Web viewAutomata Theory, Languages and computation 7 Chapter-3 Push-Down Automata and Turing Machine 29 Chapter-4 SAT Problems 44 Chapter-5

CHAPTER-1

P, NP, Exponential time complexity

There are problems that can be solved in polynomial time (called as tractable or easy

problem) and a set of problems that cannot be solved in polynomial time or solved in

exponential function of the problem size N (called as intractable or Hard problem).

I.BASIC FUNDAMENTAL CONCEPTS 1. Polynomial time Algorithms:-

An algorithm is said to be polynomial time if its running time is upper bounded (worst

case running time) by a polynomial in the size of the input.

Why time complexity?

A. Efficiency considerations for algorithms:-

It inherently tied in with the design, implementation and analysis of algorithms. Every

algorithm must use up some of a computer’s resources (CPU time & Memory Space) to

complete its task. Because of the high cost of computing resources it is always desirable to

design algorithms that are economical in the use of CPU time & memory.

B. Algorithm analysis:-

An algorithm is mainly analyzed to determine time complexity (the execution time of

the program) &Space complexity (the total memory space required).

Why analysis (what we do before coding) the algorithm?

(i) Analysis is more reliable than testing (testing is done only on specific cases of

input).

(ii) Helps to select better algorithm (different algorithms for same task)

(iii) Predicts performance (runtime of an algorithm)

(iv) Identifies scope of improvement of algorithm (which portion of algorithm is faster

& slower)

C. Focus only on time complexity:-

The execution time of a program cannot be determined exactly. This is because the execution

time varies depending on various factors like choice of the programming language, computer

2

Page 3: Automata Theory, Languages and computation · Web viewAutomata Theory, Languages and computation 7 Chapter-3 Push-Down Automata and Turing Machine 29 Chapter-4 SAT Problems 44 Chapter-5

hardware etc. we analyze the relative running time of an algorithm as a function of its input

size.

D. Time complexity classes:-

Consider a few examples for dealing with the operation count algorithm (how many

number of times, the given statement is executed irrespective of the size of input ‘n’?)

T(n) – Time complexity based on input size ‘n’.

1. Constant (e.g. prints the first element of the array)Printf(“%d”,data[0]) The statement is executed once. Hence, operation count is constant. T(n)=1

2. Linear (n) (e.g. prints the elements of an array.)For(i=0;i<n;i++)Printf(“%d”,data[i]);(i.e.) T(n)=n

3. Quadratic(n2) (e.g. prints the elements of n*n matrix.)

For(i=0;i<n;i++) For(j=0;j<n;j++)

Printf(“%d”,data[i][j]);(i.e.) T(n)=n2

4. Polynomial time (e.g. perform matrix multiplication)For(i=0;i<n;i++)

For(j=0;j<n;j++) Sum=0

For(k=0;k<n;k++)Sum=sum+(mat1[i][k]*mat2[k][j]);

(i.e.) T(n)=n3+2n2 . Because innermost loop is n2, middle loop is (n2)+n+n & outer loop is n((n2)+n+n)

-5. Logarithmic (T(n)=log n)

Algorithms that break the problem into smaller ones belong to this class.E.g. searching an element in a Binary search tree Here searching time can be reduced to O(h) (where ‘h’height of the tree)‘n’-nodes then ‘log n’-levels.

6. Linearithmic (T(n)=n log n)Algorithms that break the problem into smaller ones and then combine their result together will belong to this class.E.g. merge sort (Divide and Conquer approach)

3

Page 4: Automata Theory, Languages and computation · Web viewAutomata Theory, Languages and computation 7 Chapter-3 Push-Down Automata and Turing Machine 29 Chapter-4 SAT Problems 44 Chapter-5

It requires log n iteration to form a list of size ‘n’ & in each level there are at most ‘n’ comparisons.

7. Exponential (T(n)=2n)Algorithm that are based on brute-force search to find out solutions satisfying a condition.

E. Worst case, best case & average case Analysis:-

Consider a simple problem that prints the first even number in the array. Here the time

complexity is depends on the actual input.

Case 1: If the first element itself happen s to be even, then T(n)=1. (Best case or Lower

bound)

Case 2: If only the last element is even, then T(n)=n. (Worst case or Upper bound)

Case 3: The even element being anywhere in the array, then it is difficult to derive T(n)

because it requires knowledge about the distribution of the element. (Average case or

Tight bound)

F. Order of growth rate of algorithm:-

Consider the following computational complexity table as a function of problem size ‘N’

Log N N N Log N N2 N3 2N N!

1 2 2 4 8 4 2

3.322 10 33.22 100 1000 >103 3628800

6.644 100 664.4 10000 1000000 >>1025 - 9.332e157

9.966 1000 9966.0 1000000 109 >>10250 4.0287e2567

13.287 10000 132877 108 1012 >>102500 2.846e35659

From the above table, (at left most end) in Logarithmic complexity algorithm does not

give a rapid changes when the size of input is grows high. But (right most end) in

exponential time complexity algorithm grows more rapidly as the size of the problem

increases.

-

For e.g. consider the 3 different complexities,

F(n)=100n+2 G(n)=n4 H(n)=2n

For n=1 =102 =1 =2

For n=5 =502 =625 =32

For =1002 = >1012 =>>1025

4

Page 5: Automata Theory, Languages and computation · Web viewAutomata Theory, Languages and computation 7 Chapter-3 Push-Down Automata and Turing Machine 29 Chapter-4 SAT Problems 44 Chapter-5

n=100

From the above e.g., initially F(n) >H(n) > G(n) and next step F(n)>H(n)<G(n). At last

stage F(n)<G(n)<H(n). So the order of growth of function is majorly depends on input

size. After it reaches some bound, the relationship between those complexities will

become stable. For defining those bound, we then move on to Asymptotic Analysis.

G. Asymptotic analysis:-

How the execution time may increase when the input size increases

Is performed to measure the order of growth.

For a larger N, in asymptotic analysis only the largest term in the

time complexity is considered and also the constant multiplier in it

are ignored.

For e.g. 2n3+5n2+1 could behave asymptotically as n3 (as far as

growth of this function is considered, n3 growth takes over that of n2.

Also 2n3 and 4n3 will not have much different). For T(n)=4n log

n+3n is asymptotically as (n log n).

Some Notations are used to define the time complexity, such as Big

Oh (O)-Worst case behavior, Omega (Ω)-Best Case and Theta (Ө)-

Average case.

O(Log N) <O( N) < O(N log N) <O( N2) <O( N3) <O( 2n)

Complexity classes of problems:-1. Class P (polynomial):- (also called as PTIME or DTIME)

This complexity class is the set of all polynomially solvable problems. It is one

of the most fundamental complexity classes. P is also known to be at least as large as L

(Logarithmic), (i.e.) L is a subset of P. Any problem that is not in P is Hard.

E.g. Kruskal’s Algorithm (Greedy algorithm)

2. NP Problems (Non Deterministic Polynomial):-

It is a set of all problems for which solution can be guessed and

verified in polynomial time. Here non-deterministic means there are

no formal steps to be followed to solve the problem. NP complexity

class includes problem with exponential time but have not proved

that there is no polynomial time algorithm to solve it.

Normally it deals with decision problem (is one, which has a

solution of the form ‘yes/no’, like Have you registered for ME

5

Page 6: Automata Theory, Languages and computation · Web viewAutomata Theory, Languages and computation 7 Chapter-3 Push-Down Automata and Turing Machine 29 Chapter-4 SAT Problems 44 Chapter-5

course? Is 2005 a leap year? In this, you determine whether some

potential solution to a problem is actually a solution or not.)

Class P is a subset of NP.

E.g. Simple path in a graph(no vertices are repeated in the path).

An example of an NP-easy problem is the problem of sorting a list of

strings. The decision problem "is string A greater than string B" is in

NP. There are algorithms such as Quick sort that can sort the list

using only a polynomial number of calls to the comparison routine,

plus a polynomial amount of additional work. Therefore, sorting is

NP-easy.

3. NP Hard problems

It is the set of all problems such that any NP problem can be reduced

to them in polynomial times. NP hard problems generalize the set of

computational search problems.

If a NP hard problem is solved in polynomial time, it is possible to

solve all problems in the class NP in polynomial time.

An example of an NP-hard problem is the decision subset sum

problem, which is this: given a set of integers, does any non empty

subset of them add up to zero? That is a yes/no question, and

happens to be NP-complete. Another example of an NP-hard

problem is the optimization problem of finding the least-cost route

through all nodes of a weighted graph. This is commonly known as

the Travelling sales man problem.

4. NP Complete problems

The set of problems that are both NP and NP hard. NP complete is a

subset of NP; in addition it is also NP hard.

A polynomial time algorithm can be used to get approximate

solution to NP complete problems. Note that these solutions need not

be optimal.

All NP complete problems are equivalent, i.e. if there is a

polynomial time algorithm for any NP complete problem, and then

all other NP complete problems also have polynomial time

algorithms.

6

Page 7: Automata Theory, Languages and computation · Web viewAutomata Theory, Languages and computation 7 Chapter-3 Push-Down Automata and Turing Machine 29 Chapter-4 SAT Problems 44 Chapter-5

E.g. Graph coloring problem, minimum spanning tree.

Solving NP Complete problem:-

No formal procedures to solve NP Complete problems, any one of

the following approaches can be used.

Approximation, Probabilistic, Heuristic, Special algorithm,

polynomial reduction, Polynomial transformation, NP completeness.

NP-naming convention:-

NP-Complete -means problems that are complete in NP (i.e., any problem reduces to any other

problem in polynomial time)

NP-hard - stands for at least as hard as NP (but not necessarily in NP)

NP-easy - stands for at most as hard as NP (but not necessarily in NP)

CHAPTER-2

Automata Theory, Languages and computation

Introduction:

Aim to study Automata Theory: This is to find the complexity i.e study of limits of a problem or model and to reduce the complexity using grammar. Finite automata are useful model for many kinds of Hardware and software design.

The problem that can be solved by a computer are called decidable problem. Otherwise a problem is said to be undecidable. Within the decidable problems, the problems that can be solved by a computer using no more times then some slowly growing function of the size of the input are called “Tractable Problems”.

Depending upon the computation complexity, the problem can further be divided as NP, NP complete. The study of Automata helps to decide in which clause the problem belongs.

Grammars and regular expressions plays an important rule in the study of Automata Theory and their applications.

Grammars:

Grammars are usual models when designing software that process data with a recursive structure.

7

Page 8: Automata Theory, Languages and computation · Web viewAutomata Theory, Languages and computation 7 Chapter-3 Push-Down Automata and Turing Machine 29 Chapter-4 SAT Problems 44 Chapter-5

Regular Expressions:

Denote the structure of data especially text string to be searched i.e a declarative way to express the strings we want to accept. Regular Expressions is another way of representing a regular language.

The system converts the regular expression into either a DFA or an NFA and simulate the Automaton.

Regular Language and Automata:

The simplest language is a regular language and the corresponding machine which accept a regular language is finite automata, a simple computing machine.

A finite automaton has a set of states and its control moves from state to state in response to external inputs.

A distinction in classes of finite Automata is whether that control is ‘deterministic’ or ‘non deterministic’ meaning that the Automaton can’t be in more than one state at any one time, or it can be in several states at any one input respectively.

I - Deterministic Finite Automata:A deterministic finite Automata A = (Q, Σ, δ, q0, F) where

Q – Finite set of States

Σ – Finite set of Inputs

δ – Transition function, δ:(Q * Σ ) → Q

q0 – Starting State

F – Set of all Finite State.

8

Page 9: Automata Theory, Languages and computation · Web viewAutomata Theory, Languages and computation 7 Chapter-3 Push-Down Automata and Turing Machine 29 Chapter-4 SAT Problems 44 Chapter-5

1. The transition diagram for the DFA accepting all strings with a substring 01.

The corresponding machine is A= (q0, q1, q2, 0, 1, δ, q0, q2)

δ 0 1q0 q1 q0q1 q1 q2q2 q2 q2

Thus δ can be extended to a string δ (q1, 11011) = q2

The Regular Grammar for the above example where A = q0, B = q1 and C = q2 is:

A → 1A

A → 0B

B → 1C

C → 0C | 1C.

And the regular expression is: (1)* 0 (0)* 1 (0+1)*.

2. The set of all strings begins with 01 and end with 11.

3. The set of all strings which do not contain three consecutive zeroes i.e. the complement automata which contain three consecutive zeros. First A1 is

9

Page 10: Automata Theory, Languages and computation · Web viewAutomata Theory, Languages and computation 7 Chapter-3 Push-Down Automata and Turing Machine 29 Chapter-4 SAT Problems 44 Chapter-5

Then A1 complement is:

4. Second symbol from right end is 1

5. Every zero’s is immediately followed by 1.

10

Page 11: Automata Theory, Languages and computation · Web viewAutomata Theory, Languages and computation 7 Chapter-3 Push-Down Automata and Turing Machine 29 Chapter-4 SAT Problems 44 Chapter-5

6. Number of zeros divisible by 3.

7. Every substring of 3 symbols containing 1.

8. Length of string divisible by 2 or 5.

9. Two consecutive zeros or ones.

10. Strings which don’t contain exactly one 1.(i). Construct an automata which contain exactly one 1, then take complement. Automata contain exactly one 1.

11

Page 12: Automata Theory, Languages and computation · Web viewAutomata Theory, Languages and computation 7 Chapter-3 Push-Down Automata and Turing Machine 29 Chapter-4 SAT Problems 44 Chapter-5

its complement.

II - Deterministic vs. Non DeterministicConsider the grammarS → As, S → aA, A → bB, A → b, B → bB, B → b

To generate the string ab, machine must make the choice between S and A.

The nondeterminism occurs at S can be converted to deterministic.

Any deterministic machine is a special case of a non deterministic one. Non deterministic finite

state machine need not be powerful then the deterministic finite state machine and we can

construct an equivalent deterministic machine for a given non Deterministic finite state

machine.

12

Page 13: Automata Theory, Languages and computation · Web viewAutomata Theory, Languages and computation 7 Chapter-3 Push-Down Automata and Turing Machine 29 Chapter-4 SAT Problems 44 Chapter-5

Consider the NDFA

a b

→q0 q0,q1 Ф

q1 Ф q1,q2

q2 Ф Ф

The Equivalent DFA is

Exercise:Give the non deterministic finite automata to accept the following over 0, 1*.

1. The set of all strings such that containing either 101 or 110 as substring.

2. The set of all strings such that every 1 is followed immediately by 00.

Use of Star Operator:Σ* - All Strings whose symbols were chosen from alphabet Σ.

Σ: the collection of all input symbols. Let Σ = 0

L: the Language and collection of strings L = 0, 00

Σ ≠ L.

On the other hand L* denotes the same language as Σ *.

1. Consider the regular expression (01)+ + (010)+

Then the corresponding NFA is

13

Page 14: Automata Theory, Languages and computation · Web viewAutomata Theory, Languages and computation 7 Chapter-3 Push-Down Automata and Turing Machine 29 Chapter-4 SAT Problems 44 Chapter-5

Corresponding DFA is

2. LR = X | XR ε L (M) is reverse of the language obtained by reversing the automata as end

state as starting state. Any string in Σ = 0, 1, strings to start with (01(0+1)*)

Reversing the language is (0+1)*10

III = Regular ExpressionsRegular expressions are another way to specify regular sets.

14

Page 15: Automata Theory, Languages and computation · Web viewAutomata Theory, Languages and computation 7 Chapter-3 Push-Down Automata and Turing Machine 29 Chapter-4 SAT Problems 44 Chapter-5

If E1 and E2 are regular expressions E1UE2, E1E2, E1* are regular expressions.

ε, φ are regular expressions.

Regular expressions of

1. All Strings with no consecutive 1’s (10)*, (100*)*, 0* (100*)* (1+ ε)

2. All strings with equal number of 0’s and 1’s. (1(10)*0+0(01)*1)*

3. Every pair of adjacent 0’s appears before any pair of adjacent 1’s. (00(11))*.

4. No pair of adjacent 1’s. 0* (10+0)*(1+0)

5. 10 th symbol from a end is 1. (0+1)* 1 (0+1) (0+1)….(0+1).

6. All strings number of 0’s divisible by 5. (1*01*01*01*01*0)*

7. Strings not containing substring 101. (1+0) (1+00+000) * (0+ε)

8. When R1, R2, ….. Rn, S1, S2, …. Sn are the regular expressions with the L1 as a

language then R1L1*S1 + R1L1*S2 +R1L1*S3 + …. Can be shown as follows

Consider the regular expression (0+1)*10(0+1)*+ (0+1)*11(0+1)*.

The simplified expression is (0+1)*(10+11) (0+1)*. Hence we can convert a DFA to a regular

expression and we can use a state elimination procedure to build the regular expression for a

DFA

Following are the Automata for the regular Expression

.

ε:

Ф:

a:

R1 + R2

15

ε

a

Page 16: Automata Theory, Languages and computation · Web viewAutomata Theory, Languages and computation 7 Chapter-3 Push-Down Automata and Turing Machine 29 Chapter-4 SAT Problems 44 Chapter-5

R1R2

(R1)*

Pumping Lemma:

To prove certain language is not regular we use pumping lemma.

Statement: Let L be the regular language then there exists a constant n (which depends on L)

such that for every string w in L |w| ≥ n, we can break w into three strings, w =xyz, such that:

1. y ≠ ε

2. | xy | ≤ n

3. For all k ≥ 0, the string xykz is also in L.

Some Examples of the Language which are not regular:

1. Show that L = ap : p is a prime is not regular.

Let L be the language consisting of all a’s whose lengths are prime. Suppose L is a regular

language. Then the Pumping Lemma must hold. Then L is accepted by an automata M with n

states. If p is a prime number greater than n, consider z = ap ε L, |z| = p,

By pumping lemma z = uvw and uviw ε L for i ≥ 1.

In particular consider |uvP+1w| = |uvw| + |vp | = p + pr = (1+r)p , as length of v is r.

16

Page 17: Automata Theory, Languages and computation · Web viewAutomata Theory, Languages and computation 7 Chapter-3 Push-Down Automata and Turing Machine 29 Chapter-4 SAT Problems 44 Chapter-5

We got a string uvP+1w whose length (1+r)p is not prime. So contradiction and hence L is not regular.

In Z = |aaaaaaa| let u = aa v= aaa, w= aa

For i= 2, we get uv2w= aa (aaaaaa) aa whose length is 10 which is not prime. Hence L is

not regular.

2. Prove that the language consisting of all palindromes is not regular.

Let L be the language consisting of all palindromes. Suppose L is a regular language.

Then the Pumping Lemma must hold. Let p be the pumping length for L. Consider

z = aa……..a(n times) b aa…….a(n times) ε L

Since |z| ≥ n, z can be written as z = uvw such that

(a) for every i≥ 0; uviw ε L, and

(b) |v| > 0, and

(c) |uw| ≤ n.

Since | v| > 0, uv2w = is the string v repeated 2 times is not a palindrome, and thus it is not in

L. Contradiction. We conclude that the language consisting of all palindromes is not regular.

Exercise

1. L= anbn | n>=1

2. L = 0n | n is a perfect square

3. L = 0n | n is a perfect cube

4. L = 0n | n is a power of 2

IV - Closure Properties of Regular Languages:1. The union of two regular languages is also a regular language.

Proof:

Let M1 = (Q1, Σ, d1, q0, F1) be finite automaton for L1 and M2 = (Q2, Σ, d2, q0, F2) be

finite automaton for L2. We want to construct a finite automaton M = (Q, Σ,d, q0, F) that

recognizes L = L1 È L2 .

Q = pairs of states, one from M1 and one from M2

= (q1, q2) | q1 Î Q1 and q2 Î Q2

= Q1 ´ Q2

F = F1 ´ F2.

and d((qi,qj),w) = d1(qi,w), d2(qj,w).

17

Page 18: Automata Theory, Languages and computation · Web viewAutomata Theory, Languages and computation 7 Chapter-3 Push-Down Automata and Turing Machine 29 Chapter-4 SAT Problems 44 Chapter-5

Example 1:

L1 L2

L1: any string in Σ=ε, 0,1 has even

Number of 1’s

L2: any string in Σ= 0, 1 has odd

Number of 0’s

Automaton for Union: L1 U L2: the set of language either even number of 1’s or odd

number of 0’s

Thus, if L1 and L2 are two regular languages then so is L1 È L2 .

2. Intersection of two regular languages is regular

Proof:

Let M1 = (Q1, Σ, d1, q0, F1) be finite automaton for L1 and M2 = (Q2, Σ, d2, q0, F2) be

finite automaton for L2. We want to construct a finite automaton M = (Q, Σ,d, q0, F) that

recognizes L = L1 L2 .

Q = (qi, qj) | qi Î Q1 and qj Î Q2

= Q1 ´ Q2

F = F1 ´ F2.

and F = (qi, qj) | qi Î F1 and qj Î F2

18

Page 19: Automata Theory, Languages and computation · Web viewAutomata Theory, Languages and computation 7 Chapter-3 Push-Down Automata and Turing Machine 29 Chapter-4 SAT Problems 44 Chapter-5

Example:

Automaton for Intersection

Automaton for Intersection : L1 L2 : the set of language which has even number of

1’s and odd number of 0’s

Example 2

Intersection and union of two languages L1 = w | w has exactly two a’s and L2 = w | w has at least two b’s.

Find L1 L2 , L1 U L2:

L1

L2:

19

Page 20: Automata Theory, Languages and computation · Web viewAutomata Theory, Languages and computation 7 Chapter-3 Push-Down Automata and Turing Machine 29 Chapter-4 SAT Problems 44 Chapter-5

L1 L2:

L1 U L2:

3. Complement of regular is regular.

Proof:

Let L = L (A) for some DFA A = (Q, , δ, q0, F). Then L` = L (B), where B is the DFA

(Q, , δ`, q0, Q-F). That is B is exactly like A, but the accepting states of A have become no

accepting states of B and vice versa. Then w is in L(B) if and only if δ` (q0, w) is in Q-F, which

occurs if and only if w is not in L(A). Hence L` is a regular language.

Consider the above example 10. Construct an automata which should not contain exactly one 1.

20

Page 21: Automata Theory, Languages and computation · Web viewAutomata Theory, Languages and computation 7 Chapter-3 Push-Down Automata and Turing Machine 29 Chapter-4 SAT Problems 44 Chapter-5

To solve the above problem first construct an automata which contain exactly one 1 and then take the compliment to accept the string which do not contain exactly one 1.

i). Automata contain exactly one 1.

ii). Compliment of the above by converting final state to non final state.

4. Derivative of a language:

Let L be a language, x be a string with x ε L*, L contained in Σ *. Then the derivative of L with

respect to x is defined as

Lx = y ε Y | xy ε L denoted by б x L.

If L= 01, 001, 0, 100, 10101 then Lx = 1, 01, 101 and Ly = 0, 100, 01

The following are true:

If L is a regular set, Lx is regular for any x.

If L is a regular set LxULy, LxLy is also regular sets.

5. Regular languages are closed under homomorphism

Proof:

Let r be the regular expression for the regular languages L and h be the homomorphism.

h(r) is an expression obtained by substituting h(a) for each symbol a in r. Clearly h (a) is a

regular expression. Hence h(r) is a regular expression for every w ε L(r) the corresponding

h(w) will be in L(h(r)) and conversely.

21

Page 22: Automata Theory, Languages and computation · Web viewAutomata Theory, Languages and computation 7 Chapter-3 Push-Down Automata and Turing Machine 29 Chapter-4 SAT Problems 44 Chapter-5

Exercise:1. Construct a DFA according to the following conditions:

1. Third symbol from the right is zero.

2. The set of strings in a, b, c containing bca as a substring.

3. The set of strings in (a)* whose length is divisible by 2 or 9.

4. The set of strings in 0, 1 consisting of neither consecutive zeroes nor consecutive

ones.

5. Intersection and union of two languages L1 and L2 where L1= w | w has an even

number of a’s and L2= w | each a is followed by b.

2. Write regular expressions for the following languages:

1. The set of all strings such that the number of 0’s is odd.

2. The set of all strings that contain 1011.

3. Give state diagrams of DFA s recognizing the following languages. In all parts the

alphabet is 0, 1.

1. w | every odd position of w is 1

2. w | w has length at least 3 and its third symbol is a 0

3. All strings except the empty string.

3. Design a PDA to accept each of the following languages:

1. aibjck | i ≠ j or j ≠ k

2. The set of all strings of a’s and b’s that are not or the form ww, that is, not equal to any

string repeated.

4. Each of the following languages is the intersection of two simpler languages. In each part,

construct DFA for the simpler languages then combine them. In all parts Σ = a, b.

1. w | w has at least three a’s and at least two b’s

2. w | w has an even number of a’s and one or two b’s

3. w | w has an even number of a’s and one or two b’s

4. w | w has an odd number of a’s and ends with a b

5. w | w has an even length and an odd number of a’s

5. Each of the following languages is the complement of two simpler languages. In each part,

construct DFA for the simpler languages then combine them. In all parts Σ = 0, 1.

1. w | w doesn’t contain the substring 01

2. w | w doesn’t contain the substring 1010

22

Page 23: Automata Theory, Languages and computation · Web viewAutomata Theory, Languages and computation 7 Chapter-3 Push-Down Automata and Turing Machine 29 Chapter-4 SAT Problems 44 Chapter-5

3. w | w contains neither the substrings 01 nor 10

4. w | w is any string not in (01+)*

5. w | w is any string not in 0*1*

6. w | w is any string not in 0* U 1*

7. w | w is any string that doesn’t contain exactly two zeroes

8. w | w is any string except 0 and 1

6. Give state diagrams of DFA s recognizing the following languages. In all parts Σ = a, b.

1. w | w begins with one a and ends with one b

2. w | w contains at least three b’s

3. w | w contains the substring abab that is w = xababy for some x and y

4. w | w has length at least three and its third symbol is one a

5. w | w start with a and has odd length or start with b and has even length

6. w | w doesn’t contain the substring bba

7. w | the length of w is at most 5

8. w | w is any string except bb and bbb

9. w | every odd position of w is one b

10. w | w contains at least two a’s and at most one b

11. w | w contains even number of a’s or contains exactly two b’s

1. alt (w, x) is regular:

Proof:

If w = a1a2…an and x = b1b2…bn are strings of same length then we can define alt (w, x)

to be the string in which the symbols of w and x alternate, starting with w, that is,

a1b1a2b2….anbn. Since L and M are regular there exists automata for them and combining both

that we can get the automata for alt (w, x).

2. half (L) is regular.

Proof:

half(L) = w | xw ε L, | x | = |w|

3. Reverse of a Language:

Any string w = w1w2…wn, the reverse of w written as wR is the string w in reverse order

wn….w2w1. For any language A, Let AR = wR | w Є A.

Example:

Let L = w Є Σ* | w ends in 11 where Σ = 0, 1

23

Page 24: Automata Theory, Languages and computation · Web viewAutomata Theory, Languages and computation 7 Chapter-3 Push-Down Automata and Turing Machine 29 Chapter-4 SAT Problems 44 Chapter-5

To find the DFA which ends with 11 is equal to construct the DFA which starts with 11

and to reverse that. The DFA which has the starting symbol as 11 is:

V- Minimization of Automata

1. Myhill-Nerode Theorem:

Myhill-Nerode theorem and minimization to eliminate useless states. The Myhill-Nerode Theorem says the following three statements are equivalent:

1) The set L Í * is accepted by some FA. (We know this means L is a regular Language.)

2) L is the union of some of the equivalence classes of a right invariant (with respect to

concatenation) equivalence relation of finite index.

3) Let equivalence relation RL be defined by: xRLy if and only if for all z in *, xz is in L

exactly when yz is in L. Then RL is of finite index.

2. Equivalence of Minimization of Automata:

Let P and Q be two distinct states.

We say that both the states P and Q are equivalent if for all input strings w, δ (P, w)

is an accepting state iff δ (Q, w) is an accepting state.

24

Page 25: Automata Theory, Languages and computation · Web viewAutomata Theory, Languages and computation 7 Chapter-3 Push-Down Automata and Turing Machine 29 Chapter-4 SAT Problems 44 Chapter-5

the states p and s are equivalent

Minimize the following DFA:

Using table filling algorithm we get

B X

C X X

D X X X

E X X X

F X X X X

G X X X X X X

H X X X X X X

A B C D E F G

This shows the states (E, A) (F, D), (H, B) are equivalent.

Then the minimized diagram is:

25

Page 26: Automata Theory, Languages and computation · Web viewAutomata Theory, Languages and computation 7 Chapter-3 Push-Down Automata and Turing Machine 29 Chapter-4 SAT Problems 44 Chapter-5

EXERCISE:

• Minimize the following DFA

0 1

--->A B A

B A C

C D B

*D D A

E D F

F G E

G F G

H G D

Example:

1. w | w has even number of a’s and each a is followed by at least one b

Solution:

The automata that accept even number of a’s will look like this:

The automata that has every a followed by at least one b is:

26

Page 27: Automata Theory, Languages and computation · Web viewAutomata Theory, Languages and computation 7 Chapter-3 Push-Down Automata and Turing Machine 29 Chapter-4 SAT Problems 44 Chapter-5

Combining them using the intersection construction gives the DFA:

2. Let L = w Є Σ* | w ends in 11 where Σ = 0, 1

To find the DFA which ends with 11 is equal to construct a DFA which starts with 11

and to reverse that. The DFA which has the starting symbol as 11 is:

Homomorphism:

A string homomorphism is a function on strings that works by substituting a particular

string for each symbol.

Example:

27

Page 28: Automata Theory, Languages and computation · Web viewAutomata Theory, Languages and computation 7 Chapter-3 Push-Down Automata and Turing Machine 29 Chapter-4 SAT Problems 44 Chapter-5

The function h given by h (0) = abb and h (1) = ba is a homomorphism which replaces

each 0 by abb and each 1 by ba. Thus h (1011) = ‘baabbbaba’.

In a Language of all zeros bounded by 1’s i.e L = 10*1, then apply h(1) = ε , h(0) = a, then

the border alphabets are eliminated.

Consider the homomorphism h from the alphabet 0, 1, 2 to a, b defined by

h (0) = ab, h (1) = b, h (2) = aa then h (0210) is ‘abaabab’. Hence the homomorphism is used to

delete the state components by leaving the symbols.

CYK ALGORITHM It is used to identify the presence of the given string is generated by the given grammar without

generating the whole language. This is a polynomial Complete problem will take the

complexity of O(n3).

The following productions of a CNF grammar G.

S ----> AB | BC

A -----> BA | a

B ------>CC | b

C ------> AB | a

5 S,A,C

4 S,A,C

3 B B

2 S,A B S,C S,A

1 B A,C A,C B A,C

1

b

2

a

3

a

4

b

5

a

31 = 11.22+21.13 32 = 12.23+22.14

33 = 13.24+23.15 41 =11.32+21.23+31.14

42 =12.33+22.24+32.15 51 =11.42+41.15+21.33+31.24

EXAMPLE28

Page 29: Automata Theory, Languages and computation · Web viewAutomata Theory, Languages and computation 7 Chapter-3 Push-Down Automata and Turing Machine 29 Chapter-4 SAT Problems 44 Chapter-5

Let us check that the strings ‘abaab’, ‘bab’ and ‘bbb’ are generated by the following grammar

or not by constructing the CYK parse table:

S ---> AA | AS | b

A ---> SA | AS | a

For the string ‘bab’ the table looks like

3 S, A

2 A S, A

1 S A S

1 2 3

Since S which is the starting state is present in topmost row we can say that the string

‘bab’ ε L

For the string ‘bbb’ the table looks like

3 φ

2 φ φ

1 S S S

1 2 3

Since S which is the starting state is not present in topmost row we can say that the string

‘bbb’ doesn't belongs to L.

What is the complexity of CYK???????????.

CHAPTER-3

Push-Down Automata and Turing Machine

1. We need Push-Down Automata for the following reasons:

1. DFA accept regular languages only.

2. To design machines similar to DFAs that will accept context-free languages.

3. Push down automata is more powerful then DFA as it works with additional counter

memory.

4. For the language 0n1n | n ³ 0, the machine needs to “remember” the number of 0s.

5. To do this, we use a stack.

6. A push-down automaton (PDA) is essentially an NFA with a stack.

2. Formal Definition:29

Page 30: Automata Theory, Languages and computation · Web viewAutomata Theory, Languages and computation 7 Chapter-3 Push-Down Automata and Turing Machine 29 Chapter-4 SAT Problems 44 Chapter-5

A push-down automaton (PDA) is a seven tuple (Q, Σ, Γ, δ, q0, Z0, F) where

Q is a finite set of states.

Σ is a finite alphabet of tape symbols.

Γ is a finite alphabet of stack symbols.

q0 Î Q is the starting state.

F Í Q is the set of final states.

Z0 is the Stack Symbol.

δ is the transition function. δ is a triple δ (q, a, X) where

1. q is a state in Q.

2. a is either an input symbol in Σ or a = ε, the empty string which is assumed not

to be an input symbol.

3. X is a stack symbol, that is, a member of Γ

Block Diagram for a PDA:

3. Transitions:

Let δ (q, a, X) = (p, YZ), (r, ε) be a

transition.

It means that we

1. Move from state q.

2. Read a from the tape,

3. Pop the string X from the stack,

4. We could go to state p and replace X by YZ or state r and pop X.

5. We can’t go to state p and pop X and we can’t go to state r and replace X by YZ.

4. Example:

PDA to accept the language anbn | n ≥ 130

Page 31: Automata Theory, Languages and computation · Web viewAutomata Theory, Languages and computation 7 Chapter-3 Push-Down Automata and Turing Machine 29 Chapter-4 SAT Problems 44 Chapter-5

A = (q0, a Z0, a, b, c, a, b, Z0, δ, q0, qf). δ is defined by

δ (q0, a, Z0) = (q0, aZ0) δ (q0, b, Z0) = (q0, bZ0)

δ (q0, a, a) = (q0, aa) δ (q0, b, a) = (q0, ba)

δ (q0, a, b) = (q0, ab) δ (q0, b, b) = (q0, bb)

δ (q0, c, a) = (q1, a) δ (q0, c, b) = (q1, b)

δ (q0, c, Z0) = (q1, Z0)

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

δ (q1, ε, Z0) = (qf, ε )

5. Instantaneous Descriptions of PDA:

Definition 1:

Let A = (Q, Σ, Γ, δ, q0, Z0, F) be a PDA. AN instantaneous description (abbreviates as

ID) is (q, x, α) where q Є Q, x Є Σ* and α Є Γ*.

Definition 2:

An initial ID is (q0, x, Z0). This describes a PDA when the current state is q0, x is the

input string to be processed and PDS has only one symbol Z0.

Definition 3:

Let A be a PDA. A move relation (denoted by ) between ID’s is defined as

(q, a1a2…an, Z1Z2…Zn) (q`, a2a3…an, βZ2Z3…Zn) if δ(q, a1, Z1) contains (q`, β).

6. Acceptance of PDA:

Acceptance by Final State:

Let P = (Q, Σ, Γ, δ, q0, Z0, F) be a PDA. Then L(P), the language accepted by P by final

state, is w | (q0, w, Z0) (q, ε, α)

For some state q in F and any stack symbol α. That is, starting in the initial ID with w waiting

on the input, P consumes w from the input and enters an accepting State. The contents of the

stack at that time are irrelevant.

Acceptance by Empty Stack:

For each PDA P = (Q, Σ, Γ, δ, q0, Z0, F), we also define

N(P) = w | (q0, w, Z0) (q, ε, ε)

For any state q. That is, N (P) is the set of inputs w that P can consume and at the same time

empty stack.

7. Formal Definition of a Context Free Grammar:

A context free grammar is a four tuple (V, Σ, R, S), where

31

Page 32: Automata Theory, Languages and computation · Web viewAutomata Theory, Languages and computation 7 Chapter-3 Push-Down Automata and Turing Machine 29 Chapter-4 SAT Problems 44 Chapter-5

1. V is a finite state called the variables.

2. Σ is a finite set, disjoint from V, called the terminals.

3. R is a finite set of rules, with each rule V in a variable and a string of

variables and terminals and

4. S Є V is the start variable.

The context free grammar to generate the language 0n1n | n≥ 0 is

S → 0S1 | ε

8. Pumping Lemma for Context Free Languages:

Let L be a CFL. Then there exists a constant n such that if Z is any string in L such that

|Z| is at least n, then we can write z = uvwxy, subject to the following conditions:

1. |vwx| ≤ n. That is, the middle is not too long.

2. vx ≠ ε. Since v and x are the pieces to be “pumped” this conditions says that at

least one of the strings we pump must not be empty.

3. for all i ≥ 0, uviwxiy is in L. That is, the two strings v and x may be pumped any

number of times including 0 and the resulting string will still be a member of L.

32

Page 33: Automata Theory, Languages and computation · Web viewAutomata Theory, Languages and computation 7 Chapter-3 Push-Down Automata and Turing Machine 29 Chapter-4 SAT Problems 44 Chapter-5

Example:

Let L be the language 0n1n2n | n ≥ 1. That is, L consists of equal length of 0, 1 and 2,

e.g., 012, 001122, and so on. Let z = 001122 where u = 0, v = 01, w = 1, x = 12 and y = 2. For i

= 2 uviwxiy becomes 0(0101)1(1212)2 which is not in L. Hence L is not a CFL.

5. Configurations:

A configuration fully describes the current “state” of the PDA.

The current state p.

The remaining input w.

The current stack contents a.

Thus, a configuration is a triple

(p, w, a) Î (K, S*, G*).33

Page 34: Automata Theory, Languages and computation · Web viewAutomata Theory, Languages and computation 7 Chapter-3 Push-Down Automata and Turing Machine 29 Chapter-4 SAT Problems 44 Chapter-5

6. Accepting Strings:

After processing the string on the tape,

The PDA is in either a final or a non final state, and

The stack is either empty or not empty.

The input string is accepted if

The ending state is a final state, and

The stack is empty.

That is, the string w Î S* is accepted if (s, w, e) ¢* (f, e, e) for some f Î F.

One may define acceptance “by final state” only.

The input is accepted if and only if the last state is a final state, regardless of whether

the stack is empty.

One may define acceptance “by empty stack” only.

The input is accepted if and only if the stack is empty once the input is processed,

regardless of which state the PDA is in.

7. Example of a PDA:

PDA for L = x Є a, b, c* | |x|a + |x|b = |x|c

The transitions are:

δ (q0, a, Z0) = (q0, aZ0) , δ (q0, b, Z0) = (q0, bZ0), δ (q0, c, Z0) = (q0, cZ0)

δ (q0, a, a) = (q0, aa), δ (q0, a, b) = (q0, ab), δ (q0, b, a) = (q0, ba)

δ (q0, b, b) = (q0, bb), δ (q0, c, c) = (q0, cc), δ (q0, a, c) = (q0, ε)

δ (q0, b, c) = (q0, ε), δ (q0, c, a) = (q0, ε), δ (q0, c, b) = (q0, ε)

δ (q0, ε, Z0) = (qf, ε) where qf is the final state.

s p qa, e;

ab, a;

e

b, a; e

a, e; a

34

Page 35: Automata Theory, Languages and computation · Web viewAutomata Theory, Languages and computation 7 Chapter-3 Push-Down Automata and Turing Machine 29 Chapter-4 SAT Problems 44 Chapter-5

3. Consider the grammar G = (V, Σ, R, S) with V = S, a,b,c, Σ = a, b, c and R = S → aSa,

S → bSb, S → c, which generates the language wcwR : w Є a, b*. The corresponding

[pushdown automaton, according to the construction above, is M = (p, q, Σ, V, δ, p, q),

with

δ = ((p, e, e),(q, S)), ((q, e, S), (q,aSa)), ((q, e, S), (q, bSb)), ((q, e, S), (q, c)),

((q, a, a), (q, e)), ((q, b, b), (q, e)), ((q, c, c), (q, e))

The string abbcbba is accepted by M through the following sequence of moves.

state Unread Input Stack transition Used

p

q

q

q

q

q

q

q

q

q

q

q

q

abbcbba

abbcbba

abbcbba

bbcbba

bbcbba

bcbba

bcbba

cbba

cbba

bba

ba

a

e

e

S

aSa

Sa

bSba

Sba

bSbba

Sbba

cbba

bba

ba

a

e

T1

T2

T5

T3

T6

T3

T6

T4

T7

T6

T6

T5

4. The example illustrates the language aibjck | i, j, k ≥ 0 and i = j or i = k

35

Page 36: Automata Theory, Languages and computation · Web viewAutomata Theory, Languages and computation 7 Chapter-3 Push-Down Automata and Turing Machine 29 Chapter-4 SAT Problems 44 Chapter-5

Union of two context free language is context free,Let L1 and L2 are two CFL generated by CF Grammar

G1 = (V1,T1,P1,S1)

G2 = (V2,T2,P2,S2)

Assume that V1 and V2 are disjoint.

Consider a language L3 generated by the grammar G3 = (V1UV2US3, T1UT2 , P3, S3) at S3 is the

start symbol of G3 and S3 Є V1 U V2.

P3 = P1 U P2 U [S3→ S1 / S2] by the rule G3 is context free

It is very important that L3 = L1 U L2

If we assume wЄ L1 then form S3

S3 →S1 → W

Similarly if W Є L2

S3 →S2 → W so if WЄ L3 one of the derivation S3→ S1 and S3 →S2.

L3 = L1 U L2 is a CFL.

Example:

Let L1= anbn |n≥0

L2=bnan |n ≥0

G1 = S1→aSb

G2 = S2→bSa

Then G3 = S1,S2,S3,a,b,S→S1|S2, S1→aS1b | ε ,S2→bS2a |ε

L3 = anbn U bnan |n≥1.

For concatenation of CFL

G4 = (V1 U V2 US4, T1 U T2, P4,S4)

S4 is start symbol of G4 S4 Є V1 U V2

P4 = P1 U P2 U [S4→ S1S2]

Then G4 is context free with L4 = L1 L2

Example

Let L1= anbn |n≥0

L2=bnan |n ≥0

Then the grammar L1 L2

L1 L2 = anbm+n cn |m≥0

G= S→S1,S2,a,b,S→S1S2, S1→aS1b | ε ,S2→bS2a |ε ,S.

CFL is not closed under intersection

36

Page 37: Automata Theory, Languages and computation · Web viewAutomata Theory, Languages and computation 7 Chapter-3 Push-Down Automata and Turing Machine 29 Chapter-4 SAT Problems 44 Chapter-5

If L1 and L2 are context free languages, it is not always true that L1 L2 is not context free

language.

Proof by counter example

Consider L1 =anbncm | n≥0,m≥0

L2 =anbnck | n≥0,m≥0

S→S1,S2 S1→aS1b | ε S2→cS2 |ε are the corresponding grammar.

Now since n≤ m

Then L1 L2 =akbkck | k ≤mwhich not context free. We need two state to accept akbkck which

is not possibly for PDA .

Complement of CFL is again CFLIf L1 is CFL L1’ may or not be a CFL. That is CFL is not closed under complementation.

If at L1 and L2 are CFL. We assume complement of a CFL is CFL.

The union of CFL is CFL. That is L1’ U L2’ is CFL.

That is (L1’ U L2’)’ = L1 L2 is CFL which is a contradiction.

CFL is not closed under complement operation.

Example for context free grammar1. L= / where i=j , j=k , i=k

The context free grammar for the above language is:S → EFG ---- rules missing for F,GS → EC/F/GC → cC/єE → aEb/є

2. L= / wє (a+b)*The context free grammar for the above language is:S → aSa / bSb /є

3. L= / n,m ≥1The context free grammar for the above language is:S → S1S2

→ a S1b/ab → c S2 d / cd

4. L= / n,m ≥137

Page 38: Automata Theory, Languages and computation · Web viewAutomata Theory, Languages and computation 7 Chapter-3 Push-Down Automata and Turing Machine 29 Chapter-4 SAT Problems 44 Chapter-5

The context free grammar for the above language is:S → aSd/aTdT → bTc/bc

5. L= / n≥1The context free grammar for the above language is:S → aSbb / abb

6. L= / i≤jThe context free grammar for the above language is:S → aSb/Sb/є

7. L= / i≤j≤2iThe context free grammar for the above language is:S → aSb/aSbb/є

8. L= / ijThe context free grammar for the above language is:S → AB, A → aA/a, B → bB/b

9. L= / ijThe context free grammar for the above language is:S → TC, C → cC/є, T → aTbT → bB, B → bB/є

Exercise: 1. Give context free grammar that generates the following languages where ∑ is over 0,1 a.w / w starts and ends with the same symbol

b.w / w= , that is w is a palindrome c. w / w has more 0’s than 1’s

d. The complement of the language / n≥0

2. Use the pumping lemma to show that the following languages are not context free.

a. /n≥0

b. / n≥0

3. If A and B are languages, define A◊B = xy / xєA and yєB and |x| = |y|.Show that if A and B are regular languages, then A◊B is a context free language.

All regular languages are context-free languages.

38

Page 39: Automata Theory, Languages and computation · Web viewAutomata Theory, Languages and computation 7 Chapter-3 Push-Down Automata and Turing Machine 29 Chapter-4 SAT Problems 44 Chapter-5

Exercise:1. Consider the grammar G=(V,∑,R,S) where V=a,b,S,A, ∑=a,b, R= S → AA, A → AAA,A → a, A → bA, A → Ab.

a. Which strings of L(G) can be produced by derivations of four or fewer steps?b. Give at least four distinct derivations for the string babbab.

c. For any m,n,p >0,describe a derivation in G of the string

2. Give context free grammars that generate the following languages. Σ = a, b

a. The complement of the language anbn | n ≥ 0.

b. Set of all w#x such that wR is a substring of x for w, x Є a, b*

d. x1#x2#....#xk | k ≥ 1 for each xi Є a, b* and for some i and j xi = xjR

e. w | w starts and ends with the same symbol

f. w | the length of w is odd and its middle symbol is one a

g. w | w = wR that is w is a palindrome

3. Use pumping lemma to show that the following languages are not context free.

a. anbnanbn | n ≥ 0

b. an#a2n#a3n | n ≥ 0

c. w | w is a substring of t where w, t Є 0,1*

d. t1#t2#.......#tk | k ≥ 2, each ti Є 0,1* and ti = tj for some i ≠ j

4. Let Σ = 1,2,3,4 and C = w Є Σ * | In w the number of 1’s equal the number of 2’s and

number of 3’s equals the number of 4’s. Show that C is not context free.

5. Show that F= 0i1j | i ≠ kj for every positive integer k is not context free.

6. Let A = wtwR | w,t Є a,b* and |w| = |t| . Prove that A is not a context free language.

Theorem:39

Page 40: Automata Theory, Languages and computation · Web viewAutomata Theory, Languages and computation 7 Chapter-3 Push-Down Automata and Turing Machine 29 Chapter-4 SAT Problems 44 Chapter-5

If L is a CFL and R is a regular language, then L R is a CFL.

Proof:

To prove this theorem, we construct an automaton known as finite pushdown automata

(FPDA) which is a combination of a Finite automaton and a Pushdown automaton. The

combination will looks like this:

Let P = (QP, Σ, Γ, δP, Z0, FP) be a PDA that accepts L by a final State and

Let A = (QA, Σ, δA, qA, FA) be a DFA that accepts R.

Construct PDA P` = (QP × QA, Σ, Γ, δ (qP, qA), Z0, FP × FA) where δ ((q, p), a, X) is defined to

be the set of all pairs ((r, s), γ) such that:

s = δA(p, a) and

Pair (r, γ) is in δP (q, a, X).

That is, for each move of PDA P, we can make the same move in PDA P`, and in addition, we

carry along the DFA A in a second component of the state of P`. Note that ‘a’ may be a symbol

of Σ, or a = ε. In the former case, δ (p, a) = δA (p), while if a = ε, then δ (p, a) = p; i.e., A does

not change state while P makes moves on ε input.

It is an easy induction on the number of moves made by the PDA’s that

(qP, w, Z0) (q, w, Z0) if and only if ((qP, qA), w, Z0) ((q, p), ε, γ).

40

Page 41: Automata Theory, Languages and computation · Web viewAutomata Theory, Languages and computation 7 Chapter-3 Push-Down Automata and Turing Machine 29 Chapter-4 SAT Problems 44 Chapter-5

Where p = δ (pA, w). Since (q, p) is an accepting state of P` if and only if q is an accepting

state of P, and p is an accepting state of A, we conclude that P` accepts w if and only if both P

and A do; i.e., w is in L R.

Example:

Construct a PDA to generate the language 0n1n+1 | n ≥ 0

Consider the following PDA P = (p, q, r, 0, 1, Z, X0, δP, p, X0, r)

For equal number of 0’s and 1’s.

Now, introduce a finite automaton A = (s, t, 0, 1, δA, s, s, t) that accepts the strings in

the language of 0*1*, that is, all strings of 0’s followed by 1’s. Call this as language R.

The finite Automaton looks like:

We shall construct a PDA P` = (p, q, r × s, t, 0, 1, Z, X0, δ, (p, s), X0, r × s, t) and

the P` look like this:

41

Page 42: Automata Theory, Languages and computation · Web viewAutomata Theory, Languages and computation 7 Chapter-3 Push-Down Automata and Turing Machine 29 Chapter-4 SAT Problems 44 Chapter-5

The δ transition functions are:

δ ((p, s), ε, X0) = ((q, s), ZX0), δ ((q, s), 0, Z) = ((q, s), ZZ).

δ ((q, s), 1, Z) = ((q, t), ε) , δ ((q, s), ε, X0) = ((r, s), ε).

δ ((q, t), 1, Z) = (q, t), ε , δ ((q, t), ε, X0) = ((r, t), ε).

The language L R is the set of strings with some number of 0’s followed by one more 1, that

is 0n1n+1 | n ≥ 0. The language is a CFL, generated by the grammar with productions

S → 0S1 |1.

The PDA P accepts this language L R. After pushing Z onto the stack, it pushes more Z’s

onto the stack in response to inputs 0, staying in state dies if it sees an 0 until X0 is exposed on

the stack. At that point, it spontaneously transitions to state (r, t) and accepts.

Theorem:

The following are true about a CFL’s L, L1 and L2 and a regular language R.

1. L – R is a Context Free language.

2. Ĺ is not necessarily a context free language.

3. L1 – L2 is not necessarily a context free language.

1.Consider the CFG G=(V,∑,R,S),where V=a,b,S,A,B, ∑=a,b,R=S → aB, S →bA, A →a, A →aS, A →BAA, B → b, B →bS, B →ABB a. Show that ababba є L(G) b. Prove that L(G) is the set of all non empty strings in a,b that have equal number of occurrences of a and b

2. Let G=(V,∑,R,S), where V=a,b,S,∑=a,b and R= S → aSb, S → aSa, S → bSa, S → bSb, S →e. Show that L(G) is regular

TURING MACHINEIn the development of the theory of computation, we have several models of computing

devices. Finite Automata are the good models, works with small amount of memory.

Pushdown Automata are good models for devices that have an unlimited memory works with

last in first out manner of stack. There are some simple tasks beyond the capabilities of these

models. Hence the need of Turing machine.

A much more powerful model first proposed by Alan Turing in 1936, is

called the Turing machine. Turing machine is a device that can recognize L = anbncn / n ≥ 0

and many more similar languages, which can not be recognized by a simple FA & PDA.

42

Page 43: Automata Theory, Languages and computation · Web viewAutomata Theory, Languages and computation 7 Chapter-3 Push-Down Automata and Turing Machine 29 Chapter-4 SAT Problems 44 Chapter-5

A Turing machine consists of a finite control, a tape and a head that can be

used for reading or writing on that tape. We also study TMs with many tapes or machines with

fancier manner.

• CFG accepts anbn language

• But anbncn languages are also here and to accept those types we are going to Turing

Machine concept.

Definition:A Turing Machine is represented by a 7-tuple T = (Q, Σ, Γ, d, q0, q accept, q reject):

Q is a finite set of states

Σ is the input alphabet, where ¨ Ï Σ

Γ is the tape alphabet, a superset of Σ; ¨ Î Γ

d : Q ´ Γ → Q ´ Γ ´ L, R is the transition func.

q0 Î Q is the start state

q accept Î Q is the accept state

q reject Î Q is the reject state, and q reject q accept

1. Construct the TM for C = aibjck | k = i×j, and i, j, k ≥ 1

Example:

aaabbbbcccccccccccc

C = aibjck | k = i×j, and i, j, k ≥ 1

High-Level Idea.

For each occurrence of a:

For each occurrence of b:

Delete an occurrence of c.

C = aibjck | k = i×j, and i, j, k ≥ 1

43

Page 44: Automata Theory, Languages and computation · Web viewAutomata Theory, Languages and computation 7 Chapter-3 Push-Down Automata and Turing Machine 29 Chapter-4 SAT Problems 44 Chapter-5

a a b b b c c c c c c

x a b b b c c c c c c

x a y y y z z z c c c

x a b b b z z z c c c

x x y y y z z z z z z

CHAPTER-4

SAT Problems

Checking Satisfiabilty of a Boolean Expression

Satisfiabilty problem:

• A Boolean Expression is said to be satisfiable if it evaluates to 1 for some assignment of the variables.

• For eg. x1 ۸ ¬ x1 is unsatisfiable as it evaluates to 0 whether x1= 0 or 1 while x1 ۷ ¬ x1 is satisfiable.

Conjective Normal Form (CNF):

• A Boolean expression is said to be in Conjective Normal Form (CNF) of size k if it is of the form E1٨ E2 ٨ … ٨ Ek and each Ei, called a clause of the form αi1٧αi2 ٧ ….. ٧ αij, where each αij is a literal.

Clique:

Definition: A clique in an undirected graph G=(V, E) is a subset of vertices, each pair

44

Page 45: Automata Theory, Languages and computation · Web viewAutomata Theory, Languages and computation 7 Chapter-3 Push-Down Automata and Turing Machine 29 Chapter-4 SAT Problems 44 Chapter-5

of which is connected by an edge in E.

Definition: The clique problem is to find a clique of maximum size in a graph

Theorem. The verification algorithm takes G and a subset V’ of V vertices as the certificate. It

checks whether V’ is a clique in polynomial time by checking whether, for each pair , the edge .

Example: for Clique

Here we have a clique of size 3, hence the graph is said to be 3 – clique.

Checking Satisfiabilty:

• We can check the Satisfiabilty through constructing the truth table directly. • But if there are n variables then we have to compute for 2n times. • If n > 100 or 1000 then it is not possible to compute.• Hence we move on to the graphical method.

Graphical Method:

Step 1: Convert the Boolean expression into CNF format of length say, k.

Step 2: Construct a graph for that CNF.

Step 3: If the graph has a clique of size k then the problem is said to be satisfiable.

Step 1 ----- Boolean to CNF

Consider a Boolean Expression (x ۸ y)٧ (z ۸ x) which is a DNF form. Now we are converting them into a CNF by introducing new variables like as follows

45

Page 46: Automata Theory, Languages and computation · Web viewAutomata Theory, Languages and computation 7 Chapter-3 Push-Down Automata and Turing Machine 29 Chapter-4 SAT Problems 44 Chapter-5

Introduce a dummy variable u and u respectively for two parts. Convert AND as OR and vice versa. Hence the CNF for the given Boolean Expression is (u + x) (u + y) (¬u + ¬x) (¬u + z)

Step 2 -------- Constructing a Graph

Now the CNF is (u+x)(u+y)(¬u+¬x)(¬u+z)

Given an expression in CNF with k clauses, we construct a graph, which has a clique of size k iff the CNF expression is satisfiable. Let e = E1E2…Ek be a Boolean expression in CNF. Each Ei is of the form (xi1٧……. xiki) where xij is a literal.

Construct an undirected graph G = (V, E) whose vertices are represented by pairs of integers [i, j] where 1 ≤ i ≤ k and 1 ≤ j ≤ kj.

The number of values of G is equal to the number of literals in e. Each vertex of the graph corresponds to a literal of e.

The edges of G are these pairs [i, j], [k, l] where i ≠ k and xij ≠ xkl i.e. xij and xkl are such that if one is variable y the other is not y.

If one is y and the other is y, we cannot assign values independently to xij and xkl. To enable independent assignment of values to xij and xkl we have the condition that

xij ≠ xkl

Example:

(p1 ٧ p2 ٧ p3) ۸ (p1 ٧ p3) ۸ (p2 ٧ p3)

46

Page 47: Automata Theory, Languages and computation · Web viewAutomata Theory, Languages and computation 7 Chapter-3 Push-Down Automata and Turing Machine 29 Chapter-4 SAT Problems 44 Chapter-5

Result:

1. Pi ≠ Pi i ≤ 32. P[i, j] ≠ P[k,l] of i = k.

It has 4 clauses and the graph constructed is:

Same clauses are not connected.

u and u are not connected.

(1,1), (1, 2) are not connected....(4, 1), (4, 2) are not connected.

Step 3:

In general, it forms n vertices of n clauses which must have a clique of size n for satisfiability. Here it has a clique of size 4. Hence the given problem is satisfiable.

To check the Satisfiabilty of the given Expression through Independence Set:

47

Page 48: Automata Theory, Languages and computation · Web viewAutomata Theory, Languages and computation 7 Chapter-3 Push-Down Automata and Turing Machine 29 Chapter-4 SAT Problems 44 Chapter-5

Independence Set:

Let G be an undirected graph. A subset I of the nodes of G is an independent set if no nodes of I are connected by an edge of G. An independent set is maximal if it is as large (has as many nodes) as any independent set for the same graph.

Example:

1,4 is an Independent set since no edge between 1 and 4. 1,2,4 is not an independent set since 1 and 2 are connected. 1,4 is a maximal Independent set.

Expression E is satisfiable iff G has an independent set of size m where m is the number of clauses in E.

There are three ways to construct a graph for the given Boolean Expression• If we construct a graph then it is easy to identify the Independent set.• If the graph has an Independence set of size m then we can say that E is satisfiable.

Expression of two variables

Consider the Boolean expression (x1+x2)(x1 +x3)• Corresponding graph is above.• x2, x3 is the independent set.• Expression of two clauses has an independent set of two variables implies E is satisfiable.

Assume that G has an Independent set of size m.

• An independent set may not include two nodes from the same clause, [i, j1] and [i, j2] for some j1 ≠ j2 and both variable x and its negation ¬x.

• The independent set I of size m satisfying truth assignment T for E as follows 1. If a node corresponding to the variable x is in I then make T (x) = 1. 2. If a node corresponding to the variable ¬ x is in I then make T ( x) = 0.

48

Page 49: Automata Theory, Languages and computation · Web viewAutomata Theory, Languages and computation 7 Chapter-3 Push-Down Automata and Turing Machine 29 Chapter-4 SAT Problems 44 Chapter-5

• Each clause of E has the node corresponding to one of its literals in I and T is chosen so that literal is made true by I.

Thus, when an independent set of size m exists then E is satisfiable.Assume that E is satisfiable

• An edge connecting a variable and its negation cannot have both ends in I because we selected for I only nodes that correspond to literals made true by the truth assignment I.

• T will make one of x and ¬x true, but never both.• We conclude that of E is satisfiable then G has an independent set of size m.

Example of the graph based on the 3 – CNF expression(x1+x2+x3) (¬x1+x2+x4) (¬x2+x3+x5) (¬x3+ ¬x4+ ¬x5)

1. Same clauses are connected.2. x and x are connected.

Hence x1, x2, x3, x4 forms the independence set of size 4. Hence it is Satisfiable. The Directed Hamilton Circuit Problem is Satisfiable

• Construction of Directed Hamilton Circuit Problem based on the 3-CNF expression E=(x1+x2+x3)(¬x1+¬x2+x3).

• X1 appears once negated and once unnegated, so there are two rows of b’s and c’s.

• Thus we need cip bi,p+1 ,i>4 arcs that we can use to attach the gadgets for I1 and I2 to represent uses of xi in these clause

• Consider the gadget I2, which corresponds to the clause (¬x1+¬x2+x3).• The first literal, ¬x1, we attach b10 to r2 and we attach u2 to c11.• The second literal, ¬x2, we attach b20 to s2 and we attach v2 to c11.

49

Page 50: Automata Theory, Languages and computation · Web viewAutomata Theory, Languages and computation 7 Chapter-3 Push-Down Automata and Turing Machine 29 Chapter-4 SAT Problems 44 Chapter-5

• One of the satisfying truth assignment is x1 =1, x2=0 , x3 = 0.

• For this truth assignment, the first clause is satisfied by its first literal x1,while the second clause is satisfied by its second literal ¬x2.

• For this truth assignment, we can devise a Hamilton circuit in which the arcs a1→ b10 , a2 → c20 and a3 → c30 are present.

• The cycle covers the first clause by detouring from H1 to I1 starting with arc c10 → r1, traversing all of I1, and returning to b11.

• The second clause is covered by the detour from H2 to I2 starting with arc b20 → s2, traversing all of I2 , and returning to c21.

• The entire Hamilton cycle is shown in the above figure.Undirected Hamilton Circuits is SatisfiableWe reduce DHC to HC as follows.Suppose we are given a directed graph Gd. We construct the undirected graph Gu. For every node v of Gd, there are three nodes v0,v1,v2 in Gu.

• The edges of Gu are:1. For all nodes v of Gd , there are edges

(v (0) ,v (1)) and (v (1) ,v (2)) in Gu .2. If there is an arc v→w in Gd, then there is an edge (v (2) ,w(0)) in Gu.

50

Page 51: Automata Theory, Languages and computation · Web viewAutomata Theory, Languages and computation 7 Chapter-3 Push-Down Automata and Turing Machine 29 Chapter-4 SAT Problems 44 Chapter-5

The following figure suggests the pattern of edges, including the edge for an arc v→w

• The construction of Gu from Gd can be performed in polynomial time.• Show that Gu has a Hamilton circuit iff Gd

has a directed Hamilton circuit.(If) Suppose v1, v2,…, vn, v1 is a directed Hamilton circuit. Then surely v1

(0), v1(1), v1

(2) , v2(0),

v2(1), v2

(2), v3(0), …,vn

(0), vn(1), vn

(2), v1(0) is an undirected Hamilton circuit in Gu

That is, we go down each column, and then jump to the next column to follow an arc of Gd.

(only if) each node v(1) of Gu has only two edges, and therefore must appear in a Hamilton circuit with one of v(0) and v(2) its immediate predecessor, and the other its immediate successor.

• Thus, a Hamilton circuit in Gu must have superscripts on its nodes that vary in the pattern 0,1,2,0,1,2,… or its opposite, 2,1,0,2,1,0,….

• Since these patterns correspond to traversing a cycle in the two different directions, we assume the pattern 0,1,2,0,1,2… .

• So the edges form the cycle with direction. Thus, an undirected Hamilton circuit in Gu yields a directed Hamilton circuit in Gd .

Traveling Salesman Problem is Satisfiable• We reduce HC to Traveling Salesman Problem as follows. • Given a graph G, construct a weighted graph G’ whose nodes and edges are the same as

the edges of G, with a weight of 1 on each edge, and a limit K that is equal to the number of nodes n of G. Then a Hamilton circuit of weight n exists in G’ iff a Hamilton circuit in G.

COLORABLE PROBLEMS

2 Colorable is in P.• Clearly G is 2 colorable• The corresponding Boolean expression is (x1+x2)(x1 +x3)• Assuming that a color is true and another one is false then the expression is satisfiable

and this is in P.

3 Colorable is in NP• Clearly G is 2 colorable• The corresponding Boolean expression is (x1+x2)(x1 +x3)• Assuming that a color is true and another one is false then the expression is satisfiable

and this is in P.

51

Page 52: Automata Theory, Languages and computation · Web viewAutomata Theory, Languages and computation 7 Chapter-3 Push-Down Automata and Turing Machine 29 Chapter-4 SAT Problems 44 Chapter-5

Vertex Cover Problem

Def. A vertex cover of G=(V, E) is a subset V’ of V s.t. if , then either

Optimization problem: Find a vertex cover of minimum size.Decision problem: Determine if there exists a vertex cover of size k.

Reference Book: Introduction to Automata Theory, Languages and computation by John E. Hopcroft, Rajeev Motwani, Jeffery D. Ullman

CHAPTER-5Some Applications Watson Crick Automaton1. Introduction:

A Watson Crick automaton is an automaton which works on tapes which are double stranded sequences of symbols, in which symbols on the Corresponding cells of the two tapes are related by a complimentary relation. As it looks these tapes are similar to a DNA molecule. So these tapes in the automata are called as Watson-Crick tapes. The automata can scan two tapes correlated and it has states too. The essential difference between normal automata and these automata is that WK automata can handle double strands as its objects while normal automata operate on linear strings of terminals.

The Watson Crick tapes closely resemble the DNA. In DNA the matching cells are complimentary (Nucleotides) where the complimentary function is being as base pairs (A, G), (C, T) of the DNA alphabet. Because of this complementarily in the automata is similar to DNA molecule, the automata is called as Watson-Crick automata. In [1], Sempere shows that we can define two finite automata from the given Watson crick automaton which are known as upper and lower generally. Here the upper strand Watson crick automaton is taken and the properties are discussed.

A grammar is a construct G = (N, Σ, P, S) where N and Σ are the alphabets of auxiliary and terminal symbols with N ∩ Σ = Ø, S ε N is the axiom of the grammar and P is a finite set of productions in the form α→β. The language of the grammar is denoted by L(G) and it is the

52

Page 53: Automata Theory, Languages and computation · Web viewAutomata Theory, Languages and computation 7 Chapter-3 Push-Down Automata and Turing Machine 29 Chapter-4 SAT Problems 44 Chapter-5

set of terminal strings that can be obtained from S by applying symbol substitutions according to P. Formally, w1 =>G w2 if w1 = uαv, w2 = uβv and α→β ε P. We will denote by =>*G the reflexive and transitive closure of =>G.

We will say that a grammar G = (N,Σ,P,S) is right linear (regular) if every production in P is in the form A→uB or A→w with A,B ε N and u, w ε Σ*. The class of languages generated by right linear grammars coincides with the class of regular languages and will be denoted by REG. We will say that a grammar G = (N,Σ,P,S) is linear if every production in P is in the form A→uBv or A→w with A,B ε N and u, v, w ε Σ*. The class of languages generated by linear grammars will be denoted by LIN. We will say that a grammar G = (N,Σ,P,S) is even linear if every production in P is in the form A→uBv or A→w with A,B ε N, u, v, w ε Σ* and |u|=|v|. The class of languages generated by even linear grammars will be denoted by ELIN. A well known result from formal language theory is the inclusions REG Í ELIN Í LIN.

DNA Computing:

In DNA computing, we have only four symbols and they are .

Hence Σ has four values. The upper strand alphabet is denoted as Σu and it consists of A, T, C and G and the finite automaton are defined as Au. The family of regular languages generated by this automaton is denoted as REGu.

Watson Crick finite automata:

Here we recall the theory of WK automaton, variants of WK automaton and the language generated by them.

Formal Theory:A Watson Crick automaton is a 6-tuple M =

Where V, K are the disjoint alphabets which represent set of terminals and set of states respectively, Is a symmetric relation, K, F is contained in K, and

is a mapping such that Only for finitely many triples

(s, x, y) ε .

If the automaton passes over x1 in the upper strand and over x2 in the lower strand of a

double stranded sequence, and enters the state q then we can say that q ε This can be

written in terms of rewriting rules as: Where s, q are states and , .

53

Page 54: Automata Theory, Languages and computation · Web viewAutomata Theory, Languages and computation 7 Chapter-3 Push-Down Automata and Turing Machine 29 Chapter-4 SAT Problems 44 Chapter-5

Several variants of WK finite automaton have been introduced in and few of them which are used in this paper are

Stateless, denoted as NWK if Q= F = s0.

All Final, denoted as FWK if K = F.

Simple, denoted as SWK if we have x1 = λ or x2 = λ

for all ε p.

1- limited, denoted as 1WK, if all we have

Generally we say that a WK automaton as arbitrary Watson crick automaton (AWK) if no conditions is specified. Language generated by WKA:

Sempere says that every language generated by WK is linear and applying proper transformations we get even linear from that first and again we get regular from that also.Example:In fig 1. q0 is the initial and qf is the final state and its production rule is written as

q1 ----- > Aq2Tq2 ----- > Tq4Aq4 ----- > Gq3Cq3 ----- > CqfGqf ----- > ε

fig. 1

The string is generated by this grammar and the language generated is ATGC εGCAT. The language generated in general can be written as X ε X1 where X = x1x2…….xr and X1 = (XR)1

Optimizing Space Filling Curve with Graph Grammar Graph Grammar

A graph grammar is a pair of G = (S, P), where S is the starting graph and P is a set of production rules. Graph replacement grammars have productions of the form (M, D, C), where M is the mother graph, D is the daughter graph, and C is a set of connection instructions. All occurrences of sub graph M in a host graph H are replaced with D using the set of connections C. L (G) is the set of graphs generated by graph grammar G. Defining a new

54

Page 55: Automata Theory, Languages and computation · Web viewAutomata Theory, Languages and computation 7 Chapter-3 Push-Down Automata and Turing Machine 29 Chapter-4 SAT Problems 44 Chapter-5

class of graph grammars requires specification of rewriting rules (M and D), and an embedding mechanism is the criterion to classify graph grammars. We can distinguish two classes of grammars based on the nature of productions:Node replacement graph grammars and Edge replacement graph grammars. Node Replacement Graph GrammarDefinition An edNCE (Edge Labeled Directed Neighborhood Controlled Embedding) graph grammar is a system G = (∑, ∆, Γ, Ω, P, S),Where ∑ - is the set of nonterminal node alphabet,∆ - is the set of terminal node alphabet, ∆ ∑,Γ - is the set of edge alphabet, Ω - is the final edge alphabet, Ω Γ,P - is the finite set of productions of the form (d, Y,C) with d Є ∑ and Y is a graph,C - is the connection relation, C ∑ × Γ × Γ ×VY× in, out,S- is the starting graph.

Model Let us consider an edNCE graph grammar system for Hilbert curve γ = (G1,G2, G3),Where G =( ∑ , ∆ , Γ, Ω, P, S ), with ∑ =S,X,a,b,c, , ∆ =a,b,c, Γ =x,y,z, Ω =x,y,z,and P contains the productions as shown in fig1.and the connection relation C is a,x /x,a,in, a,y /y,b,out, b,y /y,a,in,a,x /z,a,in,a,x /z,a,out.

P2 X is rotated at 270 degree to give x2

P3 X is rotated at 90 degree to give x3

Resulting graph after derivation

55