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

Chapter 1&2

The document discusses different types of grammars and languages in the Chomsky hierarchy, including regular, context-free, context-sensitive, and unrestricted grammars. It also covers regular expressions and finite state automata, including deterministic and non-deterministic models. Examples are provided of converting between non-deterministic finite automata and deterministic finite automata.

Uploaded by

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

Chapter 1&2

The document discusses different types of grammars and languages in the Chomsky hierarchy, including regular, context-free, context-sensitive, and unrestricted grammars. It also covers regular expressions and finite state automata, including deterministic and non-deterministic models. Examples are provided of converting between non-deterministic finite automata and deterministic finite automata.

Uploaded by

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

Chomsky Hierarchy/Types of Grammar------5marks

Types Language Machine/Automata

Types-3 Regular grammar/RL FA-Finite automata-DFA


& NFA
Type-2 Context free grammar- Pushdown
CFG-CFL automata(PDA)
Type-1 Context sensitive Linear bound automata
grammar-CSG-CSL
Type-0 Universal grammar Turing machine-TM

Chapter: 2: Regular Expression and Finite automata

 Language: Language is defined as set of strings which are generated from sequence of symbols.
 Regular Language:---language which are accepted/identified by finite automata…
or
To define language if we are using three set of operations:
1) Union(+,/): (0+1) (0/1)==at a time we can take either 0 or 1
2) Concatenation(.): 0.1====== 01=====both the symbol at a time
3) kleenes star(*): 0*========^ or more occurenece={^,0,00,000,0000,….}
1*={^,1,11,111,1111,11111,……}
a*={^,a,aa,aaa,….} b*={^,b,bb,bbb,bbbb,…}-SET---collection of elements
 Regular Expression: It is used to express or define the regular language.
 Alphabet / input symbol: It is used as finite sequence of non empty symbols.

Examples of Regular Expression:


1) Binary string that generate many occurrence of 0‘s & 1’s.-- (0+1)*
2) binary string that ends with 0.- (0+1)* 0
3) binary string that start with 0.- 0(0+1)*
4) binary string that contain 0 as a substring.- (0+1)* 0 (0+1)*
5) binary string that starts with 101.- 101(0+1)*
6) binary string ends with 1101.- (0+1)*1101
7) language that contain input as {a,b} that generates string which ends with aab.-(a+b)*aab
8) ) language that contain input as {a,b} that generates string which conatains abab.- (a+b)* abab(a+b)*
9) a string of binary that contains odd number of 1’s.- 010 , 0111 , 1110101,1

(0* 1 0* 1)* 0* 1 0* ====0* (1 0* 1 0* )*1 0* ====== 0* 1 0* (1 0* 1 0* )*

10) a string of binary that contains odd number of 0’s.-0,0100,000,101010,

1 *0 1*(1* 01* 0)*

11) binary string that have even length of string.- (0+1)*-- 11 , 01010,11101

(00+11+10+01)*
12) binary string contain exactly two 0’s.- 00 , 1010 , 11001, 10101 ,111001111111

1*0 1*0 1*

input symbol{a,b,c} that ends with abc: set:{abc, abccabc, ……..abc}

(a+b+c)*abc -- a*b*c* {abc,aabbcc,aaaabbbccc,}


input symbol {a,b,c} that contains abcb as a substring: (a+b+c)* abcb(a+b+c)*

Langugae of C contains identifier:

character=letter=l Digit=d _

(L + _)(L+d+_)*

A string ending with 1 but not containing 00

00

11 1+ ={1,11,111,1111,…} / 1*={^,1,11,111,1111,…}

10 1+= 1.1*

01 (1+01)+ = (1+01)(1+01)*

String containging either ab or bba.

(a+b)* (ab+bba) (a+b)*

binary string 01 (0+1)* 01 (0+1)*

Binary string that begin or end with either 00 or 11

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

Finite automata
1) Deterministic Finite Automata(DFA)
2) Non- Deterministic Finite Automata(NFA)

1) Deterministic Finite Automata(DFA)


one state to another state if we have only one path /transition then it Is known as deterministic.

DFA= it is a 5 tupple machine

M=(Q, q0, A , ∑ , δ)

input string ends with abab:

binary string contains 0 as a substring

binary string that contain 0110

input {a,b} that contain bba

binary string that starts with 0.  {0,1} {0,01,00,0110,..}RE0(0+1)*

starts with 110.

input symbol {a,b} that starts with abba--- dead state x

