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...
Write a DFA simulator using the C++ programming language. Please refer to the following UDACITY website...
Write a DFA simulator using the C++ programming language. Please refer to the following UDACITY website if you do knot know C++. This is a free online tutorial for learning C++. 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 in form: startstate, blank, symbol read, blank, tostate Prompt user for name of file. From there, program prompts the user for strings...
Code in C Instructions For this programming assignment you are going to implement a simulation of...
Code in C Instructions For this programming assignment you are going to implement a simulation of Dijkstra’s solution to the Dining Philosophers problem using threads, locks, and condition variables. Dijkstra’s Solution Edsgar Dijkstra’s original solution to the Dining Philosophers problem used semaphores, but it can be adapted to use similar mechanisms: • Each philosopher is in one of three states: THINKING, HUNGRY, or EATING. • Every philosopher starts out in the THINKING state. • When a philosopher is ready to...
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 ∈ Σ ∗ }
Write a program in python programming language to implement/simulate a finite automaton that accepts (only): odd...
Write a program in python programming language to implement/simulate a finite automaton that accepts (only): odd Binary numbers // 00000000, 0101, 111111, etc. Show: Finite Automaton Definition, Graph, Table
Write a program in python programming language to implement/simulate a finite automaton that accepts (only): unsigned...
Write a program in python programming language to implement/simulate a finite automaton that accepts (only): unsigned integer numbers // 123, 007, 4567890, etc. Show: Finite Automaton Definition, Graph, Table.
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...
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT