Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

variables m and n are assumed to have been declared as integers. Also assume that when the code fragment begins execution, the variable n has

variables m and n are assumed to have been declared as integers. Also assume that when the code fragment begins execution, the variable n has a positive value (i.e., is 1 or greater), and the function push is a basic operation. Stack s = new Stack(); // Create an empty stack named s. for (m = 0; m < n; ++m) s.push(m * m); // Push the square of m onto the stack s.

Let T(n) denote the execution time that will be observed when this code fragment is executed. Which of the following statements best describes T(n) ? Explain why. (a) T(n) = An + B for some constants A and B . (b) A1n + B1 T(n) A2n + B2 for some constants A1 , B1 , A2 , and B2 . (c) T(n) = An2 + Bn + C for some constants A, B, and C .

the variables m and n are assumed to have been declared as integers, and the array a has at least n cells that have been given various integer values. for (m = n1; m >= 0; m) if (a[m] < 0) // If a[m] is negative, then change a[m] *= (1); // its sign by multiplying it by 1 . Let T(n) denote the execution time that will be observed when this code fragment is executed. Which of the following statements best describes T(n) ? Explain why. (a) T(n) = An + B for some constants A and B . (b) A1n + B1 T(n) A2n + B2 for some constants A1 , B1 , A2 , and B2 . (c) T(n) = An2 + Bn + C for some constants A, B, and C .

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

More Books

Students also viewed these Databases questions