This is Heap class: package sorting; import java.util.Arrays; public class Heap {               private int[] data;     private int heapSize;          public Heap(int[] data,int heapSize) {         this.data = data;         this.heapSize = heapSize;     }          public void setHeapSize(int i) {         heapSize = i;     }          public int getHeapSize() {         return heapSize;     }          //return the parent of ith element in the array.     //should return -1 if the ith element is the root of the heap     public int parent(int i) {         if(i==0)             return -1;         else             return (i-1)/2;              }          //returns the index of the left child of the ith element in the array     //for leaves the index will be greater than the heapSize     public int left(int i) {         return (2*i)+1;              }          //returns the index of the right child of the ith element in the array     //for leaves the index will be greater than the heapSize     public int right(int i) {         return (2*i) + 2;              }          //modifies the data array so that the tree rooted at the loc element     //is a max heap.     //Assumes that the trees rooted at the left and right children of loc     //are max heaps     public void maxHeapify(int loc) {         int l = left(loc);         int r = right(loc);         int largest;         if(ldata[loc])             largest = l;         else             largest = loc;         if(rdata[largest])             largest = r;         if(largest != loc) {             swap(loc,largest);             maxHeapify(largest);         }                      }          private void swap(int i, int j) {         int temp = data[i];         data[i] = data[j];         data[j] = temp;     }          //converts the data array to an array that represents a max heap     public void buildMaxHeap() {         int n = heapSize;         for(int i=(n/2)-1;i>=0;i--) {             maxHeapify(i);         }     } } Please  Implement the heapSort using above Heap class: public static void heapSort(int[] arr){ } Implement the heapSort algorithm  using the MaxHeap data structure provided for you Heap.java.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

This is Heap class:

package sorting;

import java.util.Arrays;

public class Heap {
    
    
    private int[] data;
    private int heapSize;
    
    public Heap(int[] data,int heapSize) {
        this.data = data;
        this.heapSize = heapSize;
    }
    
    public void setHeapSize(int i) {
        heapSize = i;
    }
    
    public int getHeapSize() {
        return heapSize;
    }
    
    //return the parent of ith element in the array.
    //should return -1 if the ith element is the root of the heap
    public int parent(int i) {
        if(i==0)
            return -1;
        else
            return (i-1)/2;
        
    }
    
    //returns the index of the left child of the ith element in the array
    //for leaves the index will be greater than the heapSize
    public int left(int i) {
        return (2*i)+1;
        
    }
    
    //returns the index of the right child of the ith element in the array
    //for leaves the index will be greater than the heapSize
    public int right(int i) {
        return (2*i) + 2;
        
    }
    
    //modifies the data array so that the tree rooted at the loc element
    //is a max heap.
    //Assumes that the trees rooted at the left and right children of loc
    //are max heaps
    public void maxHeapify(int loc) {
        int l = left(loc);
        int r = right(loc);
        int largest;
        if(l<heapSize && data[l]>data[loc])
            largest = l;
        else
            largest = loc;
        if(r<heapSize && data[r]>data[largest])
            largest = r;
        if(largest != loc) {
            swap(loc,largest);
            maxHeapify(largest);
        }
                
    }
    
    private void swap(int i, int j) {
        int temp = data[i];
        data[i] = data[j];
        data[j] = temp;
    }
    
    //converts the data array to an array that represents a max heap
    public void buildMaxHeap() {
        int n = heapSize;
        for(int i=(n/2)-1;i>=0;i--) {
            maxHeapify(i);
        }
    }

}

Please  Implement the heapSort using above Heap class:

public static void heapSort(int[] arr){

}
Implement the heapSort algorithm  using the
MaxHeap data structure provided for you Heap.java. 


       

Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Stack
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education