SlideShare a Scribd company logo
1 of 8
Download to read offline
please help finish sorting methods:
import java.util.Arrays;
import java.io.PrintWriter;
import java.io.File;
import java.util.Scanner;
public class SortTimes
{
/* convert nanos to seconds */
static final double ONE_BILLION = 1_000_000_000.;
/* sizes of input range should range up to 512k elements */
static int[] sizes = new int[32];
public static void main(String[] args) throws Exception
{
int sIdx = 0;
long startTime;
long endTime;
double time;
int size = 128*1024/sizes.length;
/* let's make size smaller, comment out this next line and see what happens */
size = 16*1024/sizes.length;
for( int i=0; i<sizes.length; i++ ) {
sizes[i] = (i+1)*size;
}
Scanner inp = new Scanner(System.in);
System.out.print("What is your last name? ");
String lastName = inp.next();
PrintWriter pw = new PrintWriter(new File(lastName + "_sortTimes.csv"));
pw.println( "Size, BubbleSort, MergeSort, QuickSort, JavaSort, BubbleSort (Sorted Array),
MergeSort (Sorted Array), QuickSort (Sorted Array), JavaSort (Sorted Array)" );
while( sIdx < sizes.length )
{
int[] A = new int[sizes[sIdx]];
int[] B = new int[sizes[sIdx]];
int[] C = new int[sizes[sIdx]];
int[] D = new int[sizes[sIdx]];
int[] E = new int[sizes[sIdx]];
for( int i=0; i<A.length; i++ )
{
A[i] = (int)(Math.random()*sizes[sIdx]*2);
B[i] = A[i];
C[i] = A[i];
D[i] = A[i];
E[i] = 1000; // Array E is used for testing algo on array that is already sorted.
}
System.out.println();
System.out.println("--------------------------------------------------");
System.out.println("Initial Values: ");
printArray(A);
pw.print(A.length + ", ");
System.out.println( "Starting bubble sort ---------------- Size = " + B.length);
startTime = System.nanoTime();
bubbleSort(A);
endTime = System.nanoTime();
time = (endTime - startTime) / ONE_BILLION;
System.out.println( "Bubble sort finished - time = " + time + " seconds" );
pw.print(time + ", ");
printArray(A);
System.out.println();
System.out.println( "Starting merge sort ---------------- Size = " + C.length);
startTime = System.nanoTime();
mergeSort(B);
endTime = System.nanoTime();
time = (endTime - startTime) / ONE_BILLION;
System.out.println( "Merge sort finished - time = " + time + " seconds.");
pw.print(time + ", ");
printArray(B);
System.out.println();
System.out.println( "Starting quick sort ---------------- Size = " + D.length);
startTime = System.nanoTime();
quickSort(C);
endTime = System.nanoTime();
time = (endTime - startTime) / ONE_BILLION;
System.out.println( "quickSort finished - time = " + time + " seconds." );
pw.print(time + ", ");
printArray(C);
System.out.println();
System.out.println( "Starting java's Array sort ---------------- Size = " + D.length);
startTime = System.nanoTime();
javaSort(D);
endTime = System.nanoTime();
time = (endTime - startTime) / ONE_BILLION;
System.out.println( "Java's Array sort finished - time = " + time + " seconds." );
pw.print(time + ", ");
printArray(D);
System.out.println();
System.out.println( "Starting bubble sort on sorted array ---------------- Size = " + B.length);
startTime = System.nanoTime();
bubbleSort(E);
endTime = System.nanoTime();
time = (endTime - startTime) / ONE_BILLION;
System.out.println( "Bubble sort finished - time = " + time + " seconds" );
pw.print(time + ", ");
printArray(E);
System.out.println();
System.out.println( "Starting merge sort on sorted array ---------------- Size = " + C.length);
startTime = System.nanoTime();
mergeSort(E);
endTime = System.nanoTime();
time = (endTime - startTime) / ONE_BILLION;
System.out.println( "Merge sort finished - time = " + time + " seconds.");
pw.print(time + ", ");
printArray(E);
System.out.println();
System.out.println( "Starting quick sort on sorted array ---------------- Size = " + D.length);
startTime = System.nanoTime();
quickSort(E);
endTime = System.nanoTime();
time = (endTime - startTime) / ONE_BILLION;
System.out.println( "quickSort finished - time = " + time + " seconds." );
pw.print(time + ", ");
printArray(E);
System.out.println();
System.out.println( "Starting java's Array sorted array ---------------- Size = " + D.length);
startTime = System.nanoTime();
javaSort(E);
endTime = System.nanoTime();
time = (endTime - startTime) / ONE_BILLION;
System.out.println( "Java's Array sort finished - time = " + time + " seconds." );
pw.println(time);
printArray(E);
System.out.println();
sIdx = sIdx + 1;
}
pw.close();
}
/* prints array or a portion of it if it's too large */
public static void printArray(int[] X)
{
if( X == null ) return;
System.out.print("[ ");
int i=0;
for( ; i<15 && i<X.length; i++ )
{
System.out.print( X[i] + " " );
}
if( i < X.length ) System.out.print("... ");
System.out.println("]");
}
/* Finish Methods Below*/
public static void bubbleSort(int[] X)
{
}
public static void mergeSort(int[] X)
{
}
private static void merge(int[] B, int[] C, int[] A )
{
}
/* this is simply the sort used by Arrays class */
public static void javaSort(int[] X)
{
}
public static void quickSort(int[] X)
{
quickSort(X, 0, X.length-1);
}
private static void quickSort(int[] X, int s, int e)
{
// check our stopping condition
// get pivot point from partition method
// call quickSort on left portion and quickSort on right portion
}
private static int partition( int[]X, int s, int e )
{
int pivotIdx=s;
return pivotIdx;
}
}

More Related Content

Similar to please help finish sorting methods- import java-util-Arrays- import ja.pdf

Lab01.pptx
Lab01.pptxLab01.pptx
Lab01.pptxKimVeeL
 
JAVA.Q4 Create a Time class. This class will represent a point in.pdf
JAVA.Q4 Create a Time class. This class will represent a point in.pdfJAVA.Q4 Create a Time class. This class will represent a point in.pdf
JAVA.Q4 Create a Time class. This class will represent a point in.pdfkarymadelaneyrenne19
 
FileName EX06_1java Programmer import ja.pdf
FileName EX06_1java Programmer  import ja.pdfFileName EX06_1java Programmer  import ja.pdf
FileName EX06_1java Programmer import ja.pdfactocomputer
 
I have written the code but cannot complete the assignment please help.pdf
I have written the code but cannot complete the assignment please help.pdfI have written the code but cannot complete the assignment please help.pdf
I have written the code but cannot complete the assignment please help.pdfshreeaadithyaacellso
 
Java programming lab manual
Java programming lab manualJava programming lab manual
Java programming lab manualsameer farooq
 
Assignment no39
Assignment no39Assignment no39
Assignment no39Jay Patel
 
Deep dumpster diving 2010
Deep dumpster diving 2010Deep dumpster diving 2010
Deep dumpster diving 2010RonnBlack
 
2 BytesC++ course_2014_c3_ function basics&parameters and overloading
2 BytesC++ course_2014_c3_ function basics&parameters and overloading2 BytesC++ course_2014_c3_ function basics&parameters and overloading
2 BytesC++ course_2014_c3_ function basics&parameters and overloadingkinan keshkeh
 
Java programs
Java programsJava programs
Java programsjojeph
 
Instruction1. Please read the two articles. (Kincheloe part 1 &.docx
Instruction1. Please read the two articles. (Kincheloe part 1 &.docxInstruction1. Please read the two articles. (Kincheloe part 1 &.docx
Instruction1. Please read the two articles. (Kincheloe part 1 &.docxcarliotwaycave
 
Java programs - bubble sort, iterator, linked list, hash set, reverse string,...
Java programs - bubble sort, iterator, linked list, hash set, reverse string,...Java programs - bubble sort, iterator, linked list, hash set, reverse string,...
Java programs - bubble sort, iterator, linked list, hash set, reverse string,...Sunil Kumar Gunasekaran
 
Quest 1 define a class batsman with the following specifications
Quest  1 define a class batsman with the following specificationsQuest  1 define a class batsman with the following specifications
Quest 1 define a class batsman with the following specificationsrajkumari873
 
JAVA PRACTICE QUESTIONS v1.4.pdf
JAVA PRACTICE QUESTIONS v1.4.pdfJAVA PRACTICE QUESTIONS v1.4.pdf
JAVA PRACTICE QUESTIONS v1.4.pdfRohitkumarYadav80
 
import java.uti-WPS Office.docx
import java.uti-WPS Office.docximport java.uti-WPS Office.docx
import java.uti-WPS Office.docxKatecate1
 
Java Foundations: Data Types and Type Conversion
Java Foundations: Data Types and Type ConversionJava Foundations: Data Types and Type Conversion
Java Foundations: Data Types and Type ConversionSvetlin Nakov
 
Advanced Java - Practical File
Advanced Java - Practical FileAdvanced Java - Practical File
Advanced Java - Practical FileFahad Shaikh
 

Similar to please help finish sorting methods- import java-util-Arrays- import ja.pdf (20)

Lab01.pptx
Lab01.pptxLab01.pptx
Lab01.pptx
 
JAVA.Q4 Create a Time class. This class will represent a point in.pdf
JAVA.Q4 Create a Time class. This class will represent a point in.pdfJAVA.Q4 Create a Time class. This class will represent a point in.pdf
JAVA.Q4 Create a Time class. This class will represent a point in.pdf
 
java-programming.pdf
java-programming.pdfjava-programming.pdf
java-programming.pdf
 
3.Lesson Plan - Input.pdf.pdf
3.Lesson Plan - Input.pdf.pdf3.Lesson Plan - Input.pdf.pdf
3.Lesson Plan - Input.pdf.pdf
 
FileName EX06_1java Programmer import ja.pdf
FileName EX06_1java Programmer  import ja.pdfFileName EX06_1java Programmer  import ja.pdf
FileName EX06_1java Programmer import ja.pdf
 
I have written the code but cannot complete the assignment please help.pdf
I have written the code but cannot complete the assignment please help.pdfI have written the code but cannot complete the assignment please help.pdf
I have written the code but cannot complete the assignment please help.pdf
 
Java file
Java fileJava file
Java file
 
Java file
Java fileJava file
Java file
 
Java programming lab manual
Java programming lab manualJava programming lab manual
Java programming lab manual
 
Assignment no39
Assignment no39Assignment no39
Assignment no39
 
Deep dumpster diving 2010
Deep dumpster diving 2010Deep dumpster diving 2010
Deep dumpster diving 2010
 
2 BytesC++ course_2014_c3_ function basics&parameters and overloading
2 BytesC++ course_2014_c3_ function basics&parameters and overloading2 BytesC++ course_2014_c3_ function basics&parameters and overloading
2 BytesC++ course_2014_c3_ function basics&parameters and overloading
 
Java programs
Java programsJava programs
Java programs
 
Instruction1. Please read the two articles. (Kincheloe part 1 &.docx
Instruction1. Please read the two articles. (Kincheloe part 1 &.docxInstruction1. Please read the two articles. (Kincheloe part 1 &.docx
Instruction1. Please read the two articles. (Kincheloe part 1 &.docx
 
Java programs - bubble sort, iterator, linked list, hash set, reverse string,...
Java programs - bubble sort, iterator, linked list, hash set, reverse string,...Java programs - bubble sort, iterator, linked list, hash set, reverse string,...
Java programs - bubble sort, iterator, linked list, hash set, reverse string,...
 
Quest 1 define a class batsman with the following specifications
Quest  1 define a class batsman with the following specificationsQuest  1 define a class batsman with the following specifications
Quest 1 define a class batsman with the following specifications
 
JAVA PRACTICE QUESTIONS v1.4.pdf
JAVA PRACTICE QUESTIONS v1.4.pdfJAVA PRACTICE QUESTIONS v1.4.pdf
JAVA PRACTICE QUESTIONS v1.4.pdf
 
import java.uti-WPS Office.docx
import java.uti-WPS Office.docximport java.uti-WPS Office.docx
import java.uti-WPS Office.docx
 
Java Foundations: Data Types and Type Conversion
Java Foundations: Data Types and Type ConversionJava Foundations: Data Types and Type Conversion
Java Foundations: Data Types and Type Conversion
 
Advanced Java - Practical File
Advanced Java - Practical FileAdvanced Java - Practical File
Advanced Java - Practical File
 

More from anfenterprises

Please help me figure out how to graph this- Eormulas- Solution- nput.pdf
Please help me figure out how to graph this- Eormulas- Solution- nput.pdfPlease help me figure out how to graph this- Eormulas- Solution- nput.pdf
Please help me figure out how to graph this- Eormulas- Solution- nput.pdfanfenterprises
 
PLease help KPIs and ROI are the same metric for social media marketin.pdf
PLease help KPIs and ROI are the same metric for social media marketin.pdfPLease help KPIs and ROI are the same metric for social media marketin.pdf
PLease help KPIs and ROI are the same metric for social media marketin.pdfanfenterprises
 
please help i will like please and thank you The term Osmosis is gen.pdf
please help i will like please and thank you   The term Osmosis is gen.pdfplease help i will like please and thank you   The term Osmosis is gen.pdf
please help i will like please and thank you The term Osmosis is gen.pdfanfenterprises
 
PLEASE HELP ASAP!! Quality Service Systems uses a perpetual inventory.pdf
PLEASE HELP ASAP!! Quality Service Systems uses a perpetual inventory.pdfPLEASE HELP ASAP!! Quality Service Systems uses a perpetual inventory.pdf
PLEASE HELP ASAP!! Quality Service Systems uses a perpetual inventory.pdfanfenterprises
 
Please help ASAP for an upvote With the help of diagrams- explain the.pdf
Please help ASAP for an upvote With the help of diagrams- explain the.pdfPlease help ASAP for an upvote With the help of diagrams- explain the.pdf
Please help ASAP for an upvote With the help of diagrams- explain the.pdfanfenterprises
 
Please help answer the problem in the screenshot- Thanks! 5- Support (1).pdf
Please help answer the problem in the screenshot- Thanks! 5-  Support (1).pdfPlease help answer the problem in the screenshot- Thanks! 5-  Support (1).pdf
Please help answer the problem in the screenshot- Thanks! 5- Support (1).pdfanfenterprises
 
Please help When preparing a smear from a solid culture of a suspecte.pdf
Please help  When preparing a smear from a solid culture of a suspecte.pdfPlease help  When preparing a smear from a solid culture of a suspecte.pdf
Please help When preparing a smear from a solid culture of a suspecte.pdfanfenterprises
 
Please help Required information -The following information applies t.pdf
Please help  Required information -The following information applies t.pdfPlease help  Required information -The following information applies t.pdf
Please help Required information -The following information applies t.pdfanfenterprises
 
please help 5- (2 points) On Figure 1 there are two profiles- which y.pdf
please help  5- (2 points) On Figure 1 there are two profiles- which y.pdfplease help  5- (2 points) On Figure 1 there are two profiles- which y.pdf
please help 5- (2 points) On Figure 1 there are two profiles- which y.pdfanfenterprises
 
please help 3 Identify- label- and color the following structures on.pdf
please help  3 Identify- label- and color the following structures on.pdfplease help  3 Identify- label- and color the following structures on.pdf
please help 3 Identify- label- and color the following structures on.pdfanfenterprises
 
Please help Draw a project network from the following information- W.pdf
Please help   Draw a project network from the following information- W.pdfPlease help   Draw a project network from the following information- W.pdf
Please help Draw a project network from the following information- W.pdfanfenterprises
 
Please help When staining endospores- the outer layers of the endos.pdf
Please help    When staining endospores- the outer layers of the endos.pdfPlease help    When staining endospores- the outer layers of the endos.pdf
Please help When staining endospores- the outer layers of the endos.pdfanfenterprises
 
please help To map 3 genes in E coli- interrupted mating experiment.pdf
please help    To map 3 genes in E coli- interrupted mating experiment.pdfplease help    To map 3 genes in E coli- interrupted mating experiment.pdf
please help To map 3 genes in E coli- interrupted mating experiment.pdfanfenterprises
 
please give the solution with detailed steps and explanation subject -.pdf
please give the solution with detailed steps and explanation subject -.pdfplease give the solution with detailed steps and explanation subject -.pdf
please give the solution with detailed steps and explanation subject -.pdfanfenterprises
 
Please go through the charts and identify the followings- Please go th.pdf
Please go through the charts and identify the followings- Please go th.pdfPlease go through the charts and identify the followings- Please go th.pdf
Please go through the charts and identify the followings- Please go th.pdfanfenterprises
 
Please give the definition of the following key terms- anesthesia.pdf
Please give the definition of the following key terms-     anesthesia.pdfPlease give the definition of the following key terms-     anesthesia.pdf
Please give the definition of the following key terms- anesthesia.pdfanfenterprises
 
Please give some response to question 4- 3- Explain why sun and shade.pdf
Please give some response to question 4- 3- Explain why sun and shade.pdfPlease give some response to question 4- 3- Explain why sun and shade.pdf
Please give some response to question 4- 3- Explain why sun and shade.pdfanfenterprises
 
Please fiview and the following statements and decide whether the stat.pdf
Please fiview and the following statements and decide whether the stat.pdfPlease fiview and the following statements and decide whether the stat.pdf
Please fiview and the following statements and decide whether the stat.pdfanfenterprises
 
Please fill out Homestead Crafts- a distributor of handmade gifts- op.pdf
Please fill out  Homestead Crafts- a distributor of handmade gifts- op.pdfPlease fill out  Homestead Crafts- a distributor of handmade gifts- op.pdf
Please fill out Homestead Crafts- a distributor of handmade gifts- op.pdfanfenterprises
 
please explain with every detail possible thank you! I will up vote- (4).pdf
please explain with every detail possible thank you! I will up vote- (4).pdfplease explain with every detail possible thank you! I will up vote- (4).pdf
please explain with every detail possible thank you! I will up vote- (4).pdfanfenterprises
 

More from anfenterprises (20)

Please help me figure out how to graph this- Eormulas- Solution- nput.pdf
Please help me figure out how to graph this- Eormulas- Solution- nput.pdfPlease help me figure out how to graph this- Eormulas- Solution- nput.pdf
Please help me figure out how to graph this- Eormulas- Solution- nput.pdf
 
PLease help KPIs and ROI are the same metric for social media marketin.pdf
PLease help KPIs and ROI are the same metric for social media marketin.pdfPLease help KPIs and ROI are the same metric for social media marketin.pdf
PLease help KPIs and ROI are the same metric for social media marketin.pdf
 
please help i will like please and thank you The term Osmosis is gen.pdf
please help i will like please and thank you   The term Osmosis is gen.pdfplease help i will like please and thank you   The term Osmosis is gen.pdf
please help i will like please and thank you The term Osmosis is gen.pdf
 
PLEASE HELP ASAP!! Quality Service Systems uses a perpetual inventory.pdf
PLEASE HELP ASAP!! Quality Service Systems uses a perpetual inventory.pdfPLEASE HELP ASAP!! Quality Service Systems uses a perpetual inventory.pdf
PLEASE HELP ASAP!! Quality Service Systems uses a perpetual inventory.pdf
 
Please help ASAP for an upvote With the help of diagrams- explain the.pdf
Please help ASAP for an upvote With the help of diagrams- explain the.pdfPlease help ASAP for an upvote With the help of diagrams- explain the.pdf
Please help ASAP for an upvote With the help of diagrams- explain the.pdf
 
Please help answer the problem in the screenshot- Thanks! 5- Support (1).pdf
Please help answer the problem in the screenshot- Thanks! 5-  Support (1).pdfPlease help answer the problem in the screenshot- Thanks! 5-  Support (1).pdf
Please help answer the problem in the screenshot- Thanks! 5- Support (1).pdf
 
Please help When preparing a smear from a solid culture of a suspecte.pdf
Please help  When preparing a smear from a solid culture of a suspecte.pdfPlease help  When preparing a smear from a solid culture of a suspecte.pdf
Please help When preparing a smear from a solid culture of a suspecte.pdf
 
Please help Required information -The following information applies t.pdf
Please help  Required information -The following information applies t.pdfPlease help  Required information -The following information applies t.pdf
Please help Required information -The following information applies t.pdf
 
please help 5- (2 points) On Figure 1 there are two profiles- which y.pdf
please help  5- (2 points) On Figure 1 there are two profiles- which y.pdfplease help  5- (2 points) On Figure 1 there are two profiles- which y.pdf
please help 5- (2 points) On Figure 1 there are two profiles- which y.pdf
 
please help 3 Identify- label- and color the following structures on.pdf
please help  3 Identify- label- and color the following structures on.pdfplease help  3 Identify- label- and color the following structures on.pdf
please help 3 Identify- label- and color the following structures on.pdf
 
Please help Draw a project network from the following information- W.pdf
Please help   Draw a project network from the following information- W.pdfPlease help   Draw a project network from the following information- W.pdf
Please help Draw a project network from the following information- W.pdf
 
Please help When staining endospores- the outer layers of the endos.pdf
Please help    When staining endospores- the outer layers of the endos.pdfPlease help    When staining endospores- the outer layers of the endos.pdf
Please help When staining endospores- the outer layers of the endos.pdf
 
please help To map 3 genes in E coli- interrupted mating experiment.pdf
please help    To map 3 genes in E coli- interrupted mating experiment.pdfplease help    To map 3 genes in E coli- interrupted mating experiment.pdf
please help To map 3 genes in E coli- interrupted mating experiment.pdf
 
please give the solution with detailed steps and explanation subject -.pdf
please give the solution with detailed steps and explanation subject -.pdfplease give the solution with detailed steps and explanation subject -.pdf
please give the solution with detailed steps and explanation subject -.pdf
 
Please go through the charts and identify the followings- Please go th.pdf
Please go through the charts and identify the followings- Please go th.pdfPlease go through the charts and identify the followings- Please go th.pdf
Please go through the charts and identify the followings- Please go th.pdf
 
Please give the definition of the following key terms- anesthesia.pdf
Please give the definition of the following key terms-     anesthesia.pdfPlease give the definition of the following key terms-     anesthesia.pdf
Please give the definition of the following key terms- anesthesia.pdf
 
Please give some response to question 4- 3- Explain why sun and shade.pdf
Please give some response to question 4- 3- Explain why sun and shade.pdfPlease give some response to question 4- 3- Explain why sun and shade.pdf
Please give some response to question 4- 3- Explain why sun and shade.pdf
 
Please fiview and the following statements and decide whether the stat.pdf
Please fiview and the following statements and decide whether the stat.pdfPlease fiview and the following statements and decide whether the stat.pdf
Please fiview and the following statements and decide whether the stat.pdf
 
Please fill out Homestead Crafts- a distributor of handmade gifts- op.pdf
Please fill out  Homestead Crafts- a distributor of handmade gifts- op.pdfPlease fill out  Homestead Crafts- a distributor of handmade gifts- op.pdf
Please fill out Homestead Crafts- a distributor of handmade gifts- op.pdf
 
please explain with every detail possible thank you! I will up vote- (4).pdf
please explain with every detail possible thank you! I will up vote- (4).pdfplease explain with every detail possible thank you! I will up vote- (4).pdf
please explain with every detail possible thank you! I will up vote- (4).pdf
 

Recently uploaded

mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...RKavithamani
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppCeline George
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 

Recently uploaded (20)

mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website App
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 

please help finish sorting methods- import java-util-Arrays- import ja.pdf

  • 1. please help finish sorting methods: import java.util.Arrays; import java.io.PrintWriter; import java.io.File; import java.util.Scanner; public class SortTimes { /* convert nanos to seconds */ static final double ONE_BILLION = 1_000_000_000.; /* sizes of input range should range up to 512k elements */ static int[] sizes = new int[32]; public static void main(String[] args) throws Exception { int sIdx = 0; long startTime; long endTime; double time; int size = 128*1024/sizes.length; /* let's make size smaller, comment out this next line and see what happens */ size = 16*1024/sizes.length; for( int i=0; i<sizes.length; i++ ) { sizes[i] = (i+1)*size; }
  • 2. Scanner inp = new Scanner(System.in); System.out.print("What is your last name? "); String lastName = inp.next(); PrintWriter pw = new PrintWriter(new File(lastName + "_sortTimes.csv")); pw.println( "Size, BubbleSort, MergeSort, QuickSort, JavaSort, BubbleSort (Sorted Array), MergeSort (Sorted Array), QuickSort (Sorted Array), JavaSort (Sorted Array)" ); while( sIdx < sizes.length ) { int[] A = new int[sizes[sIdx]]; int[] B = new int[sizes[sIdx]]; int[] C = new int[sizes[sIdx]]; int[] D = new int[sizes[sIdx]]; int[] E = new int[sizes[sIdx]]; for( int i=0; i<A.length; i++ ) { A[i] = (int)(Math.random()*sizes[sIdx]*2); B[i] = A[i]; C[i] = A[i]; D[i] = A[i]; E[i] = 1000; // Array E is used for testing algo on array that is already sorted. } System.out.println(); System.out.println("--------------------------------------------------"); System.out.println("Initial Values: ");
  • 3. printArray(A); pw.print(A.length + ", "); System.out.println( "Starting bubble sort ---------------- Size = " + B.length); startTime = System.nanoTime(); bubbleSort(A); endTime = System.nanoTime(); time = (endTime - startTime) / ONE_BILLION; System.out.println( "Bubble sort finished - time = " + time + " seconds" ); pw.print(time + ", "); printArray(A); System.out.println(); System.out.println( "Starting merge sort ---------------- Size = " + C.length); startTime = System.nanoTime(); mergeSort(B); endTime = System.nanoTime(); time = (endTime - startTime) / ONE_BILLION; System.out.println( "Merge sort finished - time = " + time + " seconds."); pw.print(time + ", "); printArray(B); System.out.println(); System.out.println( "Starting quick sort ---------------- Size = " + D.length); startTime = System.nanoTime(); quickSort(C);
  • 4. endTime = System.nanoTime(); time = (endTime - startTime) / ONE_BILLION; System.out.println( "quickSort finished - time = " + time + " seconds." ); pw.print(time + ", "); printArray(C); System.out.println(); System.out.println( "Starting java's Array sort ---------------- Size = " + D.length); startTime = System.nanoTime(); javaSort(D); endTime = System.nanoTime(); time = (endTime - startTime) / ONE_BILLION; System.out.println( "Java's Array sort finished - time = " + time + " seconds." ); pw.print(time + ", "); printArray(D); System.out.println(); System.out.println( "Starting bubble sort on sorted array ---------------- Size = " + B.length); startTime = System.nanoTime(); bubbleSort(E); endTime = System.nanoTime(); time = (endTime - startTime) / ONE_BILLION; System.out.println( "Bubble sort finished - time = " + time + " seconds" ); pw.print(time + ", "); printArray(E);
  • 5. System.out.println(); System.out.println( "Starting merge sort on sorted array ---------------- Size = " + C.length); startTime = System.nanoTime(); mergeSort(E); endTime = System.nanoTime(); time = (endTime - startTime) / ONE_BILLION; System.out.println( "Merge sort finished - time = " + time + " seconds."); pw.print(time + ", "); printArray(E); System.out.println(); System.out.println( "Starting quick sort on sorted array ---------------- Size = " + D.length); startTime = System.nanoTime(); quickSort(E); endTime = System.nanoTime(); time = (endTime - startTime) / ONE_BILLION; System.out.println( "quickSort finished - time = " + time + " seconds." ); pw.print(time + ", "); printArray(E); System.out.println(); System.out.println( "Starting java's Array sorted array ---------------- Size = " + D.length); startTime = System.nanoTime(); javaSort(E); endTime = System.nanoTime();
  • 6. time = (endTime - startTime) / ONE_BILLION; System.out.println( "Java's Array sort finished - time = " + time + " seconds." ); pw.println(time); printArray(E); System.out.println(); sIdx = sIdx + 1; } pw.close(); } /* prints array or a portion of it if it's too large */ public static void printArray(int[] X) { if( X == null ) return; System.out.print("[ "); int i=0; for( ; i<15 && i<X.length; i++ ) { System.out.print( X[i] + " " ); } if( i < X.length ) System.out.print("... "); System.out.println("]"); } /* Finish Methods Below*/
  • 7. public static void bubbleSort(int[] X) { } public static void mergeSort(int[] X) { } private static void merge(int[] B, int[] C, int[] A ) { } /* this is simply the sort used by Arrays class */ public static void javaSort(int[] X) { } public static void quickSort(int[] X) { quickSort(X, 0, X.length-1); } private static void quickSort(int[] X, int s, int e) { // check our stopping condition // get pivot point from partition method // call quickSort on left portion and quickSort on right portion }
  • 8. private static int partition( int[]X, int s, int e ) { int pivotIdx=s; return pivotIdx; } }