SlideShare a Scribd company logo
1 of 8
Download to read offline
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 import java-util-Arrays- import java-io-PrintWriter- import java-io-Fi.pdf

Hands on Session on Python
Hands on Session on PythonHands on Session on Python
Hands on Session on PythonSumit Raj
 
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
 
Deep dumpster diving 2010
Deep dumpster diving 2010Deep dumpster diving 2010
Deep dumpster diving 2010RonnBlack
 
Java programs
Java programsJava programs
Java programsjojeph
 
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
 
Assignment no39
Assignment no39Assignment no39
Assignment no39Jay Patel
 
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
 
3.Lesson Plan - Input.pdf.pdf
3.Lesson Plan - Input.pdf.pdf3.Lesson Plan - Input.pdf.pdf
3.Lesson Plan - Input.pdf.pdfAbhishekSingh757567
 
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
 
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
 
VTU Design and Analysis of Algorithms(DAA) Lab Manual by Nithin, VVCE, Mysuru...
VTU Design and Analysis of Algorithms(DAA) Lab Manual by Nithin, VVCE, Mysuru...VTU Design and Analysis of Algorithms(DAA) Lab Manual by Nithin, VVCE, Mysuru...
VTU Design and Analysis of Algorithms(DAA) Lab Manual by Nithin, VVCE, Mysuru...Nithin Kumar,VVCE, Mysuru
 
Military time and Standard time, JavaOne of the assignments given .pdf
Military time and Standard time, JavaOne of the assignments given .pdfMilitary time and Standard time, JavaOne of the assignments given .pdf
Military time and Standard time, JavaOne of the assignments given .pdfmarketing413921
 
import java.uti-WPS Office.docx
import java.uti-WPS Office.docximport java.uti-WPS Office.docx
import java.uti-WPS Office.docxKatecate1
 
Timers in Unix/Linux
Timers in Unix/LinuxTimers in Unix/Linux
Timers in Unix/Linuxgeeksrik
 

Similar to import java-util-Arrays- import java-io-PrintWriter- import java-io-Fi.pdf (20)

Hands on Session on Python
Hands on Session on PythonHands on Session on Python
Hands on Session on Python
 
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
 
Deep dumpster diving 2010
Deep dumpster diving 2010Deep dumpster diving 2010
Deep dumpster diving 2010
 
Java programs
Java programsJava programs
Java programs
 
Java file
Java fileJava file
Java file
 
Java file
Java fileJava file
Java file
 
java-programming.pdf
java-programming.pdfjava-programming.pdf
java-programming.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
 
Assignment no39
Assignment no39Assignment no39
Assignment no39
 
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
 
3.Lesson Plan - Input.pdf.pdf
3.Lesson Plan - Input.pdf.pdf3.Lesson Plan - Input.pdf.pdf
3.Lesson Plan - Input.pdf.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 programming lab manual
Java programming lab manualJava programming lab manual
Java programming lab manual
 
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,...
 
VTU Design and Analysis of Algorithms(DAA) Lab Manual by Nithin, VVCE, Mysuru...
VTU Design and Analysis of Algorithms(DAA) Lab Manual by Nithin, VVCE, Mysuru...VTU Design and Analysis of Algorithms(DAA) Lab Manual by Nithin, VVCE, Mysuru...
VTU Design and Analysis of Algorithms(DAA) Lab Manual by Nithin, VVCE, Mysuru...
 
Military time and Standard time, JavaOne of the assignments given .pdf
Military time and Standard time, JavaOne of the assignments given .pdfMilitary time and Standard time, JavaOne of the assignments given .pdf
Military time and Standard time, JavaOne of the assignments given .pdf
 
import java.uti-WPS Office.docx
import java.uti-WPS Office.docximport java.uti-WPS Office.docx
import java.uti-WPS Office.docx
 
Timers in Unix/Linux
Timers in Unix/LinuxTimers in Unix/Linux
Timers in Unix/Linux
 
Play image
Play imagePlay image
Play image
 

More from adhityalapcare

In 2022- Lisa and Fred- a married couple- had taxable income of $305-4.pdf
In 2022- Lisa and Fred- a married couple- had taxable income of $305-4.pdfIn 2022- Lisa and Fred- a married couple- had taxable income of $305-4.pdf
In 2022- Lisa and Fred- a married couple- had taxable income of $305-4.pdfadhityalapcare
 
