The following routine removes the first half of the list pas

The following routine removes the first half of the list passed as a parameter: public static void removeFirstHalf (List 1st) {int the size = 1st. size ()/2 for (inti = 0, I

Solution

a. We need exit condition to stop loop. Here we have to traverse till half of the List, so here theSize stores the value of half of the length of list.

b. Running time : (n/2)*(n/2) = n^2/4 = O(n^2), Removing an element from a position in array list requires shifting of all right side elements by 1 in left side.

c. Running time: n/2 = O(n)

d. No, iterator does not make any defference in running time

 The following routine removes the first half of the list passed as a parameter: public static void removeFirstHalf (List 1st) {int the size = 1st. size ()/2 fo

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site