Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

What is the time complexity for this? sum=0; for(i=0;i Answer as shown below: Example 2 Find the time complexity of function findmax in Figure 2

What is the time complexity for this?

sum=0; for(i=0;i

Answer as shown below:

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 Visual Basic 2008 Comprehensive Concepts And Techniques

Authors: Gary B. Shelly, Corinne Hoisington

1st Edition

1423927168, 978-1423927167

More Books

Students also viewed these Databases questions