Question: Use the following heapsort code to find the time complexity (big O notation). heapSort is the primary method, and calls the other methods void heapSort(Element[]

Use the following heapsort code to find the time complexity (big O notation). heapSort is the primary method, and calls the other methods

void heapSort(Element[] E, int n){

int heapsize;

for(heapSize = n; heapSize >= 2; heapsize--){

Element curMax = E[1];

Element K = E[heapsize];

fixHeap(E, heapsize-1, 1, K);

E[heapsize] = curMax;

return;

}

void fixHeap(Element[] E, int heapSize, int root, Element K)

int left = 2*root, right = 2*root+1;

if(left > heapSize)

E[root] = K; // root is a leaf

else

// determine largerSubHeap

int largerSubHeap;

if(left == heapSize)

largerSubHeap = left; // no right SubHeap

else if(E[left].key > E[right].key)

largerSubHeap = left;

else

largerSubHeap = right;

// decide whether to filter K down

if(K.key >= E[largerSubHeap].key)

E[root] = K;

else

E[root] = E[largerSubHeap];

fixHeap(E, heapSize, largerSubHeap, K);

return;

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!