SlideShare a Scribd company logo
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.pptx
KimVeeL
 
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
karymadelaneyrenne19
 
java-programming.pdf
java-programming.pdfjava-programming.pdf
java-programming.pdf
Prof. Dr. K. Adisesha
 
3.Lesson Plan - Input.pdf.pdf
3.Lesson Plan - Input.pdf.pdf3.Lesson Plan - Input.pdf.pdf
3.Lesson Plan - Input.pdf.pdf
AbhishekSingh757567
 
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
actocomputer
 
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
shreeaadithyaacellso
 
Java file
Java fileJava file
Java file
simarsimmygrewal
 
Java programming lab manual
Java programming lab manualJava programming lab manual
Java programming lab manual
sameer 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 overloading
kinan 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 &.docx
carliotwaycave
 
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 specifications
rajkumari873
 
JAVA PRACTICE QUESTIONS v1.4.pdf
JAVA PRACTICE QUESTIONS v1.4.pdfJAVA PRACTICE QUESTIONS v1.4.pdf
JAVA PRACTICE QUESTIONS v1.4.pdf
RohitkumarYadav80
 
import java.uti-WPS Office.docx
import java.uti-WPS Office.docximport java.uti-WPS Office.docx
import java.uti-WPS Office.docx
Katecate1
 
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
Svetlin Nakov
 
Advanced Java - Practical File
Advanced Java - Practical FileAdvanced Java - Practical File
Advanced Java - Practical File
Fahad 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.pdf
anfenterprises
 
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
anfenterprises
 
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
anfenterprises
 
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
anfenterprises
 
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
anfenterprises
 
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
anfenterprises
 
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
anfenterprises
 
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
anfenterprises
 
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
anfenterprises
 
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
anfenterprises
 
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
anfenterprises
 
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
anfenterprises
 
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
anfenterprises
 
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
anfenterprises
 
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
anfenterprises
 
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
anfenterprises
 
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
anfenterprises
 
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
anfenterprises
 
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
anfenterprises
 
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
anfenterprises
 

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

Digital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion DesignsDigital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion Designs
chanes7
 
Normal Labour/ Stages of Labour/ Mechanism of Labour
Normal Labour/ Stages of Labour/ Mechanism of LabourNormal Labour/ Stages of Labour/ Mechanism of Labour
Normal Labour/ Stages of Labour/ Mechanism of Labour
Wasim Ak
 
S1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptxS1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptx
tarandeep35
 
Azure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHatAzure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHat
Scholarhat
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
Delapenabediema
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
DhatriParmar
 
Best Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDABest Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDA
deeptiverma2406
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
Peter Windle
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
Vikramjit Singh
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
Balvir Singh
 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Atul Kumar Singh
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
EverAndrsGuerraGuerr
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
Celine George
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
EugeneSaldivar
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
Pavel ( NSTU)
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
SACHIN R KONDAGURI
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
camakaiclarkmusic
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
Levi Shapiro
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
Celine George
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
TechSoup
 

Recently uploaded (20)

Digital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion DesignsDigital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion Designs
 
Normal Labour/ Stages of Labour/ Mechanism of Labour
Normal Labour/ Stages of Labour/ Mechanism of LabourNormal Labour/ Stages of Labour/ Mechanism of Labour
Normal Labour/ Stages of Labour/ Mechanism of Labour
 
S1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptxS1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptx
 
Azure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHatAzure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHat
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
 
Best Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDABest Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDA
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
 

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; } }