Question

Consider the following code fragment: void list_array_print(ArrayList<String> name_lists[], int len){      for (int i=0; i <...

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?

0 0
Add a comment Improve this question Transcribed image text
Answer #1

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).

Add a comment
Know the answer?
Add Answer to:
Consider the following code fragment: void list_array_print(ArrayList<String> name_lists[], int len){      for (int i=0; i <...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT