Question: 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;a

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 (i
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
