Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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) Fibonacci Numbers

int fib(int n)

{

if (n == 0)

return 0;

if (n == 1)

return 1;

else

return fib(n - 1) + fib(n - 2);

}

int main(void)

{

cout << fib(6);

}

B) 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;

}

C) 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);

}

}

these A,B,and C are three parts so as per chegg policy please provide answer for these 3 parts not just one of them please. And do show and explain BIGO for them. Thanks

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data And Information Quality Dimensions, Principles And Techniques

Authors: Carlo Batini, Monica Scannapieco

1st Edition

3319241060, 9783319241067

More Books

Students also viewed these Databases questions

Question

6. What qualifications are needed to perform the job?

Answered: 1 week ago