File No.- ....-.--
REWA ENGINEERING COLLEGE
REWA (MP.)
Practical / Sessional - Record File
NAME _ SEHTANYA SINGH
SUBJECT THEORY OF COMPUTATION
PAPER ____ PRACTICAL FILE
BE... THIRD... Year
FIFTH, Semester
CIVIL / ELECT. / MECH. / ELECTRONICS
GOYA I Books & STATIONERS
Goyal Market, Amahiya Road, REWA (MP)Pr
REWA ENGINEERING COLLEGE, REWA _
— EWA ENGINEERING CUA EWA
THEORY OF COMPUTATION PRACTICAL FILE
(SUBJECT CODE: C5-501)
SUBMITTED FOR PARTIAL FULFILLMENT OF THE REQUIREMENT FOR THE AWARD OF THE
DEGREE OF
BACHELOR OF ENGINEERING
IN
COMPUTER SCIENCE ENGINEERING
DEPARTMENT OF COMPUTER SCIENCE ENGINEERING
REWA ENGINEERING COLLEGE, REWA, (M. P.)
SESSION JUNE- DEC (2021-22)
Submitted by:
Submitted to:
SEHIANYA SINGH ICHCHHA SHRIVASTAVA
Ernollment No. - 0301¢5191053 Assistant Professor
i V Semester CSE
Computer Science DepartmentINDEX (d
: "GRADE |
e _ TE SIGNATURE. GI
s. EXPERIMENT NAME | = |
No. . t ]
on. | Design inte State Machine Sh that accepts all e .
Strings over input symbols (0, 1} having three erfio)21 |
Consecutive 1's asa substring |
©2. ‘Design a Finite State Machine (FSM) that accepts all ‘
| Strings over input symbols {0, 1} which are divisible 0341 0 | 21 | |
by 3.
03. Design a Finite State Machine (FSM) that accepts all : 2
decimal string which are divisible by 3 14) 10 Ja) A) a
04. Design a Push Down Automata (PDA) that accepts all | |
string having equal number of 0's and 1's ‘over input 4] lo |2) | |
Symbol {0, 1} for a language Onin where n >= 1 | i
05. Design ar Program to create PDA machi S
accept the well-formed parenthesis, , ~
06. Design a PDA to: accept WCWR where wisany
binary string and WR is reverse of that string and Cis 2 | 10} 2) \ {
2 special symbol, |
[07.1 ign a Turing Machine that calculate 2s |
complement of given binary string 26| to}a) \y
08. "Design a Turing Machine that increment given) A [a
binary number by one. 28] 1o].2
09. "Design a Turing Machine thats accept the following ~ ls eee
language ab"c" where n>0, | “fay
PY
10.
Design a Turing Machine to accept Wt where wig t ay.
any binary string and WR is reverse of that string AN
afer fay NeCOMPUTER SCIENCE ENGINNERING DEPT.
THEORY OF COMPUTATION Practical File (CS-S01)LAB,V-SEM (2021-22),
Student Name -SEHJANYA SINGH Roll no, 03018191053 Date:07/10721
Practical-1
OBIECTIVE:- Desi
'gn a finite state machine that accepts all strin,
having three con:
18 over input symbol 0,1
secutive 1's as substring.
THEORY:- As per the AIM, set of valid strings are represented by set A:
A= (111, 0111, 1110, 010101111010
‘Means any string should be declared valid
machine for above AIM, hence it can be d
Q set of states: {A, 8, C, 0}
&: set of input symbols. {0, 1}
0: initial state (a)
F: set of Final states: {D}
ifit contains 111 as a substring. Let M be the
lefine as M(Q, 3, 5, gO, F) where
4: Transition Function: (Transition State diagram is shown in Figure 1.)orp 8
Faget Te Tronsktfoo Diggrons
Transition Diagram
Figure 1: FSM - accepting three consecutive 1's as a substring
Code in C++
#include
#include
Hinclude
void main()
{
char Input[(100);
clrser();
cout<<"Enter a string to validate (input string should be of 0 and 1)\n";
gets(Input);
int i=-1;goto B;
}
else if(Input[i]=="\o')
{
goto Invalid;
}
else
{
goto Wrong;
}
B.
ie
goto A;
else if(Input[i]=:
{
goto C;
}
else if(Input[i]=="\0')
{
goto Invalid;
goto Wrong;y
else if(Inputli
i
goto D;
}
else if(Inputli]=="\o")
{
goto Invalid;
goto Wrong:
if(inputt
{
}
else if(Inputfi}
{
goto D;
y
else if(Input{iJ=="\o")
qels
Valid:
Invalid:
Wrong.
exit
get
OUTPUT:
For valid string:
IE
ater)
Output: Valid String
process returned @ (@x0) execution time : 12.081 s
Press any key to continue.
Roto Valid
goto Wrong.
coute<"\n Output: Valid String”;
goto exit;
cout<<"\n Output: Invalid String";
goto exit;
cout<<"\n Please enter binary string {format of 0, 1)";
chi);
umentsitec setyaryacexe
validate (input string should be of @ and 1)ig:
#3 “CAUser\DemDocuments
ELSIE Es rr
ry
Crest
moon
ae
RO cee
Cy
aR rere
rian
acca [Link]
Sar
CTL nso eae TaeCOMPUTER SCIENCE ENGINNERING DEPT.
THEORY OF COMPUTATION Practical File (CS-S01)LAB,V-SEM (2021-22)
Student Name -SEHJANYA SINGH Roll no -0301C8191083 Dateor/10n021
Practical-2
Objective ~Design a Finite State Machine (FSM) tat acceps all strings over input symbols
{0.1} which are divisible by 3,
Discussion-
As per the AIM, set of valid strings are represented by set A:
A= {0. 00, 000. 11, 011, 110, wn}
means any binary string that when divide by three gives remainder zero. Let M be the
machine for above AIM, hence it can be define as M(Q, ©, 6, 40, F) where
Q: set of states: {q. 40, ql, q2}
E: set of input symbols: {0, 1}
0: initial state (q)
F: set of Final states: {q0}
6: Transition Function
State Input
e 0 1
q qo ql
qo qo ql
ql q qo
a ql a
Fig-Transition state diagramws! 4
vanstion one
Code in C++.
#include
#include
include
void main()
{
char Input[100};
clrser();
cout<<"Enter a string to validate (input string should be of 0 and 1)\n";
gets(Input);
int i=-1;fn
}
else if(inputlij=='1')
{
Boto qi;
x
else if(Input(i]=="\o')
{
goto Invalid;
}
else
{
goto Wrong;
}
qo:
itt;
if(input{i]=='0')
{
goto qd:
}
else if(Input[i]=='1')
{
goto qi;
}
else if(Input[i]=="\0')
{
goto Valid;eee |
goto Wrong;
qi
in;
if(Input[i]=="0')
{
goto q2;
i
else if(input[i]=='1')
{
goto q0;
}
else if(Input[i]=="\0')
{
goto Invalid;
}
else
{
goto Wrong;
}
a2:
i
if(Input[i]=="0')
{
goto qi;
}
else if{input[i]=='1')
{
goto q2;}
else if(input(i}=="\o")
{
Roto Invalid;
goto Wrong:
Valid:
Cout<<"\n Output: Valid String";
goto exit;
Invalid:
Cout<<"\n Output: Invalid String";
goto exit;
Wrong:
cout<<"\n Please enter binary string {format of 0, 1)";
exit:
getch();
Output-
For valid string
tical\[Link]
eli\Docur
RE RCRD OM CT SPST a TY rer ee 1)
10
RSIS ty
rocess returned @ (@x0) execution time : 8.575 5
Moe acu catr steFor invalid string:
‘C:\Users\Del\Documents\toc practical\[Link]
erence
Piers eres rerrew er ee ec
io
Ces SECs tr yarn ne:
ee CO ceca
ee ame eos oeCOMPUTER SCIENCE ENGINNERING DEPT
021-22)
THPORY OF COMPUTATION Practiet File (8-S01)1 ABLY-SEM (2021
Student Name SEHIANYA SINGH Roll no -ON01CS191083 Date:14/10/2021
Practical-3
AIM: Design a FSM that accepts all decimal strings which are divisible by 3.
Discussion:
As per the AIM, set of valid strings are represented by set A:
A={0, 3, 6, 9, 03, 06, 09, 12, 012, ..)
means any decimal number string that when divided by three gives remainder zero. Let M
be the machine for above AIM, hence it can be define as M(Q, £, 5, 0, F) where
Q: set of states: {q, 90, q1, a2}
E: set of input symbols: {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}
0: initial state (q)
F: set of Final states: {q0}
6: Transition Function: (Transition state diagram is shown in Figure 1.)
State va
: 93,69 44,7 oe013,69
——Transtiion Diy
Transition Diagram
Figure 1: FSM - accepting decimal string if divisible by 3.
Code in C++
#include
#include
#include
void main()
{
char Input(100];
clrscr();
cout<<"Enter a string to validate (input. String should be decimal number (i.e
constructed from 0,1,2,3,4,5,6,7,8,9 digits)\n";
gets(Input);
int i=-1;qo:
goto 40,
)
else if(input{i)==1' || inputti}=="4' || Inputl}=="7)
{
goto qi
}
else if(inputli}=='2'| | Input{i]=="5"1 | Inputtil=="8')
{
goto q2;
{
goto Invalid;
}
else
{
goto Wrong;
}
iH;
if(input{i]=='0" | | Input{i]=='3'| | Input[i]=='6'| | Input[i]=='9')
{
goto a0;
}
else if(Input(i
{
1'| | Input[i]=='4'| | Input[i]=="
goto qi;
}
else if(Input[i]==
|| Input[i]=='5'| | Input[i]=='8")re
Roto q2
else if(inputli}=="\o')
{
Roto Valid;
}
else
{
goto Wrong;
}
ist;
if{input[ij=='0'|| inputlil=='3'|| Inputli}=="6'|| Input
{
goto qi;
}
else if(Input(
{
"|| Inputfi]=="4' | | Input{i]=="7')
goto q2;
}
else if{inputli]=='2'| | Inputli]=='5'| | Inputti}:
{
goto q0;
}
else if(Inputli]=="\0')
(
goto Invalid;q2:
Valid:
Boto Wrong;
*3'| | Input(i]=='6'| | Input{i]=="9')
goto q2;
}
else if(Input{i}=='1'| | Input{i]=="4"| | Inputli]=="7')
{
goto q0;
}
else if(input{i]=='2' || Input(i]=='5'| | Input[i]=='8')
{
goto qi;
}
else if(Input[i]=="\0')
i!
goto Invalid;
}
else
{
goto Wrong;
cout<<"\n Output: Valid String";
goto exit;SS
Invalid
Cout<<"\n Output: Invalid String";
Roto exit;
Wrong
cout<<"\n Please enter valid decimal number string";
exit
getch();
OUTPUT
FOR VALID STRING:
CemidenDocumentto praciea\ shane
sladate (input string should be decinal musber (sue constructed fron O,1, 6,7,8,9 aga)
Output: Valid String
Sasa ne ee
Sierras
FOR INVALID STRING:
string to valicate (input string should be decimal number (i.e constructed from 0,1,2,3,6,5,6,7,8,9 digits)
ee
ee CO ne ee eed
Press any key to continue.a
COMPUTER SCIENCE ENGINNERING DE
ABY-SEM (2021-22)
TUEORY OF COMPUTATION Practical File (CS-801)E
ate:14/10/2021
‘Student Name -SEHJANYA SINGH Roll no. -O301CS191083,
Practical-4
AIM: Design a Push Down Automata (PDA) that accepts all string having equal
number of 0's-ang I's over input symbol {0,1}. .> 0"
aed b
Diccusioas er | eh
As per the AIM, set of valid strings that can be generated by given language is
represented in set A:
A= {01. 0011, 000111, ...}
means all string having n number of 0's followed by n numbers of I's where n
can be any number greater than equal tp and count of 0's must be equal to count
of I's
InputBuffer
‘Transition TableInput string can be valid or invalid, valid if it follows the language ae
n>= 1 else invalid. PDA has to determine whether the input string is according
to the language or not.
Let M be the PDA machine for above AIM, hence it can be define as M(Q, ©. I
5, q0, Z0, F) where
Q: set of states: {q0, ql, q2}
=: set of input symbols: {0, 1}
T: Set of stack symbols: {A, Z0}
q0: initial state (q0)
ZO: initial stack symbol (Z0)
F: set of Final states: { }
6: Transition Function
TRANSITION STATE
8(q0, 0, ZO) — (q0, AZO)
8(q0, 0, 0) — (q0, 00)
(0, 1, 0) — (ql, €)
6(q1, 1, 0) — (ql, €)
(ql, €, Z0) — (q2, €)
vy i AIe-
C40" Ale. (a
0,0/AnCode in C++
include
include
#include
void main()
{
char Input{100);
char stack{100]; //Implementing stack through array.
int Top = -1;
clrser();
coute<"Enter binary string to validate (input string should be of 0 and 1)\n";
gets(Input);
stack|++Top] = '2';//Taking '2'as an initial stack symbol.
int i=-1;
0:
is;
if(Input[i]=="0' && stack{Top]== 'Z')
{
stack[++Top]=
goto 40;
yi
else iffinput[i]=='0' && stack{Top}=='A’)
{
stack[++Top]='A
goto 90;
}
else if(Input[i
{
&& stack{Top]
Top~;EE ——————————
goto a1;
}
else
(
goto Invalid;
}
qu
ins;
{
Top--;
goto qi;
}
{
Top--;
goto q2;
}
else
{
goto Invalid;
}
a2
cout<<"\n Output: Valid String";
goto exit;
Invalid
cout<<"\n Output: Invalid String";
goto exit;}
Output-
FOR VALID STRING.
*CUsers\DelN\Documents\toc practical\sehyanya exe
ere
Cre em Rost
rocess returned 0 (0x0)
Rie
Peers Cueto
FOR INVALID STRING:
ee ER and 1)
Stor
Pere ese cet
execution time : 7.040 5
ee RD)
Se om RecsCOMPUTER SCIENCE ENGINNERING DEPT
THEORY OF COMPUTATION Practical File (CS-S01)LAB,V-SEM (2021-22).
‘Student Name -SEHJANYA SINGH Roll no -0301C5191083 Date:1 4/10/2021
Practical-5
AIM: Design a Program to create PDA machine that accept the well-formed
parenthesis.
Discussion:
As per the AIM, set of valid strings that can be generated by given language is
represented in set A:
A= {0,0 00, (0) (OO) 3
means all the parenthesis that are open must closed or combination of all legal
parenthesis formation. Here, opening par is '(' and closing parenthesis is ')'.
InputBuffer
‘Transition TableInput string can be valid or invalid, valid if the input string follow set A (define
above). PDA has to determine whether the input string is according to the
language or not.
Let M be the PDA machine for above AIM, hence it can be define as M(Q, EF,
6, 0, 20, F) where
Q: set of states: {q0, q1)
t: set of input symbols: {(,)}
[: Set of stack symbols: {(, 2}
0: initial state (qo)
20: initial stack symbol (z)
F: set of Final states: { } [Note: Here, set of final states is null as decision of
validity of string is based on stack whether it is empty or not. If empty means
valid else invalid.]
6: Transition Function
TRANSITION STATE
8(q0, (,Z) + (40, (2)
8(40. (0 + 0, 0
(40, ), 0 > (40, €)
(40, ¢, Z) > (ql, ©)Code in C++
#include
#include
zinclude
void main()
char Input[ 100];
char stack[100];
int Top = -1:
clrser():
cout<<"Enter parenthesis string (string character should be '(’ and ')')\n":
gets(Input):
stack[++Top] ='Z'://Taking 'Z'as an initial stack symbol.
int i=-1:
q0:
if(Input[iJ='(' && stack[Top]== 'Z’)
f
stack[++Top]= '(‘;
goto q0:
1
5
else if(Input[iJ=="( && stack[Top]== '(')
f
t
stack[++Top]= '(‘:
goto q0:
)
J
else iffUnput[iJ==") && stack[Top]-='()Lopes
Rolo qO;
else HUnputliP>\0" && stack] Top} 'Z)
{
Vop=-:
goto qh:
goto Invalid;
ql:
cout<<"\n Output: Valid String";
goto exit;
Invalid:
cout<<"\n Output: Invalid String";
goto exit:
exit:
getch():/
output:
Invalid string:
For cae DANDECUENE OC racial sehjan
vaere
eee ROE RL
i)
Pree Unt
hee CA)
OCC nths
ee ROR cute
Beer E as
For Valid string:
# “CAUsers\Del\Document
OC Dractical\[Link]’
Creem veces
process returned ® (@x0) execution time «
See erent Seat eeCOMPUTER SCIENCE ENGINNERING DEPT,
THEORY OF COMPUTATION Pract
lel File (CS-501)L AB,V-SEM (2021-22),
se SEHIANYA SINGH Rone -011esi9}083
wet
Date:21/1072021
Practical-6
Design a PDA to accept W*CWAR where w is an
oe of that string and Cis a special symbol.
revel
THEORY:
y binary string and WAR is
r the ATM, set of valid strings that can be generated by given language is
As per the Al
represented in set A:
{0CO. 1C1, 011000110C011000110, 101011C110101, ...}
A= {0C0.
s string must have some binary string followed by special character
amet : C
ied reverse of binary string that appears before 'C’,
Input Buffer
‘Transition Tablesine ee or invalid, valid if the input String follow set A (define
0 pDA has to determine whether the input string is according to the
or not.
ove
{1 on stee®
at the PDA machine for above AIM, hence it can be define as M(Q, £, I
1A, FY where |
‘.
gst of states: {q0, ql.q2}
. set of input symbols: {0, 1, C}
: Set of stack symbols: {A, B, Z}
0 initial state (qd)
0: initial stack symbol (Z)
fz set of Final states: {} [Note: Here, set of final states is null as decision of
validity of sting i based on stack whether itis empty or not f empty means
valid else invalid] —
& Transition Function
TRANSITION STATE
5(0, 0, 2) + (qo, Az)
(40, 1, Z) + (q0, Bz)
8(q0, 0, A) — (q0, AA)
(40, 0, B) — (q0, AB)
5(q0, 1, A) — (g0, BA)
8(q0, 1, B) + (90, BB)
5(q0, C, A) + (ql, A)
3(g0, C, B) > (ql, B)
&(ql, 0, A) > (ql)
8(q1, 1, B) > (ql, e)
a, 6.2) 00,
‘)Code in C++
#include
#include
#include
void main()
{
char Input{100};
char stack(100};
int Top = -1;
clrser();
cout<<"Enter string to be validate\n";
gets(Input);
stack[++Top] ='Z's//Taking 'Z'as an initial stack symbol.
int i=-1;
eeie
itn} 0 && stack/Top]-— py
‘
\
stack[++Top]= ‘A’;
goto qd:
\
else if(Input[i]=="1' && stack{Top]== ‘2
‘
{
stack[++Top]= 'B';
goto q0:
\
}
else iftInput{i]="0' && (stack{Top|==
‘A\| stack{Top]=='B'))
i
stack[++Top|=
goto q0:
\
5
else if(Input[i]-="1' && (stack{Top]==
‘A\l stack[Top]=='B'))
{
stack[++Top]= 'B';
goto q0:
1
j
else if{UnputfiJ="C’ && (stack{Top]=
f
t
‘A|stack{Top]="B}))
goto ql:goto ny aids
al
ies
Unputfi} 0 &E stack] Poppe 9
\
Vop=:
goto ql:
}
+ else if(Input[i}--'l' && stack{Top|=='B’)
\
Top:
goto ql:
| }
}
else if(Input[i]==\0' && stack[Top|== '2')
goto Valid:
goto Invalid:
5
Valid:
cout<<"\n Output: Valid String"
goto exit:
Invalid:
—cout \n Output: Invalid String”
gota exit
¢
od!
cus
pe COs Cx ors CRS Ud
een continue. oe eee
ror Valid string:
FF -C\psers\DelNDocumenstoc practcalisetiajaere
| eer validate
output: Valid String
Ta rae BCs) execution time : 12.409 s
Peron PerseCOMPUTER SCIENCE ENGINNERING DEPT.
)LAB,V-SEM (2021-22)
THEORY OF COMPUTATION Practial File (CS-501
‘Student Name -SEHJANYA SINGH Roll no -0301CS191083 ate:28/10/2021
Practical-7
OBJECTIVE: Design a Turing Machine that calculate 2's complement of
given binary string.
THEORY: As per the AIM, Input can be any binary string and we have to design 2 turing
machine that can calculate its two's complement. ,
For example (as shown in Figure 4) ifthe input binary string is 1011010000 then its two's
complement will be 0100110000. For constructing a turing machine if we look in the logic
then if we read the input string from right to left then the cutput string will remain exactly
the same until the first 1 is found and as the first 1 encounter, complement of rest string
appear in the output.
Input: 10110 10000
Output: 01001, ion
J
a
Output
Complement
ofinput
string
Figure 1: Input outpur relationship of 2's complement of binary string while reading right to
left.
Let M be the Turing Machine for above AIM, hence it can be define as M(Q, 8, , 6, 40, 8, F)
where
Q: set of states: {g0, 41, 42}
& set of input symbols: {0, 1}
F:Set of Tape symbols: {0, 1, 8}
40: intial state (gO)g: Blank Symbol (8)
F: set of Final states: { (Note: Here, set of final sta
: tes is null as her
turing machine as enumerator] a
6: Transition Function:
State Input
0 1 8
qo (q0, 0, R) (q0, 1, R) (q1, B, L)
qi (91, 0, l) (q2, 1, L)
a2 (92,1, L) (2, 0, t) (q3,B, R)
q3
Rules for implementing turing machine for a given language
Initial Setup: Load the input string in input buffer and consider the machine in at initial state
0.
Rules:
1. Move the input head at right direction, till it reaches to B. If B encounter then change
state from q0 to qi
Now, start reading input symbol right to left one by one.
3. If the input symbol is 0, move the input head left and do the same for all O till 1
encounter.
If the input symbol is 1, move the input head left and change its state from qi to q2.
Now, if the input symbol is 0, make it 1 and if input symbol is 1 make it O till reach to
the starting point.
Code in C++
#include
#include
#include
void main()
{
char Input[100];
clrscr();
cout<<"Enter input binary string\n";
gets(input);
1Sjp inputlil=*"1)
goto a0,
)
else inqinputlil=="\0)
7
goto a1;
else
goto Invalid;
gu
if(Input[iJ=='0')
{
ij
goto qi;
}
{
iy
goto q2;
}
else
{goto Invalid;
goto q2;
}
else if(input[
~ {
1)
Inputli'0;
in;
goto 2;
}
else iffiz= -1)
{
goto 93;
goto Invalid;
a3:
Cout<<"\nOutput: Two's complement is";
puts(Input);
goto exit;
Invalid:
cout<<"\n You have entered some invalid string,”,goto exit;
exit!
getchi);
urPuT
| no “C\users\Del!\Documents\toc practical\[Link]
certs aro
Toe)
butput: Two's complement is@1010
Sees CD)
ee MR Com) SU
toc practical\sehyanyae:
Te auras Crs
Ct) 4 =
COs Nema eee ot aes
a dees tas
Co Clas Cle eC (aed
BProcess returned @ (@x@) execution time :
13.912 s
BCs egame SEHIANYA SINGH Roll no, -0301CS191053
ut!
Date:28/102021
Practical-8
oiective= Design a Turing Machine that increment Biven binary number by one.
s Turing machine can be formally described as seven tuples
(aX, £.6,00,8,F)
where,
Qisa finite set of states.
Xis the tape alphabet
Lis the input alphabet
6s a transition function: 5:QxX>OxXx(left shift, right shift}
QQ is the initial state
Bis the blank symbol
Fis the final state.
A Turing Machine (TM) is a mathematical model which consists of an infinite length tape
divided into cells on which input is given. It consists of a head which reads the input tape. A
state register stores the state of the Turing machine.
After reading an input symbol, it is replaced with another symbol, its internal state is changed,
and it moves from one cell to the right or left. If the TM reaches the final state, the input string
is accepted, otherwise the string is rejected
The Turing machine has a read/write head. So, we can write on the tape.
Algorithm: -arcane #5 ¥° 7
yee place the first ,0" from the right end by 1.
Re
Fig: Transition Diagram
ample:
inary increment means adding 1 to the given input.
input - 0111
Output - 1000
Input - 10000
Output - 10001
Diagram: -
Code: -
#include
int main()
{
intnum, binary_val, decimal_val = 0, base = 1, rem,i,a{10];
//accepting binary number as an input
printf("Enter a binary number(1s and 0s) \n"};
scanf("%d", &num); /* maximum five digits */
binary_val = num;ve
ven binary number to decimal //number
ing Bi
ve
i num? 0}
: aie (
i = num % 10;
rem=
| = decimal_val + rem * base;
gecimal_V2
yn num / 10;
pase = base * 2;
)
printf("The Binary number is = %d \n", binary_val);
printf("Its decimal equivalent is = %d \n", decimal_val);
//incrementing decimal no
decimal_val++;
// again converting decimal to binary
for(i=0;decimal_val>0;i++)
{
alil=decimal_vai%2;
decimal_val=decimal_val/2;
}
printf(""\nBinaryincreament of Given Number is=");
for(i=i-
{
printf("%d",a[i]);
}
return 0;
}ear binary number(1s and @s)
pkg
he Binary number is = 1¢10
peel e Mae ATE i Ree C2}
Binary increament of Given Number Pies meCOMPUTER SCIENCE ENG:
INNERING DEPT.
TMEORY OF COMPUTA TION p,
actical File (CS-S01)[Link] (2021-22).
cgutent Same SEHIANYA SINGH Roll no. 0301191053
Date:t 1/11/2021
Practical-9
Objective ~ Design a Turing Machine that's accepts the following language a
b"c” where n>0.
Discussion: -
ATuring machine can be formally described as seven tuples
(QX, £,6,40,B,F)
Where,
Qisa finite set of states,
X is the tape alphabet
Zis the input alphabet
6 isa transition function: 5:0xXOxXx(left shift, right shift}
Q0 is the initial state
Bis the blank symbol
Fis the final state.
A Turing Machine (TM) is a mathematical model which Consists of an infinite length tape
Givided into cells on which input is given. It consists of a head which reads the input tape. A
state register stores the state of the Turing machine.
After reading an input symbol, its replaced with another symbol, its internal state is changed,
and it moves from one cell to the right or left. f the TM reaches the final state, the input string
is accepted, otherwise the string is rejected.
The Turing machine has a read/write head. So, we can write on the tape.gst
york’ then move right.
yak’ then move right
)Mark'e' then move left
4Cometo far left till we get 'X’
s)Repeat above steps till all 'a','b' and 'c' are el
@)At last if everything is marked that means String is accepted,
YR)
@zR)
Fig: Transition Diagram
Code:
#includeciostream>
#include
#include>a;sen(a)*3!") //if string length is not multiple of 3 , reject
"aot accepted\n";
até ‘Not
ts
-
enestrden(a)/35 //len= length of the input string
cgo(iedsicdens i++)
we(ali}!='2")
{
cout<<"Not accepted\n";
exit(®);
}
}
for(j=i;j