Question: Implement the algorithm and analyze the results using the give input files Prepare your results to use in your report next week. Objectives: Implement
Implement the algorithm and analyze the results using the give input files Prepare your results to use in your report next week. Objectives: Implement heap sort using a max-heap Problems 1. Implement a method to sort a given array using the heap sort algorithm. You can use the algorithm from the textbook (see page 2). 2. Write a driver program to test the heap sort algorithm for the arrays of varying lengths provided in Canvas. HEAPSORT (4) 1 BUILD-MAX-HEAP (4) 2 for i = A.length downto 2 exchange A[1] with A[i] 3 4 5 A.heap-size= A.heap-size - 1 MAX-HEAPIFY (4,1) BUILD-MAX-HEAP (A) 1 A.heap-size = A.length 2 for i LA.length/2] downto 1 3 MAX-HEAPIFY (A.() MAX-HEAPIFY (4,1) 1 /= LEFT (i) 2 7 = RIGHT(1) 3 if A.heap-size and A[!] > A[i] largest = 1 4 else largest i ifr A.heap-size and A[r]> A[largest 5 6 7 8 9 10 largest = r i if largest exchange A[i] with A[largest] MAX-HEAPIFY (A, largest)
Step by Step Solution
There are 3 Steps involved in it
public class HeapSort public static void heapSortint arr int n arrlength Build a maxheap buildMaxHea... View full answer
Get step-by-step solutions from verified subject matter experts