In 2021- Montana Corp- entered into a contract to begin work on a two-.pdf
In 2021- Montana Corp- entered into a contract to begin work on a two-.pdfIn 2021- Montana Corp- entered into a contract to begin work on a two-.pdf
In 2021- Montana Corp- entered into a contract to begin work on a two-.pdfadhityalapcare
 
In 2022 - Laureen is currently single- She paid $2-800 of qualified tu.pdf
In 2022 - Laureen is currently single- She paid $2-800 of qualified tu.pdfIn 2022 - Laureen is currently single- She paid $2-800 of qualified tu.pdf
In 2022 - Laureen is currently single- She paid $2-800 of qualified tu.pdfadhityalapcare
 
In 2020- Rocket inc- had reported a deferred tax asset of $106 million.pdf
In 2020- Rocket inc- had reported a deferred tax asset of $106 million.pdfIn 2020- Rocket inc- had reported a deferred tax asset of $106 million.pdf
In 2020- Rocket inc- had reported a deferred tax asset of $106 million.pdfadhityalapcare
 
implementation of virtual care Detailed Communication plan is compile.pdf
implementation of virtual care  Detailed Communication plan is compile.pdfimplementation of virtual care  Detailed Communication plan is compile.pdf
implementation of virtual care Detailed Communication plan is compile.pdfadhityalapcare
 
In 2019 there were $3-4 trillion in mergers and acquisitions worldwide.pdf
In 2019 there were $3-4 trillion in mergers and acquisitions worldwide.pdfIn 2019 there were $3-4 trillion in mergers and acquisitions worldwide.pdf
In 2019 there were $3-4 trillion in mergers and acquisitions worldwide.pdfadhityalapcare
 
implement trylexcept excepsion handler to catch all errors drom the fo.pdf
implement trylexcept excepsion handler to catch all errors drom the fo.pdfimplement trylexcept excepsion handler to catch all errors drom the fo.pdf
implement trylexcept excepsion handler to catch all errors drom the fo.pdfadhityalapcare
 
In 2012- Northland had real GDP of $4-21 billion and a population of 2.pdf
In 2012- Northland had real GDP of $4-21 billion and a population of 2.pdfIn 2012- Northland had real GDP of $4-21 billion and a population of 2.pdf
In 2012- Northland had real GDP of $4-21 billion and a population of 2.pdfadhityalapcare
 
In 2015 - the Hawai'i State Legislature passed a bill that sets a goal.pdf
In 2015 - the Hawai'i State Legislature passed a bill that sets a goal.pdfIn 2015 - the Hawai'i State Legislature passed a bill that sets a goal.pdf
In 2015 - the Hawai'i State Legislature passed a bill that sets a goal.pdfadhityalapcare
 
In 2015- Los Angeles sued Wells Fargo for unethical customer conduct-.pdf
In 2015- Los Angeles sued Wells Fargo for unethical customer conduct-.pdfIn 2015- Los Angeles sued Wells Fargo for unethical customer conduct-.pdf
In 2015- Los Angeles sued Wells Fargo for unethical customer conduct-.pdfadhityalapcare
 
In 2001- the federal government enacted a law that forbade any student.pdf
In 2001- the federal government enacted a law that forbade any student.pdfIn 2001- the federal government enacted a law that forbade any student.pdf
In 2001- the federal government enacted a law that forbade any student.pdfadhityalapcare
 
In 2000 - the CPI was 152-5- and the price of an economics textbook wa.pdf
In 2000 - the CPI was 152-5- and the price of an economics textbook wa.pdfIn 2000 - the CPI was 152-5- and the price of an economics textbook wa.pdf
In 2000 - the CPI was 152-5- and the price of an economics textbook wa.pdfadhityalapcare
 
In 1994- 52- of parents with children in high school felt that it was.pdf
In 1994- 52- of parents with children in high school felt that it was.pdfIn 1994- 52- of parents with children in high school felt that it was.pdf
In 1994- 52- of parents with children in high school felt that it was.pdfadhityalapcare
 
In 1626- Dutchman Peter Minuit purchased Manhattan Island from a local.pdf
In 1626- Dutchman Peter Minuit purchased Manhattan Island from a local.pdfIn 1626- Dutchman Peter Minuit purchased Manhattan Island from a local.pdf
In 1626- Dutchman Peter Minuit purchased Manhattan Island from a local.pdfadhityalapcare
 
