Question: Start from this code: __________________________________________ import java.util.*; public class SetListPerformanceTest { static final int N = 35500; public static void main(String[] args) { // Add
Start from this code: __________________________________________
import java.util.*;
public class SetListPerformanceTest {
static final int N = 35500;
public static void main(String[] args) {
// Add numbers 0, 1, 2, ..., N - 1 to the array list
List list = new ArrayList<>();
for (int i = 0; i < N; i++)
list.add(i);
Collections.shuffle(list); // Shuffle the array list
// Create a hash set, and test its performance
Collection
System.out.println("Member test time for hash set is " + getTestTime(set1) + " milliseconds");
System.out.println("Remove element time for hash set is " + getRemoveTime(set1) + " milliseconds");
// Create a linked hash set, and test its performance
Collection
System.out.println("Member test time for linked hash set is " + getTestTime(set2) + " milliseconds");
System.out.println("Remove element time for linked hash set is " + getRemoveTime(set2) + " milliseconds");
// Create a tree set, and test its performance
Collection
System.out.println("Member test time for tree set is " + getTestTime(set3) + " milliseconds");
System.out.println("Remove element time for tree set is " + getRemoveTime(set3) + " milliseconds");
// Create an array list, and test its performance Collection list1 = new ArrayList<>(list);
System.out.println("Member test time for array list is " + getTestTime(list1) + " milliseconds");
System.out.println("Remove element time for array list is " + getRemoveTime(list1) + " milliseconds");
// Create a linked list, and test its performance
Collection
System.out.println("Member test time for linked list is " + getTestTime(list2) + " milliseconds");
System.out.println("Remove element time for linked list is " + getRemoveTime(list2) + " milliseconds");
}
public static long getTestTime(Collection c) {
long startTime = System.currentTimeMillis();
// Test if a number is in the collection
for (int i = 0; i < N; i++)
c.contains((int)(Math.random() * 2 * N));
return System.currentTimeMillis() - startTime;
}
public static long getRemoveTime(Collection c) {
long startTime = System.currentTimeMillis();
for (int i = 0; i < N; i++)
c.remove(i);
return System.currentTimeMillis() - startTime;
}
}
__________________________________________
Add at least 3 data structures that are not in it. For example the stack data structure. For each of the 3 new data structures add to them the elements in "list" using whatever "add" method is appropriate and them and then use the getTestTime() and getRemoveTime methods on them.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
