Question: What is the big-O of the function: template void heapsort(vector as shown in Figure 7.10. Justify and explain how you arrived at your answer. 2

What is the big-O of the function: template void heapsort(vector as shownWhat is the big-O of the function: template void heapsort(vector as shown in Figure 7.10. Justify and explain how you arrived at your answer.

2 3 *Standard heapsort template void heapsort ( vector & a ) 5 6 for ( int i a.size( ) / 2-1; i >= 0; --i ) /* buildHea p */ percDown a, i, a.size() ):; 8 9 10 for int j-a.size( 1; j>0; j std:: swap a 0], a j]; percDown a, 0, j ); /*deleteMax * 12 13 15 16 17 18 19 20 21 *Internal method for heapsort. *i is the index of an item in the heap. *Returns the index of theleft child. inline int leftChild( int i) 23 24 25 26 /** 27 28 29 30 31 32 return 2*i+ 1; *Internal method for heapsort that is used in deleteMax and bui 1 dHeap *i is the position from which to percolate down *n is the 1ogical size of the binary heap templ ate & a, int i, int n ) 34 35 36 37 38 39 40 int child; Comparable tmp; for( tmp std: :move ( a[ i ] ) ; leftChild( i ) n; i = child ) chi ld = 1 eftChi ld ( i ) ; if( child != n - 1 && a[ child ] a[ child + 1 ] ) ++child; a i 1std: move( a child ]; break i f ( tmpa child ]) 42 43 else 45 46 47 48 a[ i ] = std:move ( tmp ); Figure 7.10 Heapsort

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!