In 1945- the United Nation was formed to replace _____- Responses- NAT.pdf
In 1945- the United Nation was formed to replace _____- Responses- NAT.pdfIn 1945- the United Nation was formed to replace _____- Responses- NAT.pdf
In 1945- the United Nation was formed to replace _____- Responses- NAT.pdfadhityalapcare
 
imported a data file with 7 variables how can i take two variables cal.pdf
imported a data file with 7 variables how can i take two variables cal.pdfimported a data file with 7 variables how can i take two variables cal.pdf
imported a data file with 7 variables how can i take two variables cal.pdfadhityalapcare
 
Imagine that you are an environmental scientist who has been hired to.pdf
Imagine that you are an environmental scientist who has been hired to.pdfImagine that you are an environmental scientist who has been hired to.pdf
Imagine that you are an environmental scientist who has been hired to.pdfadhityalapcare
 
ILLUSTRATION 21 P Company Pro Forma Balance Sheet Giving Effect to Pro.pdf
ILLUSTRATION 21 P Company Pro Forma Balance Sheet Giving Effect to Pro.pdfILLUSTRATION 21 P Company Pro Forma Balance Sheet Giving Effect to Pro.pdf
ILLUSTRATION 21 P Company Pro Forma Balance Sheet Giving Effect to Pro.pdfadhityalapcare
 
Ifyou have an embryo composed of multiple layers of cells- You examine.pdf
Ifyou have an embryo composed of multiple layers of cells- You examine.pdfIfyou have an embryo composed of multiple layers of cells- You examine.pdf
Ifyou have an embryo composed of multiple layers of cells- You examine.pdfadhityalapcare
 
If you have the following resources- a- Programmer analyst b- Software.pdf
If you have the following resources- a- Programmer analyst b- Software.pdfIf you have the following resources- a- Programmer analyst b- Software.pdf
If you have the following resources- a- Programmer analyst b- Software.pdfadhityalapcare
 

More from adhityalapcare (20)

In 2022- Lisa and Fred- a married couple- had taxable income of $305-4.pdf
In 2022- Lisa and Fred- a married couple- had taxable income of $305-4.pdfIn 2022- Lisa and Fred- a married couple- had taxable income of $305-4.pdf
In 2022- Lisa and Fred- a married couple- had taxable income of $305-4.pdf
 
In 2021- Montana Corp- entered into a contract to begin work on a two-.pdf
In 2021- Montana Corp- entered into a contract to begin work on a two-.pdfIn 2021- Montana Corp- entered into a contract to begin work on a two-.pdf
In 2021- Montana Corp- entered into a contract to begin work on a two-.pdf
 
In 2022 - Laureen is currently single- She paid $2-800 of qualified tu.pdf
In 2022 - Laureen is currently single- She paid $2-800 of qualified tu.pdfIn 2022 - Laureen is currently single- She paid $2-800 of qualified tu.pdf
In 2022 - Laureen is currently single- She paid $2-800 of qualified tu.pdf
 
In 2020- Rocket inc- had reported a deferred tax asset of $106 million.pdf
In 2020- Rocket inc- had reported a deferred tax asset of $106 million.pdfIn 2020- Rocket inc- had reported a deferred tax asset of $106 million.pdf
In 2020- Rocket inc- had reported a deferred tax asset of $106 million.pdf
 
implementation of virtual care Detailed Communication plan is compile.pdf
implementation of virtual care  Detailed Communication plan is compile.pdfimplementation of virtual care  Detailed Communication plan is compile.pdf
implementation of virtual care Detailed Communication plan is compile.pdf
 
In 2019 there were $3-4 trillion in mergers and acquisitions worldwide.pdf
In 2019 there were $3-4 trillion in mergers and acquisitions worldwide.pdfIn 2019 there were $3-4 trillion in mergers and acquisitions worldwide.pdf
In 2019 there were $3-4 trillion in mergers and acquisitions worldwide.pdf
 
implement trylexcept excepsion handler to catch all errors drom the fo.pdf
implement trylexcept excepsion handler to catch all errors drom the fo.pdfimplement trylexcept excepsion handler to catch all errors drom the fo.pdf
implement trylexcept excepsion handler to catch all errors drom the fo.pdf
 
In 2012- Northland had real GDP of $4-21 billion and a population of 2.pdf
In 2012- Northland had real GDP of $4-21 billion and a population of 2.pdfIn 2012- Northland had real GDP of $4-21 billion and a population of 2.pdf
In 2012- Northland had real GDP of $4-21 billion and a population of 2.pdf
 
