Question

In: Computer Science

Description: In this assignment, you will implement a deterministic finite automata (DFA) using C++ programming language...

Description:

In this assignment, you will implement a deterministic finite automata (DFA) using C++ programming language to extract all matching patterns (substrings) from a given input DNA sequence string.

  1. The alphabet for generating DNA sequences is {A, T, G, C}. Write a regular expression that represents all DNA strings that begin with ‘A’ and end with ‘T’. Note: assume empty string is not a valid string.
  2. Design a deterministic finite automaton to recognize the regular expression.
  3. Write a program which asks the user to input a DNA sequence. The program should be able to extract all the patterns (substrings present in the DNA sequence) that match the regular expression given in 1. You MUST implement DFA from (2) to check if all possible substrings in the DNA sequence is a part of the regular expression or not.

Note: even if the same pattern is found multiple times, it should be printed every time it is found. The program should mimic how a DFA processes a string: reading one letter at a time and doing state transitions. Don’t directly check if the string begins with ‘A’ and end with ‘T’.

Below are two sample input/output. Only the bolded are user input.

Input a DNA sequence: CATTTGCAGGTG

Matching patterns are:

AT

ATT

ATTT

ATTTGCAGGT

AGGT

Input a DNA sequence: TTTATAAAA

Matching patterns are:

AT

What to submit:

A zipped file containing the following:

  1. A digital copy of the regular expression
  2. A digital copy of diagram of the DFA.
  3. a cpp file representing your program
  4. Screen shots of your output

Solutions

Expert Solution

(a) DFA

q0- initial state

q2- final state

(b) Code


#include <bits/stdc++.h>
using namespace std;

set<string> s2;

void func(string stri)
{
  
   for (int i = 0; i < stri.length(); i++)
   {
       if (stri[i]=='A')
       {
           for (int j = i; j < stri.length(); j++)
           {
               if (stri[j]=='T')
               {
                   string s = stri.substr(i, j);
                   s2.insert(s);
               }
           }
       }
   }
}

int main()
{
   string s = "CATTT";
   func(s);

   for (auto i : s2)
       cout << i << " ";
   cout << endl;

   return 0;
}

Output


Related Solutions

Automata Theory and Formal Languages Instructions: Draw the DFA (Deterministic Finite Automaton) of the following: DFA...
Automata Theory and Formal Languages Instructions: Draw the DFA (Deterministic Finite Automaton) of the following: DFA in which set of all strings can be accepted which end with ‘a’ DFA in which set of all strings can be accepted which start with ab DFA in which set of all strings can be accepted which contain ab DFA in which set of all strings can be accepted which ends with ab
Automata Theory and Formal Languages Instructions: Draw the DFA (Deterministic Finite Automaton) of the following: DFA...
Automata Theory and Formal Languages Instructions: Draw the DFA (Deterministic Finite Automaton) of the following: DFA for binary number divisible by 2 DFA for binary number divisible by 3 DFA in which set of all strings can be accepted which start with a DFA in which set of all strings can be accepted which contains ‘a’
DFA Python DFA simulator A deterministic finite automaton (DFA) - also known as deterministic finite state...
DFA Python DFA simulator A deterministic finite automaton (DFA) - also known as deterministic finite state machine - is a finite state machine that accepts/rejects finite strings of symbols and only produces a unique computation (or run) of the automaton for each input string. Write a DFA simulator using the python programming language. Read your DFA from a textfile. First line contains a list of the final states (as integers), separated by a space. Rest of file contains the transitions...
Programming Language: JAVA In this assignment you will be sorting an array of numbers using the...
Programming Language: JAVA In this assignment you will be sorting an array of numbers using the bubble sort algorithm. You must be able to sort both integers and doubles, and to do this you must overload a method. Bubble sort work by repeatedly going over the array, and when 2 numbers are found to be out of order, you swap those two numbers. This can be done by looping until there are no more swaps being made, or using a...
Prove that string concatenation cannot be checked by finite automata by showing that the following language...
Prove that string concatenation cannot be checked by finite automata by showing that the following language over Σ = {0, 1} is not regular: L3 = {w1#w2#w1w2 : w1, w2 ∈ Σ ∗ }
You are using ONLY Programming Language C for this: In this program you will calculate the...
You are using ONLY Programming Language C for this: In this program you will calculate the average of x students’ grades (grades will be stored in an array). Here are some guidelines to follow to help you out: 1. In your program, be sure to ask the user for the number of students that are in the class. The number will help in declaring your array. 2. Use the function to scan the grades of the array. To say another...
In the C programming language, implement the translation from regular English to Euroglish. If the letters...
In the C programming language, implement the translation from regular English to Euroglish. If the letters were uppercase, keep them uppercase in the replacement. 1. Remove one“e”from the end of words that are more than three characters long, if they happen to end in “e”. 2. Change all double letters to a single letter (including double spaces). Do not remove double line spacing (i.e. “\n”). 3. When a word ends in “ed”, change that to just “d”. Text: The cat...
Class object in C++ programming language description about lesson inheritance example.
Class object in C++ programming language description about lesson inheritance example.
Class object in C++ programming language description about lesson inheritance example.
Class object in C++ programming language description about lesson inheritance example.
In C/C++ programming language, write down the lines of codes (and figure) to show- a) assignment-by-sharing...
In C/C++ programming language, write down the lines of codes (and figure) to show- a) assignment-by-sharing b) dangling reference
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT