Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Use Java to complete program: Create three functions named build MaxHeap(a), max heapify(aj), heap sort(a) 1. Request the user to enter a positive integer, and

image text in transcribed

Use Java to complete program: Create three functions named build MaxHeap(a), max heapify(aj), heap sort(a) 1. Request the user to enter a positive integer, and call it n 2. Generate n random integers between -10000 to 10000 and save them in array a. 3. Call heap_sort(a) function to sort the array. In order to sort the array using heapsort, you need to follow the below steps: 3.1 Build a max-heap (call the function build_heap(a)). In order to build the max-heap follow the below pseudocode: % new-a is the output of the function, if you are using any other programming language, please write % return new a at the end of your code. a - build MaxHeap(a) n -length(a); for i-n:-1:1 % i-n down to 1, can we start from n/2 instead of n? Why? a = max.heapify(a.i); end 3.2 Remove the root (remove the first element in a) 4. Determine the average-running time of heap_sort function for n-10000, and 100 repetitions. 5. Compare your answer with the average-running time of quicksort and selection sort (you need implement it)

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

Modern Database Management

Authors: Jeff Hoffer, Ramesh Venkataraman, Heikki Topi

13th Edition Global Edition

1292263350, 978-1292263359

More Books

Students also viewed these Databases questions