Ask Question
24 May, 00:15

Suppose list1 is an ArrayList and list2 is a LinkedList. Both contains 1 million double values. Analyze the following code: A: for (int i = 0; i < list1. size (); i++) sum + = list1. get (i); B: for (int i = 0; i < list2. size (); i++) sum + = list2. get (i);

+2
Answers (2)
  1. 24 May, 01:14
    0
    Code fragment A runs faster than code fragment B.

    Explanation:

    The analysis of the code revealed that code fragment A runs faster than code fragment B.
  2. 24 May, 02:33
    0
    Code A runs faster than Code B.

    Explanation:

    Values are stored as index based in the ArrayList. If you like to access one element, time complexity will be O (1). However, if you like to access an element in the LinkedList, you need to go through all the elements before that element, time complexity will be O (n).
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “Suppose list1 is an ArrayList and list2 is a LinkedList. Both contains 1 million double values. Analyze the following code: A: for (int i = ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers