Courses‎ > ‎AP Computer Science‎ > ‎Konstantinovich‎ > ‎


posted Dec 10, 2018, 6:16 AM by Konstantinovich Samuel   [ updated Dec 10, 2018, 7:18 AM ]
Do Now: 
Time both your selection and bubble sorts for 10k, 20k, 40k, and 80k elements.

Save this java File in your Sorts repo.
import java.util.Arrays;
public class Driver{

  public static void main(String[]artie){

    int[] randish = new int[Integer.parseInt(artie[0])];
    for(int i = 0 ; i < randish.length; i++){
      randish[i] =(int)(Math.random()*10000);

      int[] randish2 = Arrays.copyOf(randish,randish.length);
      int[] randish3 = Arrays.copyOf(randish,randish.length);
      if( Arrays.equals(randish,randish3)){
        System.out.println("Selection Correct!");
       System.out.println("Selection BROKEN!!!!");
      if( Arrays.equals(randish2,randish3)){
        System.out.println("Bubble Correct!");
       System.out.println("Bubble BROKEN!!!!");

Use the following commands:
java Driver 10000 test
time java Driver 10000 selection
time java Driver 20000 selection
time java Driver 40000 selection
time java Driver 80000 selection
time java Driver 10000 bubble
time java Driver 20000 bubble
time java Driver 40000 bubble
time java Driver 80000 bubble

Add your times to this google sheet along with your osis/period

This is NOT a competition. 
If you could not get the sort working, then please say so and put 100 for the numerical values.

New Material:

Homework: Complete insertionSort(int[])