Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Relational Database Technology

Authors: Suad Alagic

1st Edition

354096276X, 978-3540962762

More Books

Students also viewed these Databases questions

Question

preference for well defined job functions;

Answered: 1 week ago

Question

Question What are the requirements for a SIMPLE 401(k) plan?

Answered: 1 week ago