Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The questions are below the code. I am just wondering if my math is even close to correct. public class MethodsToAnalyze { /** Return index

The questions are below the code. I am just wondering if my math is even close to correct.

image text in transcribed

image text in transcribed

image text in transcribed

public class MethodsToAnalyze { /** Return index where value is found in array or -1 if not found. @param array ints where value may be found * @param value int that may be in array * @return index where value is found or -1 if not found public static int find(int[] array, int value) { // 3 + n(3), O(n) for (int i = 0; i -1) { array[index] = newValue; index = find(array, oldvalue); } } 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? The worst-case scenario would be that every index contained the oldValue and needed to be replaced with the new value. This would mean that the while loop would be executed and would have to iterate through every index, making a call to the find() method through each loop. Using n for the while loop multiplied by 3+3n for the find() method. As well as checking the while condition each time and assigning newValue T(n) = 1(3+3n) +1 +n(1) + n(3+3n) = 3+3n+1+n+3n+3n^2 = 3n^2 + 7n + 4 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()? Assuming that it will iterate through at least half an array on average to find the oldValue, we can use n^2/2 and n/2

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 Concepts

Authors: David Kroenke, David J. Auer

3rd Edition

0131986252, 978-0131986251

More Books

Students also viewed these Databases questions

Question

Is the person willing to deal with the consequences?

Answered: 1 week ago