Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Please help with this Java question! _____________________________________ package algorithm; import databases.ConnectToSqlDB; import java.util.List; import java.util.Random; public class Numbers { /* * Show all the different
Please help with this Java question!
_____________________________________
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, Oracle 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"); Listnumbers = 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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started