Question: //Java package algorithm; import databases.ConnectToSqlDB; import java.util.List; import java.util.Random; public class Numbers { /* * Show all the different kind of sorting algorithm by applying
//Java
package algorithm; import databases.ConnectToSqlDB; import java.util.List; import java.util.Random; public class Numbers { /* * Show all the different kind of sorting algorithm by applying into (num array). * Display the execution time for each sorting.Example in below. * * Use any databases[MongoDB or MySql] to store data and retrieve data. * * At the end. After running all the sorting algo, come to a conclusion which one is suitable on given data set. * */ public static void main(String[] args) throws Exception { int [] num = new int[1000000]; storeRandomNumbers(num); ConnectToSqlDB connectToSqlDB = new ConnectToSqlDB(); //Selection Sort Sort algo = new Sort(); algo.selectionSort(num); long selectionSortExecutionTime = algo.executionTime; System.out.println("Total Execution Time of "+ num.length + " numbers in Selection Sort take: " + selectionSortExecutionTime + " milli sec"); connectToSqlDB.insertDataFromArrayToSqlTable(num, "selection_sort", "SortingNumbers"); List numbers = connectToSqlDB.readDataBase("selection_sort", "SortingNumbers"); printValue(numbers); int n = num.length; randomize (num, n); //Insertion Sort algo.insertionSort(num); long insertionSortExecutionTime = algo.executionTime; System.out.println("Total Execution Time of " + num.length + " numbers in Insertion Sort take: " + insertionSortExecutionTime + " milli sec"); //By following above, Continue for rest of the Sorting Algorithm.... //Come to conclusion about which Sorting Algo is better in given data set. } public static void storeRandomNumbers(int [] num){ Random rand = new Random(); for(int i=0; i 0 for (int i = n-1; i > 0; i--) { int j = r.nextInt(i); int temp = arr[i]; arr[i] = arr[j]; arr[j] = temp; } } public static void printValue(List array){ for(String st:array){ System.out.println(st); } } } Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
