Write a code to implement the heap sort algorithm in JAVA or Python. Test your program with different sets of data and take screenshots. Copy and paste your code and screenshots into a Word document....

1 answer below »



Write a code to implement the heap sort algorithm in JAVA or Python. Test your program with different sets of data and take screenshots. Copy and paste your code and screenshots into a Word document. Perform an asymptotic analysis of your algorithm. Using the same word document respond to the following:















    • Find the best case, worst case, and average case in time and space complexity.








    • How do your findings compare with the quicksort and mergesort best, worst, and average case evaluated in the Written Assignment for this Unit?








Answered Same DayDec 05, 2022

Answer To: Write a code to implement the heap sort algorithm in JAVA or Python. Test your program with...

Vikas answered on Dec 05 2022
41 Votes
Assignment
import java.util.*;
import java.io.*;
public class Main
{
    public static void main(S
tring[] args) throws IOException{
        int[] arr = {8,2,5,3,0,1,19,21,17,84};
        heapSort(arr);
    }
    
    static void heapify(int[] arr, int n, int i) {
int largest = i;
int left = 2 * i + 1;
int right = 2*i+2;
if (left < n && arr[left] > arr[largest])
largest = left;
if (right < n && arr[right] > arr[largest])
largest = right;
if (largest != i) {
int tmp = arr[i];
arr[i] = arr[largest];
arr[largest] = tmp;
...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here