Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

public static HashSet<Integer> doHashSetSearchGreatest(int numItems) { System.ou

ID: 3923303 • Letter: P

Question

   public static HashSet<Integer> doHashSetSearchGreatest(int numItems) {

       System.out.print("doHashSetSearchGreatest: ");

       HashSet<Integer> set = new HashSet<>();

       // TODO Write code that adds integers 0 through (numItems - 1)

       // to set.

       long startTime = getTimestamp();

       // TODO Write code that checks if integer (numItems - 1)

       // is a member of set.

       long endTime = getTimestamp();

       long totalTime = endTime - startTime;

       System.out.println(totalTime);

      

       return set;

   }

Explanation / Answer

1.Code that appends integers 0 through (numitems - 1) to the list. I have added a loop for adding values to the list

for(int i=0; i<numItems-1; i++)

       list.add(i);

  

2.code that checks if integer (numItems - 1)

if(set.contains(numItems-1))

   System.out.println((numItems-1)+ " is a memeber of set");

else

   System.out.println((numItems-1)+ " is not a memeber of set");

   long endTime = getTimestamp();

//long endTime = System.currentTimeMillis();

long totalTime = endTime - startTime;

System.out.println(totalTime);