Computers and Technology, 19.03.2021 22:20 23lopezjimenezl
In the QuickSort algorithm, the partition method we developed in class chose the start position for the pivot. We saw that this leads to worst case performance, O(n2), when the list is initially sorted. Try to improve your QuickSort by choosing the value at the middle, instead of the value at the start, for the pivot. Test your solution with the Driver you used for homework. Upload the output produced by the Driver, and your modified QuickSort source file.
ORIGINAL
public class QuickSort> implements Sorter
{
List list;
public void sort(List list)
{
this. list = list;
qSort(0, list. size() -1);
}
public void qSort(int start, int end)
{
if(start >= end)
return;
int p = partition(start, end);
qSort(start, p-1);
qSort(p+1,end);
}
public int partition(int start, int end)
{
int p = start;
E pivot = list. get(p);
for(int i = start+1; i <= end; i++)
if(pivot. compareTo(list. get(i)) > 0)
{
list. set(p, list. get(i));
p++;
list. set(i, list. get(p));
}
list. set(p, pivot);
return p;
}
}
Driver
public class DriverQuicksort
{ static final int MAX = 20;
public static void main(String[] args)
{
Random rand = new Random(); // random number generator
List numbers = new ArrayList ();
Sorter sorter;
sorter = new QuickSort ();
// Test QuickSort with random input
System. out. println ("Testing Quicksort");
for (int i=0; i
numbers. add (rand. nextInt(50)); // random int in [0..49]
System. out. println ("Before sorting:");
System. out. println (numbers);
sorter. sort (numbers );
System. out. println ("After sorting:");
System. out. println (numbers);
System. out. println ();
// Test QuickSort with ascending input
numbers. clear();
for (int i=0; i
numbers. add (i * 10); // initially in ascending order
System. out. println ("Before sorting:");
System. out. println (numbers);
sorter. sort ( numbers);
System. out. println ("After sorting:");
System. out. println (numbers);
System. out. println ();
// Test QuickSort with descendng input
numbers. clear();
for (int i=0; i
numbers. add (MAX-i); // initially in ascending order
System. out. println ("Before sorting:");
System. out. println (numbers);
sorter. sort ( numbers);
System. out. println ("After sorting:");
System. out. println (numbers);
System. out. println ();
numbers. clear();
numbers. add(75);
numbers. add(93);
numbers. add(35);
numbers. add(0);
numbers. add(75);
numbers. add(-2);
numbers. add(93);
numbers. add(4);
numbers. add(6);
numbers. add(76);
System. out. println ("Before sorting:");
System. out. println (numbers);
sorter. sort(numbers);
System. out. println ("After sorting:");
System. out. println (numbers);
System. out. println ();
}
}
Answers: 1
Computers and Technology, 22.06.2019 22:40
Write a program that defines symbolic names for several string literals (chars between quotes). * use each symbolic name in a variable definition. * use of symbolic to compose the assembly code instruction set can perform vara = (vara - varb) + (varc - vard); ensure that variable is in unsigned integer data type. * you should also further enhance your symbolic logic block to to perform expression by introducing addition substitution rule. vara = (vara+varb) - (varc+vard). required: debug the disassembly code and note down the address and memory information.
Answers: 3
Computers and Technology, 23.06.2019 06:40
How many nibbles can be stored in a 16-bit word?
Answers: 1
Computers and Technology, 24.06.2019 11:20
William travels a lot on business purpose. he needs to regularly communicate with his business partner. he also needs to send out weekly reports to his boss while he is traveling. which web-based application best suits william’s needs? (social media, webmail, wiki) is the best web-based application for william. he can access this application via the internet using a (digital cable, fax machine, web browser).
Answers: 1
Computers and Technology, 24.06.2019 12:30
Why does the pc send out a broadcast arp prior to sending the first ping request
Answers: 1
In the QuickSort algorithm, the partition method we developed in class chose the start position for...
Mathematics, 20.10.2020 07:01
Health, 20.10.2020 07:01
Mathematics, 20.10.2020 07:01
Physics, 20.10.2020 07:01
History, 20.10.2020 07:01
Biology, 20.10.2020 07:01
Spanish, 20.10.2020 07:01
History, 20.10.2020 07:01
Mathematics, 20.10.2020 07:01
English, 20.10.2020 07:01
Chemistry, 20.10.2020 07:01
Chemistry, 20.10.2020 07:01
Mathematics, 20.10.2020 07:01