In 2015 - the Hawai'i State Legislature passed a bill that sets a goal.pdf
In 2015 - the Hawai'i State Legislature passed a bill that sets a goal.pdfIn 2015 - the Hawai'i State Legislature passed a bill that sets a goal.pdf
In 2015 - the Hawai'i State Legislature passed a bill that sets a goal.pdf
 
In 2015- Los Angeles sued Wells Fargo for unethical customer conduct-.pdf
In 2015- Los Angeles sued Wells Fargo for unethical customer conduct-.pdfIn 2015- Los Angeles sued Wells Fargo for unethical customer conduct-.pdf
In 2015- Los Angeles sued Wells Fargo for unethical customer conduct-.pdf
 
In 2001- the federal government enacted a law that forbade any student.pdf
In 2001- the federal government enacted a law that forbade any student.pdfIn 2001- the federal government enacted a law that forbade any student.pdf
In 2001- the federal government enacted a law that forbade any student.pdf
 
In 2000 - the CPI was 152-5- and the price of an economics textbook wa.pdf
In 2000 - the CPI was 152-5- and the price of an economics textbook wa.pdfIn 2000 - the CPI was 152-5- and the price of an economics textbook wa.pdf
In 2000 - the CPI was 152-5- and the price of an economics textbook wa.pdf
 
In 1994- 52- of parents with children in high school felt that it was.pdf
In 1994- 52- of parents with children in high school felt that it was.pdfIn 1994- 52- of parents with children in high school felt that it was.pdf
In 1994- 52- of parents with children in high school felt that it was.pdf
 
In 1626- Dutchman Peter Minuit purchased Manhattan Island from a local.pdf
In 1626- Dutchman Peter Minuit purchased Manhattan Island from a local.pdfIn 1626- Dutchman Peter Minuit purchased Manhattan Island from a local.pdf
In 1626- Dutchman Peter Minuit purchased Manhattan Island from a local.pdf
 
In 1945- the United Nation was formed to replace _____- Responses- NAT.pdf
In 1945- the United Nation was formed to replace _____- Responses- NAT.pdfIn 1945- the United Nation was formed to replace _____- Responses- NAT.pdf
In 1945- the United Nation was formed to replace _____- Responses- NAT.pdf
 
imported a data file with 7 variables how can i take two variables cal.pdf
imported a data file with 7 variables how can i take two variables cal.pdfimported a data file with 7 variables how can i take two variables cal.pdf
imported a data file with 7 variables how can i take two variables cal.pdf
 
Imagine that you are an environmental scientist who has been hired to.pdf
Imagine that you are an environmental scientist who has been hired to.pdfImagine that you are an environmental scientist who has been hired to.pdf
Imagine that you are an environmental scientist who has been hired to.pdf
 
ILLUSTRATION 21 P Company Pro Forma Balance Sheet Giving Effect to Pro.pdf
ILLUSTRATION 21 P Company Pro Forma Balance Sheet Giving Effect to Pro.pdfILLUSTRATION 21 P Company Pro Forma Balance Sheet Giving Effect to Pro.pdf
ILLUSTRATION 21 P Company Pro Forma Balance Sheet Giving Effect to Pro.pdf
 
Ifyou have an embryo composed of multiple layers of cells- You examine.pdf
Ifyou have an embryo composed of multiple layers of cells- You examine.pdfIfyou have an embryo composed of multiple layers of cells- You examine.pdf
Ifyou have an embryo composed of multiple layers of cells- You examine.pdf
 
If you have the following resources- a- Programmer analyst b- Software.pdf
If you have the following resources- a- Programmer analyst b- Software.pdfIf you have the following resources- a- Programmer analyst b- Software.pdf
If you have the following resources- a- Programmer analyst b- Software.pdf
 

Recently uploaded

Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfchloefrazer622
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...Sapna Thakur
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...Pooja Nehwal
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpinRaunakKeshri1
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajanpragatimahajan3
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
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
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...anjaliyadav012327
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Disha Kariya
 
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
 

Recently uploaded (20)

Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdf
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajan
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
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
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
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
 

import java-util-Arrays- import java-io-PrintWriter- import java-io-Fi.pdf

  • 1. 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);
  • 2. 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);
  • 3. 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();
  • 4. 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();
  • 5. 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;
  • 6. 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)
  • 7. { } 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 )