Question: For the following problem, draw execution diagrams and use these diagrams to determine the BigO time complexities. Explain your BIG O answers! Hand-execute the following
For the following problem, draw execution diagrams and use these diagrams to determine the BigO time complexities. Explain your BIG O answers! Hand-execute the following code using the graphical diagramming technique demonstrated by the instructor. For each problem you must: 1) Draw a box for each function instance 2) Draw box(es) for local variables and parameters inside each function box 3) Draw boxes outside of all other boxes to show any global variables 4) Show the values of variables changing inside the boxes 5) Put all the code within each function box 6) Indicate program flow inside boxes with arrows 7) Draw arrows between boxes indicating calls to functions 8) Indicate on each arrow any argument values passed to a function 9) Draw arrows between boxes indicating any return values 10) Indicate on each arrow any values returned from a function 11) Show any output from the program 12) Show and explain the the final BigO!
1) Hanoi
void main() { // start the solution here Hanoi(3, 1, 3, 2); } void Hanoi (int N, int Start, int Goal, int Spare) { if (N == 1) // move the disk to the goal peg cout << "Move disk from peg " << Start << " to peg " << Goal << endl; else { // move the disks above the target disk to the spare peg Hanoi(N - 1, Start, Spare, Goal); // move the "target" disk to the goal peg cout << "Move disk from peg " << Start << " to peg " << Goal << endl; // move the disks from the spare peg to the goal peg Hanoi(N - 1, Spare, Goal, Start); } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
