Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

CS Java Question. Algorithm: sortIt() Minimum Statements. How many statements would be executed in a call to sortIt() when the array size is zero (n

CS Java Question. Algorithm: sortIt()

Minimum Statements. How many statements would be executed in a call to sortIt() when the array size is zero (n == 0) or one (n == 1)?

Best Case Scenario. Under what conditions would the minimum number of statements be executed for an array where n is large? Would the algorithm execute a different number of statements if the elements in the array were already in sorted order? Reverse order? Random order? All the same? What is the growth function under the best case conditions?

Worst Case Scenario. Under what conditions would the maximum number of statements be executed for an array where n is large? (Already in some kind of sorted order? Duplicates?) What is the growth function under the worst-case conditions?

What is the runtime order (big-O) of sortIt() based on the above growth functions?

Code:

* Take an int[] and reorganize it so they are in ascending order.

* @param array ints that need to be ordered

*/

public static void sortIt(int[] array) {

for (int next = 1; next < array.length; next++) {

int value = array[next];

int index = next;

while (index > 0 && value < array[index - 1]) {

array[index] = array[index - 1];

index--;

}

array[index] = value;

}

}

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

Repairing And Querying Databases Under Aggregate Constraints

Authors: Sergio Flesca ,Filippo Furfaro ,Francesco Parisi

2011th Edition

146141640X, 978-1461416401

More Books

Students also viewed these Databases questions

Question

What is most practical and efi cient?

Answered: 1 week ago

Question

Identify the elements that make up the employee reward package.

Answered: 1 week ago

Question

Understand the purpose, value and drawbacks of the interview.

Answered: 1 week ago