Use the following method to generate an array (arr1) of 5000 randomly generated elements. public static int[] RandomArrayGenerator(int n) { int[] Array = new int[n]; Random r = new Random(); for(int...


Use the following method to generate an array (arr1) of 5000 randomly generated elements.


  public static int[] RandomArrayGenerator(int n)


  {


    int[] Array = new int[n];


    Random r = new Random();


    for(int i=0;i<>


    {


      Array[i] = r.nextInt(1000);


    }


    return Array;


  }


[Note that by using nextInt(100) you will generate an integer between 0 and  100.]



  1. Use insertion sort to sort arr1.

  2. Use RandomArrayGenerator again to create arr2 containing 5000 randomly generated element.

  3. Use the static sort methods of Java's Arrays class to sort arr2.

  4. Time each of the methods so that you can make a comparison of the efficiency. You can create longs and store the system time to know when the method starts and ends. You can then take the difference run time in milliseconds.


long startTime = System.currentTimeMillis();


//call sort method here


long endTime = System.currentTimeMillis();



Jun 07, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here