Binary string that contain exactly 2 0’s.--> 1*0 1* 0 1*

string contain either ab or bba :

(11+10)*- minimum string : {11,10,^}--- note: intial state is also becomes accepted.
(00)*(11)* - {00,11,^, 000011,0011,1111}

(0+1)*(01+110) {01,110}

(1+110)*0{0, 10,1100}

Extended Transition fuction: ▲*

Transition fuction for DFA Q * E –> Q

1) for q belongs to Q , ▲*(q,^)=q

2) y belongs to E* and a belongs to E

▲*(q,ya)= ▲(▲(q,y),a)

traverse  001

▲*(A,001)= ▲(▲(A,00),1)

▲(A,00)=▲(▲(A,0),0)

= ▲(A, 0)= A

▲*(A,001)= ▲(▲(A,00),1)

= ▲(A,1)=B

string1011

Lang: binary string that ends with 101-01101


δ*(A,01101)=δ(δ(A,0110),1)
δ(A,0110)=δ(δ(A,011),0)
δ(A,011)=δ(δ(A,01),1)
δ(A,01)=δ(δ(A,0),1) =δ(A,1)=B
δ(A,011)= δ(δ(A,01),1)=δ(B,1)=B
δ(A,0110)=δ(δ(A,011),0)=δ(B,0)=C
δ*(A,01101)=δ(δ(A,0110),1)=δ(C,1) =D

Union, Intersection and Difference

1) L1: binary string does not contain 00 as a substring.


L2: binary string that ends with 01
find L1 U L2 , L1_ L2, L1-L2

Ex: L1: binary string ends with 01.


L2: Binary string contains odd number of 1’s.
Find L1UL2, L1∩L2 & L1-L2.
NFA-Non deterministic Finite automata
five tupple

Subset Construction Method: (Conversion from NFA to DFA)

initial state of NFA becomes initial state of DFA-state

state contains either 3 or 5 that all becomes accepting state in DFA

For-{1}……A For-{3}-H
δ(A,a)={2}…….B δ(H,a)=φ….C
δ(A,b)=φ…….C—Dead state δ(H,b)={3}…..H
For-{2}-B
δ(B,a)={3,4}…..D
δ(B,b)={5}……E
For-{3,4}-D
δ(D,a)=δ(3,a)Uδ(4,a)={4}…..F
δ(D,b)={3,5}……G
For-{5}-E
δ(E,a)=φ…..C
δ(E,b)=φ……C
For-{4}-F
δ(F,a)={4}……F
δ(F,b)={5}……E
For-{3,5}-G
δ(G,a)=φ…..C
δ(G,b)={3}……H
For-{1}…..A For-{3,4}-D
δ(A,a)= {2,3}….B δ(D,a)={4}…..C
δ(A,b)={4}……C δ(D,b)={3}…….F
For-{2,3}=B For-{3}-F
δ(B,a)={4}…..C δ(F,a)={4}….C
δ(B,b)={3,4}…..D δ(F,b)={3}…..F
For-{4}-C
δ(C,a)=φ…….E
δ(C,b)=φ…..E
Q a b - defines initial state , + ,*,circle defines accepting state transition table
-A B C
B C D
+C* E E
+D* C F
E E E
F C F
Convert the following NFA into DFA using subset construction method.

Q a b
1 2 5
2 φ 3
3 4 3
4 3,5 φ
5* φ 1
For-{1}…..A For-{3,5}-G
δ(A,a)={2}…..B δ(G,a)={4}……F
δ(A,b)={5}….C δ(G,b)={1,3}={3,1}……H
For-{2}-B For-{1,3}-H
δ(B,a)=φ…..D δ(H,a)={2,4}…….I
δ(B,b)={3}….E δ(H,b)={3,5}………G
For-{5}-C For-{2,4}-I
δ(C,a)=φ…….D δ(I,a)={3,5}……..G
δ(C,b)={1}……..A δ(I,b)={3}……..E
For-{3}-E
δ(E,a)={4}……F
δ(E,b)={3}……E
For-{4}-F
δ(F,a)={3,5}….G
δ(F,b)=φ…..D
Q a b
1 2 5
2 φ 3
3 4 3
4 3,5 φ
5* φ 1

Shortcut method for converting NFA to DFA


a b
{1}-A {2} {5}
{2}-B φ {3}
{5}-C φ 1
{3}-D 4 3
{4}-E {3,5} φ
{3,5}-F 4 {1,3}
{1,3}-G {2,4} {3,5}
{2,4}-H {3,5} {3}
φ-I

