






















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
The design of various finite state machines and pushdown automata to accept different types of strings and perform operations on binary numbers. The programs include designing a machine that accepts strings ending with '101', a machine that accepts strings with equal number of '1's and '0's, a machine that accepts decimal numbers divisible by 2, a machine that counts the number of '1's and '0's in a given string, a program to increment a binary number by 1, and a program to create a pushdown automaton that accepts well-formed parentheses. The problem statements, solutions, and explanations for these experiments, making it a valuable resource for students studying automata theory, formal languages, and programming concepts related to string processing and numerical operations.
Typology: Study notes
1 / 30
This page cannot be seen from the preview
Don't miss anything!
S. Expt. Name of the Experiment Date of Exp. Date of Perform Sign No. No.
EXPERIMENT No. – 1 PROBLEM DEFINATION :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:
EXPERIMENT No. – 2 PROBLEM DEFINATION : Design a Program for creating machine that accepts the string always ending with
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 101 always. Viva Questions:
Solution: #include
Solution: C++ program to find remainder without using #include
break; case 'B': else state='A'; state='A'; if(str[i]=='0') state='C'; else if(str[i]=='1') state='A'; break; case 'C': if(str[i]=='1') state='C'; else if(str[i]=='0') state='B'; break; } cout<<state; } if(state=='A') cout<<"\n string is accepeted as it reached the final state ....."<<state<<"......at the end"; else cout<<"\n string is not accepted as it reached.... "<<state<<"......which is not the final state"; }
Solution: #include
return dec_value; } int main(){ string inputString; int number; cout<<"Enter Input string containing {0,1}:"; cin>>inputString; int length = inputString.length(); cout<<"\n Number in Decimal Format:"; number = binaryToDecimal(inputString); cout<<number; if(inputString[length-1] == '0'){ cout<<"
n"<<number<<" is divisible by 2"; } else { cout<<"\n"<<number<<" is not divisible by 2"; } /* if(number%2 == 0){ cout<<"
n"<<number<<" is divisible by 2"; } else { cout<<"\n"<<number<<" is not divisible by 2"; } */ return 0; }
EXPERIMENT No. – 5 PROBLEM DEFINATION : Design a program for creating a machine which accepts string having equal no. of 1’s and 0’s. Problem Statement: This is the program to check whether the string having equal no. of 1’s and 0’s or Not. Enter Binary string. Use Logic to manipulate. Declare if-else Condition. Displaying output on the Display. Viva Questions:
Solution: #include<iostream.h> #include<conio.h> #include<string.h> int main() { clrscr(); char *ar; int i,count=0,c=0,n; cout<<"Enter string in the form of 0 and 1 "; cin>>ar; n=strlen(ar); for(i=0;i<n;i+ +) { if(ar[i]=='0') count++; else } if( count == c ) cout<<”\n Accepted (Equal 0s & 1s)”; cout<<”\n Rejected”; return 0; } c++;
cout<<"No of 0's="<<count<<endl; cout"no of 1's="<<c; return 0; }
EXPERIMENT No. – 7 PROBLEM DEFINATION : Design a Program to find2’scomplement of a given binary number.. Problem Statement: Twos complement of an N-bit number is defined as the complement with respect to 2N. It is the result of subtracting the number from 2N, which in binary is one followed by N zeroes. In simple words twos complement is defined as sum of 1’s complement of a binary number and 1. Logic: Step by step descriptive logic to find twos complement of a binary string.
printf("Enter %d bit binary value: ", SIZE); /* Input 8-bit binary string / gets(binary); / Find ones complement of the binary number / for(i=0; i<SIZE; i++) { if(binary[i] == '1') { onesComp[i] = '0'; } else if(binary[i] == '0') { onesComp[i] = '1'; } } onesComp[SIZE] = '\0'; /
EXPERIMENT No. – 8 PROBLEM DEFINATION : Design a Program which will increment the given binary number by 1. Problem Statement: This is the program to count whether the no. of 1’s and 0’s in given string. Enter Binary string. Convert the binary string to Decimal Increment the value Convert the value into binary number Viva Questions: