Question: *JAVA ONLY* Defend all answers based on specific references to the code. Do not count return statements or initialization of method arguments. You are strongly

*JAVA ONLY*

Defend all answers based on specific references to the code. Do not count return statements or initialization of method arguments. You are strongly encouraged to walk through algorithms in the debugger and to add statement-counting code to given methods to test and refine your analysis. All growth functions must be in simplified t(n) = ____ format and order must be presented in proper big-O notation.

/** * Replace all occurrences of oldValue with newValue in array. * @param array ints where oldValue may be found * @param oldValue value to replace * @param newValue new value */ public static void replaceAll(int[] array, int oldValue, int newValue) { int index = find(array, oldValue); while (index > -1) { array[index] = newValue; index = find(array, oldValue); } }

Algorithm: replaceAll()

1.

A) Expected Average Case Scenario. Assuming a randomly ordered array of unique elements and oldValue is a value in the array, how many replaceAll() loop iterations will occur? How many loop iterations in calls to find()? What is the expected average growth function for a call to replaceAll()?

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

Additionally, what arguments could I add to the command line or surrounding the method itself to verify the answers to these questions?

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!