Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

*JAVA ONLY* /** * Replace all occurrences of oldValue with newValue in array. * @param array ints where oldValue may be found * @param oldValue

*JAVA ONLY*

/** * 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) 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?

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

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

More Books

Students also viewed these Databases questions

Question

5 The mechanics of the circular flow model.

Answered: 1 week ago

Question

1 The difference between a command system and a market system.

Answered: 1 week ago

Question

4 How the market system adjusts to change and promotes progress.

Answered: 1 week ago