Question: 4. Given an ArrayList of initial size n, give a big-O characterization (and justification) of the running time of the following Java function, in


 4. Given an ArrayList of initial size n, give a big-O characterization 

4. Given an ArrayList of initial size n, give a big-O characterization (and justification) of the running time of the following Java function, in terms of n: public void doubleList (ArrayList myList) { int size = myList.size(); for (int i = 0; i < size; i++) { int pos= rand.nextInt (myList.size()); // rand is a Random object myList.add(pos, i); } } Would your answer change if the the fourth line instead read "int pos myList.size();"? If so, what would be the new running time and why?

Step by Step Solution

3.43 Rating (156 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

Answer Lets analyze the original function and the modified version Original Function public void dou... View full answer

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 Programming Questions!