Consider the following implementation of the insertion sort algorithm for an ArrayList of Strings.
Remember that the remove() method returns the element that is being removed from the ArrayList.

public static int insertSort(ArrayList list) {
int count = 0;
for (int i = 1; i < list.size(); i++){
String toInsert = list.get(i);
int j;
for (j = i; j > 0; j--){
count++;
if (toInsert.compareTo(list.get(j-1)) >= 0){
break;
}
}
list.add(j, list.remove(i));
}
return count;
}

The method returns an int which represents a statement execution count. What will this value be when the method returns if the parameter list contains the following Strings in the following order:

a. "door"
b. "car"
c. "malware"
d. "arithmetic"



Answer :

Other Questions