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 (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
Answer Lets analyze the original function and the modified version Original Function public void dou... View full answer
Get step-by-step solutions from verified subject matter experts
