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

C++ lang. For this lab we will perform both a breadth-first and a depth-first se

ID: 653214 • Letter: C

Question

C++ lang. For this lab we will perform both a breadth-first and a depth-first search on a tree that you construct from a file. For this one you will need to utilize the node class to build your own tree structure and handle connecting each node as you read in data from the file. Once the tree is constructed you will then ask the user for a search term. You will then search using both DFS and BFS and return the value if found and the number of steps to search using both methods (whether the item was found or not). You should print out each node as you visit it to give the path of the search techniques. You will then give a simple comparison as to which was more efficient (least number of steps). The file will be called

Explanation / Answer

typedef struct Tree {

   int data;

   struct Tree *leftchild, *rgtchild;

} node;

{node *new_node, *root;

   node *NEW_node();

   root = NULL;

       new_node = NEW_node();

            if (root == NULL)

               root = new_node;

            else

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

      if (root->leftchild == NULL)

         root->leftchild = new_node;

      else

         insert(root->leftchild, new_node);

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

      if (root->rgtchild == NULL)

         root->rgtchild = new_node;

      else

         insert(root->rgtchild, new_node);

   }

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