Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Urgent Question: Please help to explain this coding, and more on n,k, and arrs. What is the purpose of k ? What is the difference
Urgent Question: Please help to explain this coding, and more on n,k, and arrs. What is the purpose of k ? What is the difference between n and arrs? package test; import java.text.NumberFormat; import java.util.Random; import java.util.Arrays; import java.util.Locale; - @author Hyoungjin Choi public class Test \{ - @param args the command line arguments 1 public static void main(String[] args) \{ int arrs =1000; //k=10 tests(10, 20, arrs); tests (10,100, arrs ) tests(10, 1000 , arrs); tests(10, 10000 , arrs); //k=20 tests (20,20, arrs); tests (20,100, arrs ) tests(1000, 10000 , arrs); //k=2,000 tests(2000, 20, arrs); tests ( 2000,100 , arrs); tests(2000, 1000 , arrs); tests(2000, 10000, arrs); //k=5,000 tests(5000, 20, arrs); tests(5000, 100, arrs); tests(5000, 1000, arrs); tests(5000, 10000, arrs); //k=10,000 tests(10000, 20, arrs); tests( 10000,100 , arrs); tests (10000,1000, arrs); tests(10000, 10000 , arrs); /=100,000 tests(100000, 20, arrs); tests(100000, 100, arrs); tests( 100000,1000 , arrs); tests( 100000,10000 , arrs); tests(100000, 100000, arrs); \} / *@param k "Switch" for Insertion sort to kick in - @param n Size of the array - @param arrs Number of arrays to randomly generate */ public static void tests(int k, int n, int arrs) \{ long begin, end; long t1=0,t2=0; Random rand = new Random(); for (int i=0;ia[1]){ swap (a,0,1); 3 else\{ swap (a,1,0); \} 3 hybridQuickSort (a,0, a.length 1,k); 3 / - @param a Sample integer array - @param p Lower bound index - @param r Upper bound index - @param k "Switch" to for Insertion sort to kick in@ a size less than or - equal to k +/ private void hybridQuicksort(int[] as, int ps, int rs int k ) \{ while (pk){ int q= partition (a,p,r); // tail recursion to cut down on time if (qpp&.&a[j1]> currentElement ){ a[j]=a[j1]; j; \} a[j]= currentElement; \} ? / - @param a int array sample - @param p Lower bound - @param r Upper bound * @return Pivot index for quicksort 1 private int partition(int[] a, int p, int r ) \{ // Picking pivot using median of three int pivot = medianOfThree (a,p,r); int i=p1 for (int j=p;ja[ middle ]){ swap(a, left, middle); 3 if (a[left] >a[ right ]){ swap(a, left, right); ? if [a[ middle ]>a[ right ]){ swap (a, middle, right ); 3 swap(a, middle, right); return a[right]; \} \}
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