Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Convert the for loop to a while loop and calculate its time complexity, please include the cost for each step. a sample output is provided

Convert the for loop to a while loop and calculate its time complexity, please include the cost for each step. a sample output is provided below.

```code

int sum=1; for (int a=0;a0) sum--;<>

image text in transcribed

Example 2 Find the time complexity of function findmax in Figure 2 that finds the maximum value in the array of integer given by the two parameters A and n int findmax(int All, int n) f int max-A[0]; for (int i-1;ikn;i++) if (A [i]>max) max=A[i]; return max, Figure 2. Program for Example 2. Solution: Complete the following steps 1. Create a three column table putting line numbers in the first column, statements of the program in the second column, and the cost of each statement in the third column. Sum the cost of the individual statements to find the cost of the program. 2. Line Statement Cost 1 int findmax(int All, int n) { int max=A[O]; int i1; while (imax) max-AM; 2k return max, Total Total Total T(n) 4k + 3 T(n)-4(n - 1) +3 T(n) = 4n-1<>

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

Microsoft SQL Server 2012 Unleashed

Authors: Ray Rankins, Paul Bertucci

1st Edition

0133408507, 9780133408508

More Books

Students also viewed these Databases questions

Question

16.8 Explain the typical steps in a grievance procedure.

Answered: 1 week ago

Question

2. Discuss the steps in preparing a manager to go overseas.

Answered: 1 week ago

Question

8. Measure the effectiveness of the succession planning process.

Answered: 1 week ago