Bubble Sort

  • iterates through starting at the first index, compare the first and second elements
  • if the first element if greater than the second element then they are swapped otherwise they are not swaped and the iteration ends
  • then compare the second and third elements and swap if they are not in order
  • this process continues until the last element for this specific element
  • the remaining iterations do the same thing until the largest element is placed at the end
  • in each iteration the comparsion takes place up to the last unsorted element
import java.util.*;
import java.lang.*;
class SortManager<Integer extends Comparable<Integer>> {
    private final String name;
    private Integer temp; 
    private ArrayList<Integer> lefty = new ArrayList<Integer>();
    private ArrayList<Integer> righty = new ArrayList<Integer>();
    public ArrayList<Integer> arr1 = new ArrayList<Integer>(); // Creates arraylist to be implemented into the different sort methods
    public ArrayList<Integer> arr2 = new ArrayList<Integer>();
    public ArrayList<Integer> arr3 = new ArrayList<Integer>();
    public ArrayList<Integer> arr4 = new ArrayList<Integer>();

    
    public SortManager(String name) {
        this.name = name;
    }

    public SortManager(String name, Integer[] list) {
        this.name = name;
        this.addList(list);
        
    }

    public void addList(Integer[] list) {
       // for (Integer[] objects: seriesOfObjects)
            for (Integer data: list) {
                this.arr1.add(data);
                this.arr2.add(data);
                this.arr3.add(data);
                this.arr4.add(data);
            }
    }

    public void bubbleSort(ArrayList<Integer> array) {
        int n = array.size(); // find the length of the arraylist
        for (int i = 0; i < n - 1; i++) { // iterates through every element in the arraylist
            for (int j = 0; j < n - i - 1; j++) { // makes sure that the current index is less than the length and does not repeat iteration over the elements that are already "locked" in their place

            Integer x = array.get(j);
            Integer y = array.get(j+1);
                if (x.compareTo(y) > 0) { // if the first element is greater than second element then they are swapped otherwise the position of that element is locked and it moves to the next element
                    // only happens if the swap occurs
                    // when implemented into the queue, this is where the compare to method would be used
                    this.temp = x;
                    array.set(j, y);
                    array.set(j + 1, this.temp); // easy swap function

                    System.out.println("Swapped " + x + " with " + y + " for index " + j);
                }
                else{
                    System.out.println("No swap needed for " + x + " at index " + j);
                }
                
            }
                System.out.println(array);
        }

    }

    public void selectionSort(ArrayList<Integer> array) {
        int n = array.size();

        for (int i = 0; i < n-1;i++) {
            int minimumIndex = i; // setting the minimum to the first value in the array before iterating to find the true minimum value
            for (int j = i + 1; j < n; j++){
                if (array.get(j).compareTo(array.get(minimumIndex)) < 0) {
                    minimumIndex = j;
                    System.out.println("The minimum value in the array is now " + j); // finds the true minimum of the array
                }

            }

            this.temp = array.get(minimumIndex);
            array.set(minimumIndex, array.get(i));
            array.set(i, this.temp); // easy swap function

            System.out.println("Swapped " + array.get(i) + " with " + array.get(minimumIndex) + " for index " + i);
            System.out.println(array);
        }

    }

    public void insertionSort(ArrayList<Integer> array) {
        int n = array.size();
        for (int i = 0; i < n-1;i++) {
            Integer current = array.get(i); // takes the second element in the array
            int j = i - 1;

            while (j >= 0 && (array.get(j).compareTo(current) > 0)) { // the swap only executes if j is greater than 0 meaning that there are still values in front of j and that the element in front of the current one is greater tan the current
                array.set(j + 1, array.get(j));
                System.out.println("Swapped " + current + " with " + array.get(j) + " for index " + i);
                j = j - 1;
           
            }
            array.set(j+1, current);
            System.out.println(array); 
        }

    }

