Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

We only defined a DFA to either \"accept\" or \"not accept\" a string, based on

ID: 3856160 • Letter: W

Question

We only defined a DFA to either "accept" or "not accept" a string, based on whether the machine, when reading that string, ended in a final state or not. Consider a variant called an Output-DFA: it is a 6-tuple (Q, E, Lambda, delta, q_0, F) where Q, E, q_0, F are defined exactly as in a normal DFA, but T is the output alphabet, and delta: Q times sigma times (Lambda times (Lambda Union {epsilon}) rightarrow Q is the transition function. In other words, we associate either a character of Lambda or epsilon as the "output" of executing that transition. We commonly write a transition of this form as q a/b rightarrow q' where a is the character read, and b is the character outputted. For such an Output-DFA M and w elementof sigma*, let M(w) be the concatenation of the characters outputted on each transition taken, and the machine only outputs anything if and only if the machine has read all of its input. If M has language L, let Out(M) = {M(w): w elementof L}. (a) Prove that if L is regular, then Out(M) is regular. (b) A fixed point string is a string that, when applying some function to it, the function returns the same string. Consider an Output-DFA M with the same input and output alphabet. Prove that the language: FP(M) = {w elementof E*: M(w) = w} is regular. (c) Suppose that instead of outputting a single character from T (or epsilon) on each transition, we output a string in T*. Call these machines Output*-DFAs. Prove that the languages outputted by Output-DFAs and those outputted by Output*-DFAs are the same.

Explanation / Answer

#include<stdio.h>

#define max 100

int main()

{

char str[max],f='x',c;

printf("do you want to check for epsilon string's case? (y/n) : ");

scanf("%c",&c);

if(c=='y'|| c=='Y')

goto flag;

printf("enter the string to be checked: ");

scanf("%s",str);

int i;

for(i=0;i<strlen(str);i++)

{

switch(f)

{

case 'x': if(str[i]=='0') f='y';

else if(str[i]=='1') f='x';

break;

case 'y': if(str[i]=='0') f='x';

else if(str[i]=='1') f='y';

break;

}

}

flag: if(f=='x') printf(" String is accepted as it reaches the final state that is %c",f);

else printf(" String is not accepted as it reaches a state %c which is not the final state",f);

return 0;

}

OR

#include <iostream>

#include <string>

#include <stdlib.h>

#include <new>

using namespace std;

int main() {

string *states, *final, *trap, **transition,input, tmp;

char *alf, temp;

int nos, nots, nofs, noa, i, j, current, flag;

cout << "This is a program to simulate a DFA" << endl;

cout << "Enter the number of states, number of final states and"

<< " the number of trap states. ";

cin >> nos >> nofs >> nots;

cout << "Enter the number of symbols in the alphabet: ";

cin >> noa;

states = new string[nos];

final = new string[nofs];

trap = new string[nots];

alf = new char[noa+1];

cout << " Enter the states (initial state first) ";

for (i = 0; i < nos; i++)

cin >> states[i];

cout << "Enter the final states: ";

for (i = 0; i < nofs; i++)

cin >> final[i];

cout << "Enter the trap states: ";

for (i = 0; i < nots; i++)

cin >> trap[i];

cout << "Enter the alphabet for the DFA: ";

for (i = 0; i < noa; i++)

cin >> alf[i];

//allocating space for the transition table

transition = new string *[nos];

for (i = 0; i < nos; i++)

transition[i] = new string[noa];

//getting the values for the transition table

cout << "Enter the transition for the given states:";

for (i = 0; i < nos; i++) {

cout << " For state " << states[i] << endl;

for (j = 0; j < noa; j++) {

cout << "On input " << alf[j] << " to state : ";

cin >> transition[i][j];

}

}

cout << "The transition table you entered is : ";

cout << "state ";

for (i = 0; i < noa; i++)

cout << alf[i] << " ";

for (i = 0; i < nos; i++) {

cout << endl << states[i] << " ";

for (j = 0; j < noa; j++)

cout << transition[i][j] << " ";

}

while (true) {

current = 0, flag = 0;// current will keep track of the current state

cout << " Enter the input string( enter exit to terminate) : ";

cin >> input;

if (input.compare("exit") == 0)

exit(0);

for (i = 0; i < input.length(); i++) {

// process the string and change the state accordingly

temp = input.at(i);

// getting the index of the input from the alphabet set

for (j = 0; j < noa; j++) {

if (alf[j] == temp) {

break;

}

}

// storing the value of transition state

tmp = transition[current][j];

// changing the current state to the next state

for (int k = 0; k < nos; k++)

if (states[k].compare(tmp) == 0) {

current = k;

break;

}

// loop for checking if a the dfa is in a trap state

for (j = 0; j < nots; j++)

if (states[current].compare(trap[j]) == 0) {

cout << "The input string has been rejected";

flag = 1;

break;

}

if (flag == 1)

break;

}

if (flag == 1)

continue;

for (i = 0; i < nofs; i++)

if (states[current].compare(final[i]) == 0) {

cout << "The input has been accepted by the DFA";

flag = 1;

break;

}

if (flag == 1)

cout << "The input has been rejected by the DFA";

}

return 0;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote