Answered step by step
Verified Expert Solution
Question
1 Approved Answer
public class Main { public static void main(String args) { 1/declaration and instantiation of lists Linkedlist TestLinkedList = new LinkedList(); ArrayList TestArrayList = new ArrayList();
public class Main { public static void main(String args) { 1/declaration and instantiation of lists Linkedlist TestLinkedList = new LinkedList(); ArrayList TestArrayList = new ArrayList(); // 1. Get the first command line argument and store it as an integer value called n 1/ 2. Randomly generate n doubles and insert them at the first place in TestLinkedlist. // The easiest way to do this is to generate a random int from 0 to TestLinkedlist.size(), inclusive, // and use the add(element) method from LinkedList class. (Not you should be using the inbuilt Linked List | Il class not the Linked List that you created for the last lab) // 3. Remove 1/4 of the elements throughouth the list, at random indecies. // 4. Repeat 2 and 3 with TestArrayList // Add in timing code for both steps 2 and 3 so you can compare the time for the Linked and Array list. // to help you out, here's the timing code, with helpful comments on where to insert your code. // Test with command line arguments of 100, 1000, 10000, and 100000. //process command-line argument 1/get time before code is run. //process command-line argument 1/get time before code is run. long starttime = System.nanoTime(); //TestArrayList 1/get time after code is run and subtract start time to get time elapsed. long totaltime = System.nanoTime() - starttime; System.out.println("ArrayList insertion and removal time: + totaltime + ns"); starttime = System.nanoTime(); //TestLinkedList 2 code totaltime = System.nanoTime() - starttime; System.out.println ("LinkedList insertion and removal time: + totaltime + " ns"); } } // Fill out the Time Comparisions file in this project and then write a paragraph describing your observations // and the time complexity of Adding and removing from both the Linked List and the ArrayList. Fill out the following Tables. ArrayList Add Time | Remove Time I 100 1000 10000 100000 I LinkedList n | Add Time | Remove Time 100 1000 10000 100000 I | public class Main { public static void main(String args) { 1/declaration and instantiation of lists Linkedlist TestLinkedList = new LinkedList(); ArrayList TestArrayList = new ArrayList(); // 1. Get the first command line argument and store it as an integer value called n 1/ 2. Randomly generate n doubles and insert them at the first place in TestLinkedlist. // The easiest way to do this is to generate a random int from 0 to TestLinkedlist.size(), inclusive, // and use the add(element) method from LinkedList class. (Not you should be using the inbuilt Linked List | Il class not the Linked List that you created for the last lab) // 3. Remove 1/4 of the elements throughouth the list, at random indecies. // 4. Repeat 2 and 3 with TestArrayList // Add in timing code for both steps 2 and 3 so you can compare the time for the Linked and Array list. // to help you out, here's the timing code, with helpful comments on where to insert your code. // Test with command line arguments of 100, 1000, 10000, and 100000. //process command-line argument 1/get time before code is run. //process command-line argument 1/get time before code is run. long starttime = System.nanoTime(); //TestArrayList 1/get time after code is run and subtract start time to get time elapsed. long totaltime = System.nanoTime() - starttime; System.out.println("ArrayList insertion and removal time: + totaltime + ns"); starttime = System.nanoTime(); //TestLinkedList 2 code totaltime = System.nanoTime() - starttime; System.out.println ("LinkedList insertion and removal time: + totaltime + " ns"); } } // Fill out the Time Comparisions file in this project and then write a paragraph describing your observations // and the time complexity of Adding and removing from both the Linked List and the ArrayList. Fill out the following Tables. ArrayList Add Time | Remove Time I 100 1000 10000 100000 I LinkedList n | Add Time | Remove Time 100 1000 10000 100000 I |
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