Question: Write a class, MaxHeap, to implement a max-heap of values of type double. (You can either use an ArrayList to represent the heap, or use

Write a class, MaxHeap, to implement a max-heap of values of type double. (You can either use an ArrayList to represent the heap, or use an array and be prepared to grow the array. The array implementation will probably be more efficient. (Maybe you should try both!)) Next, write three sorting methods: One should use the heapsort algorithm as covered in class. A second should sort the array by inserting all the elements from the array into a heap defined by your MaxHeap class, and then removing all the items from the heap and putting them back into the array in order. Finally, the third sorting method should be an optimized version of quicksort that is as efficient as you can make it. You will probably want to use randomized quicksort. You might want to switch to insertion sort on very small subarrays. You might even consider using a stack instead of recursion. Finally, you should write a main program that does timing experiments on your three sorting methods plus the built-in sorting method, Arrays.sort(A). It is probably best to apply all four algorithms to identical arrays. Remember that you can easily make a copy of an array, A, by calling A.clone(). Use arrays filled with random numbers. You will need to use fairly large arrays to get useful time measurements. Use System.nanoTime() to do the time measurements. Consider turing off the Java just-in-time compiler to get more accurate comparisons. To do that, run the program with the javac option -Xint.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!