    public void middlePart(ArrayList<Integer> array, int left, int right) {
        if (left < right) {
            int middle = left + ((right-1) / 2);

            middlePart(array, left, middle);
            middlePart(array, middle + 1, right);

            mergeSort(array, left, middle, right);
        }
    }

    public void mergeSort(ArrayList<Integer> array, int left, int middle, int right) {
        int n = middle - left + 1;
        int n2 = right - middle;

        for (int i=0; i<n; i++){
            lefty.add(i,array.get(left + i));
        }
        for (int j=0; j<n2; j++){
            righty.add(j,array.get(middle+1+j));
        }

        int i = 0, j = 0;

        int k = left;
        while ( i < n && j < n2) {
            if (lefty.get(i).compareTo(righty.get(j)) < 0) {
                array.set(k, lefty.get(i));
                i++;
            }
            else {
                array.set(k, righty.get(j));
                j++;
            }
            k++;
        }

        while (i<n) {
            array.set(k, lefty.get(i));
            i++;
            k++;
        }

        while (j <n2) {
            array.set(k, righty.get(j));
            j++;
            k++;


    }
}


    public void printQueue() {
        System.out.println("Original List: ");
        for (Integer data : arr1)
            System.out.print(data + " ");
        System.out.println();
        System.out.println("Bubble Sorted List: ");
        bubbleSort(arr1);
        System.out.print(arr1);

        System.out.println();
        System.out.println();
        System.out.println("Selection Sorted List: ");
        selectionSort(arr2);
        System.out.print(arr2);

        System.out.println();
        System.out.println();
        System.out.println("Insertion Sorted List: ");
        insertionSort(arr3);
        System.out.print(arr3);

        System.out.println();
        System.out.println();
        System.out.println("Merge Sorted List: ");
        System.out.print(arr4);

        System.out.println();
        System.out.println();
    }

}
class SortTester {
    public static void main(String[] args) {
        Integer[] sortdata = new Integer[] { 5, 1, 4, 2, 8 };
        Integer[] sortdata2 = new Integer[] { 64, 34, 25, 12, 22, 11, 90 };

        SortManager test = new SortManager("Int", sortdata);
        test.printQueue();

        SortManager test2 = new SortManager("Int", sortdata2);
        test2.printQueue();

    }
}
SortTester.main(null);
Original List: 
5 1 4 2 8 
Bubble Sorted List: 
Swapped 5 with 1 for index 0
Swapped 5 with 4 for index 1
Swapped 5 with 2 for index 2
No swap needed for 5 at index 3
[1, 4, 2, 5, 8]
No swap needed for 1 at index 0
Swapped 4 with 2 for index 1
No swap needed for 4 at index 2
[1, 2, 4, 5, 8]
No swap needed for 1 at index 0
No swap needed for 2 at index 1
[1, 2, 4, 5, 8]
No swap needed for 1 at index 0
[1, 2, 4, 5, 8]
[1, 2, 4, 5, 8]

Selection Sorted List: 
The minimum value in the array is now 1
Swapped 1 with 5 for index 0
[1, 5, 4, 2, 8]
The minimum value in the array is now 2
The minimum value in the array is now 3
Swapped 2 with 5 for index 1
[1, 2, 4, 5, 8]
Swapped 4 with 4 for index 2
[1, 2, 4, 5, 8]
Swapped 5 with 5 for index 3
[1, 2, 4, 5, 8]
[1, 2, 4, 5, 8]

Insertion Sorted List: 
[5, 1, 4, 2, 8]
Swapped 1 with 5 for index 1
[1, 5, 4, 2, 8]
Swapped 4 with 5 for index 2
[1, 4, 5, 2, 8]
Swapped 2 with 5 for index 3
Swapped 2 with 4 for index 3
[1, 2, 4, 5, 8]
[1, 2, 4, 5, 8]

Merge Sorted List: 
[5, 1, 4, 2, 8]

