Question
For each of the following problems, draw execution diagrams and use these diagrams to determine the time complexities in Big O notation. EXPLAIN YOUR BIG
For each of the following problems, draw execution diagrams and use these diagrams to determine the time complexities in Big O notation. EXPLAIN YOUR BIG O ANSWERS!
Hand-execute the following code using the graphical diagramming technique demonstrated in class. 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!
A) BOB
int y; // global y gets its own box
// (only one y box for the wholeprogram)
void p(int x)
{
x = y - 1;
y += x;
cout << x << " " << y << endl;
if (x < 3) p(x);
cout << x << " " << y << endl;
}
void main(void)
{
int x;
x = 0; y = 2; p(x); cout << x << " " << y << endl;
}
B) 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);
}
}
please solve both the parts as they are separate. don't just solve any one of them please. And do Show and explain the the final BigO
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started