Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Need Help WIth the answer to the TODOs in the java code below. Need it for arraylist and linkedlist package cs271.lab.list; import java.util.ArrayList; import java.util.LinkedList;
Need Help WIth the answer to the TODOs in the java code below. Need it for arraylist and linkedlist package cs271.lab.list; import java.util.ArrayList; import java.util.LinkedList; import java.util.List; import org.junit.After; import org.junit.Before; import org.junit.Test; public class TestPerformance { 1 // TODO run test and record running times for SIZE = 10, 100, 1000, 10000, ... // (choose in conjunction with REPS below up to an upper limit where the clock // running time is in the tens of seconds) 2 // TODO which of the two lists performs better as the size increases? private final int SIZE = 10; 3 // TODO choose this value in such a way that you can observe an actual effect // for increasing problem sizes private final int REPS = 1000000; private ListarrayList; private List @Before public void setUp() throws Exception { arrayList = new ArrayListlinkedList; (SIZE); linkedList = new LinkedList (); for (var i = 0; i < SIZE; i++) { arrayList.add(i); linkedList.add(i); } } @After public void tearDown() throws Exception { arrayList = null; linkedList = null; } @Test public void testLinkedListAddRemove() { for (var r = 0; r < REPS; r++) { linkedList.add(0, 77); linkedList.remove(0); } } @Test public void testArrayListAddRemove() { for (var r = 0; r < REPS; r++) { arrayList.add(0, 77); arrayList.remove(0); } } @Test public void testLinkedListAccess() { var sum = 0L; for (var r = 0; r < REPS; r++) { sum += linkedList.get(r % SIZE); } } @Test public void testArrayListAccess() { var sum = 0L; for (var r = 0; r < REPS; r++) { sum += arrayList.get(r % SIZE); } } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started