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

A standard Turing machine acceptor accepts an input string if it enters a halt s

ID: 3569569 • Letter: A

Question

A standard Turing machine acceptor accepts an input string if it enters a halt state at any
time during the computation. Write a detailed construction method for turning a standard
Turing machine acceptor M into a Turing machine acceptor with output M' that erases its
input and writes 1 or 0 in the leftmost tape cell (just to the right of the left end marker)
before it halts. The machine M' should write 1 for the strings that are in L(M) and 0 for
strings not in L(M) that cause M to terminate in a non-halt state.
Your write-up should include the following: 1) a general construction method using
formal notation where appropriate, 2) an informal explanation of the method, and 3) at
least one specific example of applying the method.

Explanation / Answer

include <stdio.h>

# include <conio.h>

# include <stdlib.h>

typedef struct BST {

  int data;

  struct BST *lchild, *rchild;

} node;

void insert(node *, node *);

void inorder(node *);

void preorder(node *);

void postorder(node *);

node *search(node *, int, node **);

void main() {

  int choice;

  char ans = 'N';

  int key;

  node *new_node, *root, *tmp, *parent;

  node *get_node();

  root = NULL;

  clrscr();

  printf(" Program For Binary Search Tree ");

  do {

     printf(" 1.Create");

     printf(" 2.Search");

     printf(" 3.Recursive Traversals");

     printf(" 4.Exit");

     printf(" Enter your choice :");

     scanf("%d", &choice);

     switch (choice) {

     case 1:

       do {

           new_node = get_node();

           printf(" Enter The Element ");

           scanf("%d", &new_node->data);

           if (root == NULL) /* Tree is not Created */

             root = new_node;

           else

             insert(root, new_node);

           printf(" Want To enter More Elements?(y/n)");

           ans = getch();

       } while (ans == 'y');

       break;

     case 2:

       printf(" Enter Element to be searched :");

       scanf("%d", &key);

       tmp = search(root, key, &parent);

       printf(" Parent of node %d is %d", tmp->data, parent->data);

       break;

     case 3:

       if (root == NULL)

           printf("Tree Is Not Created");

       else {

           printf(" The Inorder display : ");

           inorder(root);

           printf(" The Preorder display : ");

           preorder(root);

           printf(" The Postorder display : ");

           postorder(root);

       }

       break;

     }

  } while (choice != 4);

}

/*

Get new Node

*/

node *get_node() {

  node *temp;

  temp = (node *) malloc(sizeof(node));

  temp->lchild = NULL;

  temp->rchild = NULL;

  return temp;

}

/*

This function is for creating a binary search tree

*/

void insert(node *root, node *new_node) {

  if (new_node->data < root->data) {

     if (root->lchild == NULL)

       root->lchild = new_node;

     else

       insert(root->lchild, new_node);

  }

  if (new_node->data > root->data) {

     if (root->rchild == NULL)

       root->rchild = new_node;

     else

       insert(root->rchild, new_node);

  }

}

/*

This function is for searching the node from

binary Search Tree

*/

node *search(node *root, int key, node **parent) {

  node *temp;

  temp = root;

  while (temp != NULL) {

     if (temp->data == key) {

       printf(" The %d Element is Present", temp->data);

       return temp;

     }

     *parent = temp;

     if (temp->data > key)

       temp = temp->lchild;

     else

       temp = temp->rchild;

  }

  return NULL;

}

/*

This function displays the tree in inorder fashion

*/

void inorder(node *temp) {

  if (temp != NULL) {

     inorder(temp->lchild);

     printf("%d", temp->data);

     inorder(temp->rchild);

  }

}

/*

This function displays the tree in preorder fashion

*/

void preorder(node *temp) {

  if (temp != NULL) {

     printf("%d", temp->data);

     preorder(temp->lchild);

     preorder(temp->rchild);

  }

}

/*

This function displays the tree in postorder fashion

*/

void postorder(node *temp) {

  if (temp != NULL) {

     postorder(temp->lchild);

     postorder(temp->rchild);

     printf("%d", temp->data);

  }

}

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