Original List: 
64 34 25 12 22 11 90 
Bubble Sorted List: 
Swapped 64 with 34 for index 0
Swapped 64 with 25 for index 1
Swapped 64 with 12 for index 2
Swapped 64 with 22 for index 3
Swapped 64 with 11 for index 4
No swap needed for 64 at index 5
[34, 25, 12, 22, 11, 64, 90]
Swapped 34 with 25 for index 0
Swapped 34 with 12 for index 1
Swapped 34 with 22 for index 2
Swapped 34 with 11 for index 3
No swap needed for 34 at index 4
[25, 12, 22, 11, 34, 64, 90]
Swapped 25 with 12 for index 0
Swapped 25 with 22 for index 1
Swapped 25 with 11 for index 2
No swap needed for 25 at index 3
[12, 22, 11, 25, 34, 64, 90]
No swap needed for 12 at index 0
Swapped 22 with 11 for index 1
No swap needed for 22 at index 2
[12, 11, 22, 25, 34, 64, 90]
Swapped 12 with 11 for index 0
No swap needed for 12 at index 1
[11, 12, 22, 25, 34, 64, 90]
No swap needed for 11 at index 0
[11, 12, 22, 25, 34, 64, 90]
[11, 12, 22, 25, 34, 64, 90]

Selection Sorted List: 
The minimum value in the array is now 1
The minimum value in the array is now 2
The minimum value in the array is now 3
The minimum value in the array is now 5
Swapped 11 with 64 for index 0
[11, 34, 25, 12, 22, 64, 90]
The minimum value in the array is now 2
The minimum value in the array is now 3
Swapped 12 with 34 for index 1
[11, 12, 25, 34, 22, 64, 90]
The minimum value in the array is now 4
Swapped 22 with 25 for index 2
[11, 12, 22, 34, 25, 64, 90]
The minimum value in the array is now 4
Swapped 25 with 34 for index 3
[11, 12, 22, 25, 34, 64, 90]
Swapped 34 with 34 for index 4
[11, 12, 22, 25, 34, 64, 90]
Swapped 64 with 64 for index 5
[11, 12, 22, 25, 34, 64, 90]
[11, 12, 22, 25, 34, 64, 90]

Insertion Sorted List: 
[64, 34, 25, 12, 22, 11, 90]
Swapped 34 with 64 for index 1
[34, 64, 25, 12, 22, 11, 90]
Swapped 25 with 64 for index 2
Swapped 25 with 34 for index 2
[25, 34, 64, 12, 22, 11, 90]
Swapped 12 with 64 for index 3
Swapped 12 with 34 for index 3
Swapped 12 with 25 for index 3
[12, 25, 34, 64, 22, 11, 90]
Swapped 22 with 64 for index 4
Swapped 22 with 34 for index 4
Swapped 22 with 25 for index 4
[12, 22, 25, 34, 64, 11, 90]
Swapped 11 with 64 for index 5
Swapped 11 with 34 for index 5
Swapped 11 with 25 for index 5
Swapped 11 with 22 for index 5
Swapped 11 with 12 for index 5
[11, 12, 22, 25, 34, 64, 90]
[11, 12, 22, 25, 34, 64, 90]

Merge Sorted List: 
[64, 34, 25, 12, 22, 11, 90]

import java.util.*;
import java.lang.*;
class SortManager<Integer extends Comparable<Integer>> {
    private final String name;
    private Integer temp; 
    private ArrayList<Integer> lefty = new ArrayList<Integer>();
    private ArrayList<Integer> righty = new ArrayList<Integer>();
    public ArrayList<Integer> arr4 = new ArrayList<Integer>();

    
    public SortManager(String name) {
        this.name = name;
    }

    public SortManager(String name, Integer[] list) {
        this.name = name;
        this.addList(list);
        
    }

