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

Please turn the following algorithm into a C++ program. Thanks. USE NODE A as th

ID: 3819754 • Letter: P

Question

Please turn the following algorithm into a C++ program. Thanks.

USE NODE A as the ROOT. In addition to the default output similar to above, determine and print the LENGTH AND SEQUENCE OF THE LONGEST BRANCH in the resulting tree. There are several methods to do this:

Method A: Increment a global counter in the first line of traverse, and decrement the global counter on the last line of traverse. Also keep a separate global stack, push when incrementing the counter, pop when decrementing the counter. Also keep track of the max counter value. If a new max is created, print the global stack. This method will print several stacks, each one longer than the previous one, so the last one printed will be the longest path in the tree.

Method B: You should be able to omit the global stack if you use the data already pushed onto the function all stack. You can implement this in C using pointers, you just need to (somehow) determine the size of the stack frame, then you can iterate up the stack.

Please use method A if possible because it can be done in c++. Method B works for me as well.

// A recursive solution for a stack traversal of a graph

/*
Each instance of traverse keeps track of one node’s adjacency list. The CALL to and RETURN from traverse, are similar to PUSH and POP.

};

static bool[] visited = {false, false, false, false, false, false, false, false};

// the resulting tree. Each node's parent is stored

// "Push" C

init target to 0 // index 0 is node A
  while(not at end of node’s list) // count thru cols in node’s row

{

   if(target is node’s neighbor and target is unvisited)

   {

   next target

}

Explanation / Answer

};

static bool[] visited = {false, false, false, false, false, false, false, false};

// the resulting tree. Each node's parent is stored

// "Push" C

init target to 0 // index 0 is node A
  while(not at end of node’s list) // count thru cols in node’s row

{

   if(target is node’s neighbor and target is unvisited)

   {

   next target

}