Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1) Explain your choice of the input size n and in terms of O(n) scale determine the running time (number of steps) T(n) of the

1) Explain your choice of the input size n and in terms of O(n) scale determine the running time (number of steps) T(n) of the algorithms represented by the methods.

Use the simplest and possibly the smallest valid Big-Oh expression.

T(n) can also be considered as the number elementary operations the algorithm must make.

2) If it applies, point out your estimates for the worst and best cases, and also for the average case performance if available.

3) Document each method describing what you consider the methods precondition and post-condition.

4) It is not necessary to run these methods in actual programs, but if the task it performs is dubious, testing the method with various input in actual applications of the code may help to find its purpose and the big-Oh estimate.

static int find(int[] arr){

zeroCounter = 0;

(int k = 0; k< arr.length; k++){

(arr[k]==0)

zeroCounter++;

}

(zeroCounter == arr.length)

0;

(zeroCounter < arr.length - 2){

//see maxIndex() definition below

max = maxIndex(arr);

arr[max] = 0;

//see display() definition below

display(arr);

zeroCounter ++;

}

maxIndex(arr);

//end method

//helper methods

static int maxIndex(int[]arr){

int maxindex = 0;

for(int k = 0 ; k< arr.length; k++){

// note the use of absolute value

if(Math.abs(arr[maxindex]) < Math.abs(arr[k]))

maxindex = k;

}

return maxindex;

}

static void display(int[]arr){

System.out.println();

for(int k = 0 ; k< arr.length; k++)

System.out.print(arr[k]+ );

System.out.println();

}

Comments

What does the method do:

Input size n =

Worst case T(n) = O(________) Best case T(n) = O(________)

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

Database Fundamentals Study Guide

Authors: Dr. Sergio Pisano

1st Edition

B09K1WW84J, 979-8985115307

More Books

Students also viewed these Databases questions

Question

develop your skills of project planning.

Answered: 1 week ago