    public void addList(Integer[] list) {
       // for (Integer[] objects: seriesOfObjects)
            for (Integer data: list) {
               
               
                this.arr4.add(data);
            }
    }



    public void middlePart(ArrayList<Integer> array, int left, int right) {
        if (left < right) {
            int middle = left + ((right-1) / 2);

            middlePart(array, left, middle);

            
            middlePart(array, middle + 1, right);
            

            mergeSort(array, left, middle, right);
        }
    }

    public void mergeSort(ArrayList<Integer> array, int left, int middle, int right) {
        int n = middle - left + 1;
        int n2 = right - middle;

        for (int i=0; i<n; i++){
            lefty.add(i,array.get(left + i));
        }
        for (int j=0; j<n2; j++){
            righty.add(j,array.get(middle+1+j));
        }

        int i = 0, j = 0;

        int k = left;
        while ( i < n && j < n2) {
            if (lefty.get(i).compareTo(righty.get(j)) < 0) {
                array.set(k, lefty.get(i));
                i++;
            }
            else {
                array.set(k, righty.get(j));
                j++;
            }
            k++;
        }

        while (i<n) {
            array.set(k, lefty.get(i));
            i++;
            k++;
        }

        while (j <n2) {
            array.set(k, righty.get(j));
            j++;
            k++;


    }
}


    public void printQueue() {

        System.out.println();
        System.out.println();
        System.out.println("Merge Sorted List: ");
        middlePart(arr4, 0, arr4.size() - 1);
        System.out.print(arr4);

        System.out.println();
        System.out.println();
    }

}
class SortTester {
    public static void main(String[] args) {
        Integer[] sortdata = new Integer[] { 5, 1, 4, 2, 8 };
        Integer[] sortdata2 = new Integer[] { 64, 34, 25, 12, 22, 11, 90 };

        SortManager test = new SortManager("Int", sortdata);
        test.printQueue();

        SortManager test = new SortManager("Int", sortdata);
        test.printQueue();

    }
}
SortTester.main(null);

Merge Sorted List: 
[4, 2, 5, 1, 8]

// Java program for implementation of Bubble Sort
import java.util.*;
 
class BubbleSort {
    void bubbleSort(int arr[])
    {
        int n = arr.length;
        int count = 0;
        int count2 = 0;
        for (int i = 0; i < n - 1; i++) {
            for (int j = 0; j < n - i - 1; j++) {
                count++;
                if (arr[j] > arr[j + 1]) {
                    // swap arr[j+1] and arr[j]
                    int temp = arr[j];
                    arr[j] = arr[j + 1];
                    arr[j + 1] = temp;
                    count2++;
                }
            }
        }
                

        System.out.println("Number of Comparison " + count);
        System.out.println("Number of Swaps " + count2);
    }
 
    /* Prints the array */
    void printArray(int arr[])
    {
        int n = arr.length;
        for (int i = 0; i < n; ++i)
            System.out.print(arr[i] + " ");
        System.out.println();
    }
 
    // Driver method to test above
    public static void main(String args[])
    {
        BubbleSort ob = new BubbleSort();
        Random rd = new Random(); // creating Random object
        int[] arr = new int[5000];
        for (int i = 0; i < arr.length; i++) {
            arr[i] = rd.nextInt(10);
        }
        ob.printArray(arr);
        ob.bubbleSort(arr);
        System.out.println("Sorted array");
        ob.printArray(arr);
    
}
}
BubbleSort.main(null);
5 6 3 0 2 3 1 3 5 0 1 0 4 2 2 5 2 6 5 9 6 4 9 2 8 7 9 0 9 8 2 7 3 2 0 7 4 7 7 2 6 7 3 4 8 0 9 8 6 9 0 7 9 0 6 2 8 5 0 0 7 5 3 4 8 5 2 7 8 1 0 7 1 0 3 3 4 6 3 3 7 0 6 3 8 3 1 9 3 0 8 2 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9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 

