Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

Recommended Textbook for

Database Reliability Engineering Designing And Operating Resilient Database Systems

Authors: Laine Campbell, Charity Majors

1st Edition

978-1491925942

More Books

Students also viewed these Databases questions

Question

Who or what is affected by this situation?

Answered: 1 week ago

Question

How important is this situation to the organizations mission?

Answered: 1 week ago