Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please Help with this JAVA program In this programming project you will practice the implementation of sorting algorithms. Download the attached base le for a

Please Help with this JAVA program

In this programming project you will practice the implementation of sorting algorithms. Download the attached base le for a starting place; it includes some very simple testing code. You may modify the base le. However, please retain the signatures of the two stub methods and make sure you keep all of your code in the le. Also attached is Sorting.java, which includes the textbook's sorting algorithm implementations for reference.

***: Modify the quick sort method to choose the partition element using the middle- of-three technique described in the chapter. The central idea of middle-of-three is to pick three elements from the array, and then select the middle value of them. This increases the chance that the partition element will divide the array in half, maximizing performance.

**Reimplement the mergesort algorithm to pass only arrays as parameters. This must include a helper method, public static void mergesort(Comparable[] a), a recursive method, public static Comparable[] mergesortRec(Comparable[] a), and a merge method, public static Comparable[] merge(Comparable[] a, Comparable[] b). Do not use global variables, instead create new arrays as data is divided and merged. (This approach is slower than the mergesort from the book. The goal is to better understand the mergesort concept.)

Lastly, write appropriate testing documentation - see next section. [10 points]

PLEASE FIND base.java below

/** * Implements various sorting algorithms. * * @author (your name), Acuna, Sedgewick * @verison (version) */ public class BaseSorting { /** * Entry point for sample output. * * @param args the command line arguments */ public static void main(String[] args) { //Q1 String[] a = {"S", "O", "R", "T", "E", "X", "A", "M", "P", "L", "E"}; quicksortmid(a); assert isSorted(a); //requires assertions enabled. show(a); //Q2 String[] b = {"S", "O", "R", "T", "E", "X", "A", "M", "P", "L", "E"}; mergesort(b); assert isSorted(b); show(b); } public static void quicksortmid(Comparable[] a) { //TODO: implement this. } public static void mergesort(Comparable[] a) { //TODO: implement this. } /** * Displays contents of array, space separated. * @author Sedgewick * @param a Array to display. */ private static void show(Comparable[] a) { for (Comparable a1 : a) System.out.print(a1 + " "); System.out.println(); } /** * Checks if array is in sorted order. * @author Sedgewick * @param a Array to be checked. * @return Returns true if array is sorted. */ public static boolean isSorted(Comparable[] a) { for (int i = 1; i < a.length; i++) if (less(a[i], a[i-1])) return false; return true; } //See previous method. private static boolean less(Comparable v, Comparable w) { return v.compareTo(w) < 0; } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

2. Carry out the customers wishes:

Answered: 1 week ago

Question

Q.1. Taxonomic classification of peafowl, Tiger and cow ?

Answered: 1 week ago

Question

Q .1. Different ways of testing the present adulterants ?

Answered: 1 week ago