Bubble Sort

Number of Data Time Number of Comparisons Number of Swaps
20 0.4 s 190 63
20 0.5 s 190 100
20 0.3 s 190 82
50 0.5 s 1225 537
50 0.4 s 1225 582
50 0.5 s 1225 507
100 0.6 s 4950 2243
100 0.6 s 4950 2723
100 0.7 s 4950 2030
500 1.3 s 124750 52315
500 1.0 s 124750 56154
500 0.6 s 124750 58842
1000 1.5 s 499500 222638
1000 1.7 s 499500 232023
1000 1.3 s 499500 226050
5000 7.1 s 12497500 5657897
5000 7.3 s 12497500 5642181
5000 7.7 12497500 5575902
// Java program for implementation of Selection Sort
import java.io.*;
public class SelectionSort
{
    void sort(int arr[])
    {
        int n = arr.length;
        int count = 0;
        int count2 = 0;
 
        // One by one move boundary of unsorted subarray
        for (int i = 0; i < n-1; i++)
        {
            // Find the minimum element in unsorted array
            int min_idx = i;
            for (int j = i+1; j < n; j++) {
                count++;
                if (arr[j] < arr[min_idx])
                    min_idx = j;
 
            // Swap the found minimum element with the first
            // element
            int temp = arr[min_idx];
            arr[min_idx] = arr[i];
            arr[i] = temp;
            count2++;
            }
        }

        System.out.println("Number of Comparison " + count);
        System.out.println("Number of Swaps " + count2);
    }
 
    // Prints the array
    void printArray(int arr[])
    {
        int n = arr.length;
        for (int i=0; i<n; ++i)
            System.out.print(arr[i]+" ");
        System.out.println();
    }
 
    // Driver code to test above
    public static void main(String args[])
    {
        SelectionSort ob = new SelectionSort();
        Random rd = new Random(); // creating Random object
        int[] arr = new int[5000];
        for (int i = 0; i < arr.length; i++) {
            arr[i] = rd.nextInt(10);
        }
        ob.printArray(arr);
        ob.sort(arr);
        System.out.println("Sorted array");
        ob.printArray(arr);
    }
}
SelectionSort.main(null);
1 2 8 6 8 6 9 2 9 9 1 9 4 3 5 3 0 3 7 3 9 9 1 6 3 0 9 3 8 9 3 4 2 1 9 2 7 7 7 6 8 7 6 9 5 4 3 7 3 0 5 3 0 6 5 4 2 3 7 8 0 3 5 9 4 8 1 7 6 9 1 0 7 3 4 3 6 2 2 0 4 8 6 0 5 1 0 4 1 0 7 8 8 7 6 7 5 9 2 4 2 6 4 5 8 3 5 5 7 1 3 5 4 4 4 4 2 6 6 2 0 9 6 9 9 7 0 3 2 1 9 9 2 0 6 4 3 1 7 3 0 3 9 3 9 8 1 7 9 7 5 5 4 1 5 4 8 9 4 3 3 0 9 9 9 2 3 1 5 8 4 7 6 7 4 5 2 4 9 6 3 9 8 4 5 8 2 2 2 9 9 9 9 8 2 4 2 0 8 7 4 9 1 3 3 6 3 8 9 1 0 1 8 7 6 2 9 5 3 3 4 8 3 4 5 4 1 5 8 3 1 8 6 8 2 3 6 0 5 2 6 7 9 5 1 7 2 8 0 1 8 0 7 7 9 7 2 7 1 4 0 0 8 7 1 1 1 0 8 6 8 6 0 6 9 3 3 2 1 9 2 3 1 8 7 9 8 3 2 1 9 2 8 9 9 0 1 5 5 2 2 7 1 0 1 0 4 9 1 2 3 2 9 2 3 1 3 8 3 7 6 6 7 2 7 0 4 6 0 0 8 0 1 1 5 3 4 1 6 6 5 7 8 6 9 9 5 0 8 8 4 4 0 5 7 8 0 2 7 3 0 5 1 9 5 8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750
500 1.4 s 124750 124750
500 1.5 s 124750 124750
1000 2.0 s 499500 499500
1000 1.6 s 499500 499500
1000 1.3 s 499500 499500
5000 8.0 s 12497500 12497500
5000 7.0 s 12497500 12497500
5000 6.1 s 12497500 12497500
// Java program for implementation of Insertion Sort
public class InsertionSort {
	/*Function to sort array using insertion sort*/
	void sort(int arr[])
	{
		int n = arr.length;
		int count = 0;
		int count2 = 0;

		for (int i = 1; i < n; ++i) {
			int key = arr[i];
			int j = i - 1;

			/* Move elements of arr[0..i-1], that are
			greater than key, to one position ahead
			of their current position */
			while (j >= 0 && arr[j] > key) {
				count++;
				arr[j + 1] = arr[j];
				j = j - 1;
				count2++;
			}
			arr[j + 1] = key;
		}

		System.out.println("Number of Comparison " + count);
        System.out.println("Number of Swaps " + count2);
	}

