Question: The java code for SortingMain.java and DrawingPanel.java is here : https://drive.google.com/open?id=0BxOSocfKKTXOcGxzdHhoYjIxRnc The instructor asks to code with InsertionSort, SelectionSort, heapSort or mergeSort to make the
The java code for SortingMain.java and DrawingPanel.java is here: https://drive.google.com/open?id=0BxOSocfKKTXOcGxzdHhoYjIxRnc
The instructor asks to code with InsertionSort, SelectionSort, heapSort or mergeSort to make the program run. Would you be able to provide the code for those 4. Thanks in advance
Programming Overview:
Your task is to sort 3D points according to their z coordinate to be displayed to the user. Points with a smaller z coordinate will appear on top of points with similar x and y coordinates but greater z coordinates. To accomplish this, you will implement four different sorting methods along with a Point3D object class to represent your 3D points. The four sorting algorithms that you will be implementing are: insertion sort, selection sort, heap sort, and merge sort. For your heap sort, you should be creating a heap-like structure in your method to use for your heap. You should implement your heap sort in-place. You may write and use your own helper methods if you wish. I strongly suggest using a few for some of these sorts.
Before you start implementing your sorting algorithms, you will need to write you Point3D object first. Your Point3D object must implement the Comparable interface so that we can compare our Point3D objects to each other. You must include the following methods in your Point3D class (you may have more, but must have at least these):
public Point3D()
Creates a default 3D points with all coordinates set to 0
public Point3D(int x, int y, int z)
Creates a 3D point with the given coordinates
public int getX()
Returns the x coordinate for the 3D point
public int getY()
Returns the y coordinate for the 3D point
public int getZ()
Returns the z coordinate for the 3D point
public int compareTo(Point3D other)
Compares our point object with the other given point object. Returns a negative value if our point is less than the other, a positive value if our point is greater than the other, or 0 if our point is equal to the other. Since we will be looking at the z values to display the points, you should first consider z values, followed by x, and finally y. For example, if I have a point (3, 2, 1) and another point (1, 2, 3), the first point should be seen as less than the second point.
public String toString()
Returns a String representation of the point in the format of (x, y, z)
Provided Files:
DrawingPanel.java
This file provides the graphical interface to display the points. You do not need to change anything in the code for this file. You arent required to understand how the DrawingPanel works. This is simply a file that you need in order to get the graphical output.
SortingMain.java
This is the starter code that you will finish implementing. SortingMain.java handles the setup and graphics to display the points. It is your task to implement several sorting algorithms inside this class to sort your Point3D objects so that they are properly displayed on the DrawingPanel. The method headers for your methods are provided. You should fill in the methods (creating private helper methods as needed) and comment on all of your methods that you implement. You can then change the sorting algorithm used in drawPoints to see if yours is working properly.
Write-Up Questions:
1.What are the runtimes for each of the algorithms you implemented (big-oh will suffice)? Provide a brief description as to why they are the runtime you provided.
2.Using Quick Sort, with the median pivot rule (pick the median of: data[lo], data[hi 1], and data[(hi + lo) / 2]), sort the following list of numbers. Show your work by drawing the tree of partitions and pivots (as seen on the slides) with the partition rules discussed in class (swapping the pivot to index lo and doing swaps to complete the partitions). Apply a cutoff of 3 elements and sort with any sorting method.
data = [5, 7, 9, 1, 3, 4, 6, 8, 2]
3. Using Radix Sort with a radix of 6 (letters: a, b, c, d, e, and f) to alphabetically sort the following Strings, draw the contents of each bucket at the end of each radix digit iteration pass.
Strings = (abc, da, ffff, defcd, abebd, ca, b, fef, dfe)
What to turn in:
SortingMain.java with the sorting methods fully implemented
Point3D.java entirely written by you as defined above
Electronic version of your write-up
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
