0% found this document useful (1 vote)
2K views5 pages

CS 501 TOC Student 'S Lab Manual ODD Experiment 1 & 2 (1) - 1563252281

This document contains a lab manual for the Theory of Computation laboratory course. It includes an index listing experiments to be conducted, with spaces to record the dates and signatures for when each experiment is completed. The first experiment described is about designing a program to create a machine that accepts three consecutive ones. The second experiment is about designing a program to create a machine that accepts strings always ending in "00". The document provides the aims, theories, sample questions, and solutions for each experiment.

Uploaded by

Tanay Patil
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (1 vote)
2K views5 pages

CS 501 TOC Student 'S Lab Manual ODD Experiment 1 & 2 (1) - 1563252281

This document contains a lab manual for the Theory of Computation laboratory course. It includes an index listing experiments to be conducted, with spaces to record the dates and signatures for when each experiment is completed. The first experiment described is about designing a program to create a machine that accepts three consecutive ones. The second experiment is about designing a program to create a machine that accepts strings always ending in "00". The document provides the aims, theories, sample questions, and solutions for each experiment.

Uploaded by

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

THEORY OF COMPUTATION LABORATORY 1

LAB MANUAL
(CS-501)

V Sem (CSE)

CHAMELI DEVI GROUP OF


INSTITUTIONS, INDORE

CHAMELI DEVI GROUP OF INSTITUTIONS, INDORE. DEPARTMENT OF COMPUTER SCIENCE & ENGG
THEORY OF COMPUTATION LABORATORY 2

CHAMELI DEVI GROUP OF INSTITUTIONS


INDORE (M.P.)

DEPARTMENT OF
Computer Science & Engg

CERTIFICATE

This is to certify that Mr./Ms……………………………………………………………… with RGPV

Enrollment No. 0832 ..…………………………..has satisfactorily completed the course of experiments in

Theory of Computation laboratory, as prescribed by Rajiv Gandhi Proudhyogiki Vishwavidhyalaya, Bhopal

for V Semester of the Computer Science & Engg Department during year 2019 20

Signature of
Faculty In-charge

CHAMELI DEVI GROUP OF INSTITUTIONS, INDORE. DEPARTMENT OF COMPUTER SCIENCE & ENGG
THEORY OF COMPUTATION LABORATORY 3

INDEX
Sl. Expt. Name of the Experiment Date Signature
No. No. of of Faculty-
Condu in-Charge
ction
01. 1 Design a Program for creating machine that accepts three consecutive one
02. 2 Design a Program for creating machine that accepts the string always ending 00

EXPT. No. - 1. TO STUDY LEX TOOL AND ITS INSTALLATION IN LINUX

CHAMELI DEVI GROUP OF INSTITUTIONS, INDORE. DEPARTMENT OF COMPUTER SCIENCE & ENGG
THEORY OF COMPUTATION LABORATORY 4
Aim: Design a Program for creating machine that accepts three consecutive one?

Theory: Given an array of n non-negative numbers, the task is to find the minimum sum of elements (picked
from the array) such that at least one element is picked out of every 3 consecutive elements in the array.
Examples :
Input : arr[] = {1, 2, 3}
Output : 1
Input : arr[] = {1, 2, 3, 6, 7, 1}
Output : 4
We pick 3 and 1 (3 + 1 = 4)
Note that there are following subarrays
of three consecutive elements
{1, 2, 3}, {2, 3, 6}, {3, 6, 7} and {6, 7, 1}
We have picked one element from every subarray.
Input : arr[] = {1, 2, 3, 6, 7, 1, 8, 6, 2, 7, 7, 1}
Output : 7
The result is obtained as sum of 3 + 1 + 2 + 1
Viva Questions:
1. Define Automata?
2. What is the application of Finite Automata?
3. What does it mean that string end with 3 consecutive 1?
4. What are the characteristics of Automata?
Solution:
Sum (i) be the minimum possible sum when arr[i] is part of a solution sum (not necessarily result) and is last picked
element. Then our result is minimum of sum(n-1), sum(n-2) and sum(n-3) [We must pick at least one of the last three
elements].
We can recursively compute sum(i) as sum of arr[i] and minimum(sum(i-1), sum(i-2), sum(i-3)). Since there
are overlapping sub problems in recursive structure of problem, we can use Dynamic Programming to solve this problem.
Example
for (int i=3; i<n; i++)
sum[i] = arr[i] +
minimum(sum[i-3], sum[i-2], sum[i-1]);

EXPT. No.- 2.TO WRITES A PROGRAM FOR ACCEPTING THE STRING ALWAYS ENDS WITH 00

Aim: Design a Program for creating machine that accepts the string always ending 00

CHAMELI DEVI GROUP OF INSTITUTIONS, INDORE. DEPARTMENT OF COMPUTER SCIENCE & ENGG
THEORY OF COMPUTATION LABORATORY 5

Theory: An NFA is typically described using a directed graph. Each edge and vertex is labelled either 0 or 1
representing possible transitions. Vertices represent the states of the NFA. Those labelled 0 are non accepting
states, and those labelled 1 are accepting states.
 It takes an input string of finite length. Typically, the input string is a binary sequence of 0’s and 1’s.
 We begin with the vertex 1 which is always the start state and follow the edges sequentially given by the
bits of input string until the input string has no further bit.
 The term ‘non deterministic’ means that at any state V we have more than one choice of following an
edge. The NFA consumes the input string and set of states Q represents the possible moves of NFA.
 If Q contains at least one state where the last vertex is accepting then we say that the NFA has accepted
the input string otherwise the NFA has rejected the input string.
 String should end with 00 always.

Viva Questions:
1. Define string created by using alphabet?
2. How to design the automata for accepting the string?
3. How the string is accepted by the Automata?
4. Difference between DFA and NDFA?

Solution:
String should start with any 1 or 0 but it should end with 00 by using switch case and for loop for finding the
number of alphabets in the string.
Considering the example:

for(i=0;str[i]!='\0';i++)
{
switch(f)
{
case 'a': if(str[i]=='0') f='b';
else if(str[i]=='1') f='a';

CHAMELI DEVI GROUP OF INSTITUTIONS, INDORE. DEPARTMENT OF COMPUTER SCIENCE & ENGG

You might also like