Difference between NFA and DFA


NFA DFA
Non deterministic---for each input symbol there are Deterministic- for each symbol there is only one transition
multiple transition
δ: Q* ∑2Q δ: Q*∑Q
DFA NFA NFA- ^
∑-{0,1} ∑-{0,1} ∑-{0,1,^}

M=(Q,q0,A,∑,δ) M=(Q,q0,A,∑,δ) M=(Q,q0,A,∑,δ)


δ: Q*∑Q δ: Q*∑2Q δ: (Q*∑U{^})2Q

It is more restrictive less restrictive less restrictive=NFA with null transition

each input symbol contain one each input symbol multiple transiton each input symbol multiple transiton &
transition also contain null transion

Examples:

1) Union : a+b

Convert NFA-^ to DFA: NFA-^ to NFA - Subset construction method to convert NFA- DFA
Convert The following NFA-^ into DFA:
Transition table:

Q 0 1 ^
A A φ B
B C φ D
C φ B φ
+D* D φ φ
that already given. Accepting state in NFA === Accepting state NFA-^

total no of states in NFA ===== total no of states in NFA-^

Q ^(Q) 0 ^(0) 1 ^(1)


A {A,B,D} δ(A,0)Uδ(B,0)Uδ(D,0 {A,B,D,C} δ(A,1)Uδ(B,1)Uδ(D,1 φ
) )
{A,C,D} {φ}
B {B,D} {C,D} {C,D} φ φ
C {C} φ φ {B} {B,D}
D* {D} {D} {D} φ φ
NFA:

(0) (1)
A {A,B,D,C φ
}
B {C,D} φ
C φ {B,D}
D* {D} φ
intial state of NFA becomes initial state in DFA

Q 0 1
A=q0 {A,B,C,D}=q1 φ=q5
{A,B,C,D}=q1 {A,B,C,D}=q1 {B,D}=q2
{B,D}=q2 {C,D}=q3 φ=q5
{C,D}=q3 {D}=q4 {B,D}=q2
{D}=q4 {D}=q4 φ=q5
φ=q5 q5 q5
NFA-^ to NFA : total no states are same
NFA---- accepting state? ----4
Q ^(Q) a ^(a) b ^(b)
1 {1,4} φ φ {2,3,5} {2,3,5}
2 {2} {3} {3} φ φ
3 {3} φ φ φ φ
4 {4} φ φ {5} {5}
5 {5} {4} {4} φ φ
NFA:
Q ^(a) ^(b)
1 φ {2,3,5}
2 {3} φ
3 φ φ
4* φ {5}
5 {4} φ

NFA to DFA Conversion: Subset construction method


Q a b
{1}=A φ=F {2,3,5}=B
{2,3,5}=B {3,4}=C φ=F
{3,4}=C φ=F {5}=D
{5}=D {4}=E φ=F
{4}=E φ=F {5}=D
φ=F
Q ^(Q) a ^(a) b ^(b)
1 {1,2,5,6} {1,3} {1,2,5,6,3} {5,7} {5,6,7}
2* {2} {3} {3} φ φ
3 {3} φ φ {4} {4}
4 {4} φ φ {2} {2}
5 {5,6} φ φ {5,7} {5,6,7}
6* {6} φ φ {7} {7}
7 {7} {6} {6} φ φ
NFA:
Q ^(a) ^(b)
1 {1,2,5,6,3} {5,6,7}
2* {3} φ
3 φ {4}
4 φ {2}
5 φ {5,6,7}
6* φ {7}
7 {6} φ
NFA to DFA Conversion:
Q a b
1 {1,2,5,6,3} {5,6,7}
{1,2,5,6,3} {1,2,5,6,3} {4,5,6,7}
{5,6,7} {6} {5,6,7}
{4,5,6,7} {6} {2,5,6,7}
{6} φ {7}
{2,5,6,7} {3,6} {5,6,7}
{7} {6} φ
{3,6} {φ} {4,7}
{4,7} {6} {2}
{2} {3} φ
3 φ 4
4 φ 2
φ φ φ
MINIMIZATION of DFA/ Optimization of DFA
two groups: 1) Accepting states 2) Non accepting states

Q 0 1 0th partition / equivalence 0 : {Accepting}{NA}: {q1,q2,q4} {q0,q3,q5}


