Consider the following code fragment:
void list_array_print(ArrayList<String> name_lists[], int len){
for (int i=0; i < len; ++i){
for(String s : name_lists[i]){
System.out.println(s);
}
}
}
What is the time complexity for this method?
Select one:
a. None of the alternatives since each list might have different size.
b. O(N), N = len
c. O(1)
d. O(N*M), N = len, and M = max(name_lists[i])
wHICH ONE?
Answer d) O(N * M) because there are two loops, the outer for loop iterates for N = len and the inner for loop iterates for M for each iteration of outer for loop therefore the total complexity of this particular code fragment will be O(N * M).
Consider the following code fragment: void list_array_print(ArrayList<String> name_lists[], int len){ for (int i=0; i <...