	/* A utility function to print array of size n*/
	static void printArray(int arr[])
	{
		int n = arr.length;
		for (int i = 0; i < n; ++i)
			System.out.print(arr[i] + " ");

		System.out.println();
	}

	// Driver method

	public static void main(String args[])
	{

		InsertionSort ob = new InsertionSort();
		Random rd = new Random(); // creating Random object
        int[] arr = new int[5000];
        for (int i = 0; i < arr.length; i++) {
            arr[i] = rd.nextInt(10);
        }
        ob.printArray(arr);
        ob.sort(arr);
        System.out.println("Sorted array");
        ob.printArray(arr);
	}
};

InsertionSort.main(null);
6 9 7 7 4 3 0 1 1 3 8 1 2 3 7 2 9 8 9 0 5 4 7 1 7 0 8 7 8 9 3 5 9 9 5 7 9 4 6 9 9 9 3 8 4 1 8 8 4 0 8 6 8 5 2 6 1 9 1 2 3 9 6 8 7 8 2 1 1 9 4 3 6 1 5 2 6 1 4 3 3 9 1 2 2 5 0 9 0 7 7 7 9 5 2 1 7 3 4 4 0 9 5 5 1 5 4 2 2 4 7 8 5 3 2 8 8 2 7 9 5 5 6 8 0 6 0 3 9 4 9 6 6 9 8 0 7 4 2 3 0 6 6 2 3 2 1 0 0 0 9 3 2 5 2 7 6 4 8 9 0 1 8 1 3 6 9 9 3 5 7 5 0 2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9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 
Number of Data Time Number of Comparisons Number of Swaps
20 0.3 s 92 92
20 0.5 s 92 92
20 0.3 s 92 92
50 0.4 s 511 511
50 0.5 s 511 511
50 0.5 s 511 511
100 0.5 s 1970 1970
100 0.3 s 2333 2333
100 0.5 s 2296 2296
500 0.8 s 53808 53808
500 0.6 s 56663 56663
500 0.8 s 54318 54318
1000 2.2 s 213082 213082
1000 1.6 s 219507 219507
1000 2.0 s 226161 226161
5000 9.5 s 5560675 5560675
5000 6.2 s 5616655 5616655
5000 11.9 s 5714100 5714100
/* Java program for Merge Sort */
class MergeSort {
    // Merges two subarrays of arr[].
    // First subarray is arr[l..m]
    // Second subarray is arr[m+1..r]

    public int count = 0;
    public int count2 = 0;