q0 q3 q1 1st partition:
q1* q2 q5
q2* q2 q5 Q 01 Q 0 Q 1
q3 q0 q4 q1 q2 q5 q0 q3 q0 q1
q4* q2 q5 q2 q2 q5 q3 q0 q3 q4
q5 q5 q5
q4 q2 q5 all in same group q5 q5 same group q5 q5
{q0,q3} {q5} {q1,q2,q4}
2nd partition:
Q 0 1 Q 0 Q 1
q1 q2 q5 q0 q3 q0 q1
q2 q2 q5 q3 q0 q3 q4
q4 q2 q5 all in same group
Furthur partition is not possible
final partition : {q0,q3} {q5} {q1,q2,q4}
Transition table:

Q a b
1 2 3
2 3 5
3 4 3
4 3 5
5* 2 5

0th partition: {1,2,3,4} {5}


1st partition:
Q a Q b
1 2 1 3
2 3 2 5
3 4 3 3
4 3 4 5 partition: {1,3} {2,4} {5}
nd
2 partition:
Q a Q b
1 2 1 3
3 4 3 3
---------
Q a Q b
2 3 2 5
4 3 4 5
Furthur partition is not possible: final: {1,3} {2,4} {5}
Q 0 1
q0 q1 q3
q1 q0 q3
q2 q1 q4
q3* q5 q5
q4 q3 q3
q5* q5 q5

0 th : {q0,q1,q2,q4}{q3,q5}
Q 0
q0 q1
q1 q0
q2 q1
q4 q3
{q0,q1,q2}{q4} 1st partition is complete when all group a’s & b’s transition are completed.
Q 1
q0 q3
q1 q3
q2 q4
{q0,q1}{q2}{q4}{q3,q5}
2nd partition:
Q 0
q0 q1
q1 q0

Q 1
q0 q3
q1 q3
Furthur partition is not possible: Final: {q0,q1}{q2}{q4}{q3,q5}
Convert the following DFA into minimized DFA
Q 0 1 0th partition: {q2,q5,q8} {q0,q1,q3,q4,q6,q7}

q0 q1 q4
q1 q2 q5
q2* q3 q7
q3 q4 q7
q4 q5 q8
q5* q6 q1
q6 q7 q1

q7 q8 q2

q8* q0 q4

q2,q5,q8} {q0,q1,q3,q4,q6,q7}
1st partition:
Q 0 1
q2* q3 q7
q5* q6 q1
q8* q0 q4

Q 0 1
q0 q1 q4
q1 q2 q5
q3 q4 q7
q4 q5 q8
q6 q7 q1

q7 q8 q2
{q0,q3,q6}{q1,q4,q7}{q2,q5,q8}
2nd partition:
Furthur partition is not possible: {q0,q3,q6}{q1,q4,q7}{q2,q5,q8}
Chapter:1:

SET: {….} collection of elements


{2,1,3,4,5}
Union: A={1,2,3} B={4,5,6}
={1,2,3,4,5,6}
Intersection : A={1,2,3} B ={3,2,5}
={2,3}
A-B={1}
A’, U={1,2,3,4,5}
A’={4,5}
Fuction F(x)=X2

F(x)= 2x+3
RR+
one to one??? yes
given fuction onto

Set A Set B
1 5
-1 1
2 7

Condition Onto one to one


RR No No
R+R No Yes
RR+ Yes No
R+R+ Yes Yes

Relation:
A={1,2,3}
={(1,1),(1,2),(1,3)..}
Equivalence:
1) Reflexive: R aRa: {(1,1),(2,2),(3,3)}
2) Symmetric: if aRb then bRa : (1,2) ---- > (2,1)
3) Transitive:if aRb, bRc then aRc: (1,2) & (2,3) -(1,3)
4) all the properties satisfied then R becomes equi.
A*B={(1,3),(1,2),(2,2),(2,3)}
1)={(1,1),(3,3)}
2) ={(3,1),(2,1),(3,2)}
3)={ (1,3),(1,2),(2,2),(2,3), (1,1),(3,3), (3,1),(2,1),(3,2)}
(1,2) & (2,3) = (1,3)
(2,3) & (3,1)=(2,1)
(3,1) & (1,2)=(3,2)

R={(1,2),(1,1),(2,1)(2,2),(3,2),(3,3)}
1: reflexive
2: (2,3)
={(1,2),(1,1),(2,1)(2,2),(3,2),(3,3),(2,3)}
3: (1,2)(2,3)(1,3)
(3,2)(2,1)(3,1)
Logic:
AND OR NOT

