Great Deal! Get Instant $10 FREE in Account on First Order + 10% Cashback on Every Order Order Now

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 Day Dec 05, 2022

Solution

Vikas answered on Dec 05 2022
53 Votes
Assignment
import java.util.*;
import java.io.*;
public class Main
{
    public static void main(String[] args) throws IOException{
        int[] a
= {8,2,5,3,0,1,19,21,17,84};
        heapSort(a
);
    }
    
    static void heapify(int[] a
, int n, int i) {
int largest = i;
int left = 2 * i + 1;
int right = 2*i+2;
if (left < n && a
[left] > a
[largest])
largest = left;
if (right < n && a
[right] > a
[largest])
largest = right;
if (largest != i) {
int tmp = a
[i];
a
[i] = a
[largest];
a
[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