    void merge(int arr[], int l, int m, int r)
    {
        // Find sizes of two subarrays to be merged
        int n1 = m - l + 1;
        int n2 = r - m;
        
 
        /* Create temp arrays */
        int L[] = new int[n1];
        int R[] = new int[n2];
 
        /*Copy data to temp arrays*/
        for (int i = 0; i < n1; ++i)
            L[i] = arr[l + i];
        for (int j = 0; j < n2; ++j)
            R[j] = arr[m + 1 + j];
 
        /* Merge the temp arrays */
 
        // Initial indexes of first and second subarrays
        int i = 0, j = 0;
 
        // Initial index of merged subarray array
        int k = l;
        while (i < n1 && j < n2) {
            if (L[i] <= R[j]) {
                arr[k] = L[i];
                i++;
                count++;
                count2++;
            }
            else {
                arr[k] = R[j];
                j++;
                count++;
                count2++;
            }
            k++;
        }
 
        /* Copy remaining elements of L[] if any */
        while (i < n1) {
            arr[k] = L[i];
            i++;
            k++;
            count++;
        }
 
        /* Copy remaining elements of R[] if any */
        while (j < n2) {
            arr[k] = R[j];
            j++;
            k++;
            count++;
        }

    }
 
    // Main function that sorts arr[l..r] using
    // merge()
    void sort(int arr[], int l, int r)
    {
        if (l < r) {
            // Find the middle point
            int m = l + (r - l) / 2;
 
            // Sort first and second halves
            sort(arr, l, m);
            sort(arr, m + 1, r);
 
            // Merge the sorted halves
            merge(arr, l, m, r);
        }

        System.out.println("Number of Comparison " + count);
        System.out.println("Number of Swaps " + count2);

    }

    
 
    /* A utility function to print array of size n */
    static void printArray(int arr[])
    {
        int n = arr.length;
        for (int i = 0; i < n; ++i)
            System.out.print(arr[i] + " ");
        System.out.println();
    }
 
    // Driver code
    public static void main(String args[])
    {
 
        MergeSort ob = new MergeSort();
        Random rd = new Random(); // creating Random object
        int[] arr = new int[5000];
        for (int i = 0; i < arr.length; i++) {
            arr[i] = rd.nextInt(10);
        }
        ob.printArray(arr);
        ob.sort(arr, 0, arr.length - 1);
        System.out.println("Sorted array");
        ob.printArray(arr);
    }
}