Check the following relation is equivalence or not and make it equivalent


{(1,2),(2,3),(3,4),(5,4)}

PROOF----5 marks / 7marks


statement is to be true:
1) Direct proof
2) Contradiction: P is true----- p is false------wrong
3 is odd number: suppose 3 is even…..assumption wrong---
3) mathematical induction---equations
1) For any positive integers which are odd then prove that multiplication of this numbers is odd.
3 * 5 = 15 odd
positive integer: 2x+1
second positive integer number : 2y+1
a*b = (2x+1)*(2y+1)
= 4xy+2x+ 2y+1
=2(2xy+x+y) +1
assume 2xy+x+y =z
= 2z + 1 which is also odd

By contradiction :
Assumption: multiplication of this number is even:
2z even number = (2x+1)(2y+1)
2z=4xy+2x+2y+1
2z=2(2xy+x+y) + 1
cancel out 2 from both sides
z= 2xy + x + y +(1/2)
assumption becomes wrong, so by contradiction we can prove that….

Contradiction :
1) Output contradict first that becomes our assumption
2) proving state true: assumption becomes false or input changed
1) Prove that for any set A,B,C if A∩B=φ and C ⊆ B then A∩C=φ.
Assumption: suppose A∩C = x

A∩B=φ xis subset of A x belongs to A


x also belongs to C x is subset of C
C⊆B
x also belongs to B
input becomes flase:
A∩B=x
so our assumption becomes false
by contradict given statement true.
3) prove that √2 is irrational number
Assumption: √2 is rational number
4) For any positive integers I,j,& n , if i*j=n then either i<= √n or j<=√n.
suppose, I >√n AND j > √n
I >√n
multiplying with j at both the sides
I * j > √n * j …………..(1)
----------
j > √n 6>5 5>3  6>5>3  6>3
multiplying both the sides √n
j * √n > n……………….(2)
Combine (1) & (2)
I * j > j *√n > n
we can also write this as ,
I*j >n
so by contradiction we can prove that For any positive integers I,j,& n , if i*j=n then either i<=
√n or j<=√n.

3) mathematical induction
it has 3 steps:
1) basic step: show that the statement is true for some integer
2) hypothesis step: assume the statement is true for some integer variable k
3) Induction step: statement is true for K+1
1) Prove that p( n)=1+2+…+n= n(n+1)/2
basic step:
n=0
p(n)=1+2+…+n
p(0)=0=LHS
n(n+1)/2 =0=RHS
basic step is true
Hyothesis step:
p(n)=1+2+…+n=n(n+1)/2
let n=k
p(k)=1+2+…+k=k(k+1)/2 this is also true.
Induction step:
LHS:1+2+….+(K+1)
RHS=(k+1)(k+2)/2
LHS= 1+2+….+(K+1)
= 1+2+….+k+ (k+1)
= k(K+1)/2 + (k+1)
Prove that for integer n>=0 p(n)=12+22+…+n2= n(n+1)(2n+1)/6
basic step: n=0
p(0)=lhs=rhs=0
basic step is true
-------
Hyposthesis step:
let n=k
p(k)= 12+22+…+k2= k(k+1)(2k+1)/6 is also true.
Induction step:
lhs: 12+22+…+(k+1)2
rhs= (K+1)(k+2)(2K+3)/6
lhs= 12+22+…+(k+1)2
=12+22+…+k2+(k+1)2
Prove that for n>=0 6n-1 is divisible by 5.
n=0
60-1=1-1=0 which is divisible by 5.
-----
hypothe: 6k-1 is also divisible by 5====5x
induction step:
n=k+1
6k+1 -1
6k . 6 -1
6k .(5+1) -1
6k .5 + 6k - 1
6k .5+ 5x
5 (6k+1) which is already divisible by 5.
so the …..
Prove that 5n-2n is divisible by 3
n=0 basic step is true
n=k : 5k – 2k ===3x is also true
n=k+1
5k+1 – 2 k+1
5k.5 – 2k 2
5k.(3+2) – 2k 2
5 k 3 + 5 k 2 - 2k 2
5k 3 + 2(5k - 2k )
5k 3 + 2(3x )
3(5k+ 2x) is also divisible by 3.
Prove that for all integer n>=1 P(n)=1+4+7+…+(3n-2)=n(3n-1) / 2

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