SlideShare a Scribd company logo
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 Python
Sumit 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.pdf
karymadelaneyrenne19
 
Deep dumpster diving 2010
Deep dumpster diving 2010Deep dumpster diving 2010
Deep dumpster diving 2010RonnBlack
 
Java programs
Java programsJava programs
Java programsjojeph
 
Java file
Java fileJava file
Java file
simarsimmygrewal
 
java-programming.pdf
java-programming.pdfjava-programming.pdf
java-programming.pdf
Prof. Dr. K. Adisesha
 
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
 
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 overloading
kinan keshkeh
 
3.Lesson Plan - Input.pdf.pdf
3.Lesson Plan - Input.pdf.pdf3.Lesson Plan - Input.pdf.pdf
3.Lesson Plan - Input.pdf.pdf
AbhishekSingh757567
 
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 programming lab manual
Java programming lab manualJava programming lab manual
Java programming lab manual
sameer 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 &.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
 
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 .pdf
marketing413921
 
import java.uti-WPS Office.docx
import java.uti-WPS Office.docximport java.uti-WPS Office.docx
import java.uti-WPS Office.docx
Katecate1
 
Timers in Unix/Linux
Timers in Unix/LinuxTimers in Unix/Linux
Timers in Unix/Linuxgeeksrik
 
Play image
Play imagePlay image
Play image
Fardian Syah
 

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.pdf
adhityalapcare
 
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
adhityalapcare
 
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
adhityalapcare
 
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
adhityalapcare
 
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
adhityalapcare
 
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
adhityalapcare
 
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
adhityalapcare
 
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
adhityalapcare
 
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
adhityalapcare
 
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
adhityalapcare
 
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
adhityalapcare
 
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
adhityalapcare
 
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
adhityalapcare
 
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
adhityalapcare
 
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
adhityalapcare
 
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
adhityalapcare
 
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
adhityalapcare
 
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
adhityalapcare
 
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
adhityalapcare
 
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
adhityalapcare
 

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

The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
Vivekanand Anglo Vedic Academy
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
Tamralipta Mahavidyalaya
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
heathfieldcps1
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
vaibhavrinwa19
 
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
 
678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf
CarlosHernanMontoyab2
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
MysoreMuleSoftMeetup
 
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
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
Nguyen Thanh Tu Collection
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
Jisc
 
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
 
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdfAdversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Po-Chuan Chen
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
Jean Carlos Nunes Paixão
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
DeeptiGupta154
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
Delapenabediema
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
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
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
Peter Windle
 
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
 
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
 

Recently uploaded (20)

The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
 
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...
 
678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
 
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
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
 
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
 
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdfAdversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
 
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
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
 
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
 

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 )