Question: public static void replaceAll(int[] array, int oldValue, int newValue) { int index = find(array, oldValue); while (index > -1) { array[index] = newValue; index =

 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()

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

B) Best Case Scenario. Under what conditions would the minimum number of replaceAll() loop iterations be executed for an array where n is large? What would cause the replaceAll() loop to never iterate even if n is large? What is the cost of the find() call(s) under these conditions? What is the total growth function under these conditions?

C) Worst Case Scenario. Assuming newValue and oldValue are not equal, under what conditions would the maximum number of replaceAll() loop iterations be executed for an array where n is large? Note that every call to find() inside the replaceAll() loop is guaranteed to iterate a different number of times, so what would the average number of find() loop iterations be?What is the total growth function under these conditions?

D) 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()?

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

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!