MergeSort.main(null);
4 9 2 9 4 8 2 7 2 8 2 1 9 0 1 4 0 4 2 4 1 1 6 5 2 1 3 0 9 4 3 2 8 3 5 7 0 5 7 2 3 2 7 2 5 7 4 6 2 1 5 7 5 7 8 6 7 1 6 7 5 4 5 6 6 5 1 6 2 3 5 8 0 1 4 9 2 3 5 3 6 4 5 5 1 2 8 9 8 5 4 7 2 8 5 7 3 3 1 6 1 9 2 4 6 1 8 2 0 2 6 2 8 2 5 0 0 2 4 5 9 8 1 7 3 6 4 2 3 8 2 3 7 6 8 9 8 9 4 9 1 8 3 9 2 7 1 8 4 1 2 7 4 7 2 8 7 6 9 2 0 9 1 5 2 7 9 0 0 0 3 6 1 0 1 0 1 7 0 7 3 4 4 5 5 0 7 0 3 9 0 9 2 8 3 6 8 0 5 2 8 7 0 7 3 6 4 7 8 3 5 5 0 8 6 2 3 6 0 6 7 6 0 0 1 2 1 8 8 9 2 7 2 6 4 9 2 8 3 1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 0 4 4 1 7 9 2 9 9 5 7 3 4 5 9 2 3 0 0 7 4 9 7 5 1 6 8 8 4 7 3 0 0 7 0 1 7 2 9 1 8 7 9 8 6 3 5 7 5 8 1 5 6 6 7 6 9 0 7 1 2 8 9 7 6 4 4 8 1 7 2 0 7 3 1 6 7 0 5 1 2 2 2 0 6 3 9 0 9 5 9 0 3 3 0 5 3 5 1 8 8 8 3 0 6 8 4 8 3 8 7 2 1 5 5 8 6 9 1 2 6 0 6 6 0 4 5 7 4 7 2 7 2 0 5 4 1 9 1 2 6 6 8 6 7 5 5 1 0 8 1 9 6 2 9 9 4 4 6 2 1 9 4 0 7 1 6 5 2 4 1 2 7 6 1 2 5 5 4 6 0 4 8 7 3 9 8 5 1 6 7 7 2 8 2 7 6 0 1 2 7 5 1 2 8 1 6 3 1 6 9 1 2 2 2 5 6 2 4 4 1 4 6 8 2 0 1 4 6 3 8 2 2 3 4 6 4 7 5 9 1 4 8 4 9 4 2 6 6 2 1 4 1 8 5 0 6 5 4 3 1 0 5 9 0 2 2 8 3 6 0 0 3 0 2 1 1 4 9 7 5 0 4 4 4 8 4 6 2 8 3 8 9 0 2 8 6 8 8 2 5 8 5 6 0 5 6 2 0 5 7 1 6 2 0 6 0 6 9 8 5 0 8 6 8 9 1 8 4 1 4 5 3 9 6 6 9 2 7 6 3 5 2 6 8 7 0 6 9 9 2 1 3 0 8 9 9 9 3 0 4 6 3 3 2 6 9 7 9 5 0 1 2 8 6 1 3 4 5 6 4 3 9 2 0 9 
Number of Data Time Number of Comparisons Number of Swaps
20 0.3 s 88 63
20 0.3 s 88 61
20 0.3 s 88 60
50 0.3 s 286 223
50 0.3 s 286 219
50 0.3 s 286 216
100 0.8 s 672 542
100 0.3 s 672 528
100 0.4 s 672 536
500 1.7 s 4488 3770
500 2.2 s 4488 3770
500 3.5 s 4488 3786
1000 4.8 s 9976 8530
1000 4.5 s 9976 8528
1000 4.1 s 9976 8502
5000 7.9 s 5560675 5560675
5000 8.8 s 5616655 5616655
5000 6.6 s 5714100 5714100

Big O Noation:

  • used to analyze how efficient an algorithm is from the amount of time, storage, and other resources ittakes to run
  • it also takes into account a change in the input size
  • it tells us how well an algorithm will perform
  • how much time is takes to run is the time complexity
  • memory that is uses is the space complexity
  • running time does not directly equate to regular time
  • time is thought of as the number of operations or steps it takes to complete a problem of size n
  • big o tracks how quickly the runtime grows relative to the size of the input ### 0(1) -> Constant time
  • This means that it takes a constant time to run the algorithm regardless of the size input
  • some ex: math operations, accessing an array via the index, accessing a hash via the key, pushing and popping on a stack, insertion and removal from a queue ### O(n) -> Linear time
  • the run time increases at the same pace (linear) as the input
  • ex: like reading a book: if it takes 3 minutes to read 3 pages, then it should take 30 minutes to read 30 pages of a book that is the same print and size
  • code ex: traversing an array
  • loops are generally an indicator that the code has a runtime of O(n) ### O(n^2) -> Quadratic time
  • this means that the run time is in quadratic meaning that the squared sum of the input data is propotional to the time
  • ex: bubble sort, insertion sort, selection sort
  • seeing two neseted loops is generally a good indicator that the code has a runtime of O(n^2)
  • ex: n = 4, means that there will be 16 operations total ### O(log n) -> Logarithmic time
  • the running time grows in prportion to the logarithm of the input size
  • this means that the run time barely increases as you exponentially increase the input
  • ex: binary search, very little searching and the time gets cut in half each time ### O(nlog n) -> combination of linear and logarithmic
  • ex: merge sort, timsort, heapsort