Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

read the following function or algorithm and determine the correct answer for al

ID: 3716976 • Letter: R

Question

read the following function or algorithm and determine the correct answer for all the blanks number are as commented

template class Item Type> void BubbleUp(ltem Type values[, int startlndex, int endindex) Il Post Adjacent pairs that are out of order have been switched ll between values startindex].values endindex] beginning at Il valuesfendindex] index > startindex index-)/1 1 values index-1]) //2 for (int index if (values[indexj Swap(valueslindex] values index-1) template class Item lypes void BubbleSort(ltem Type valuesl int numValues) l Post The elements in the array values are sorted by key int current 113 while (current s numValues - 1) BubbleUp(values, current, current+t

Explanation / Answer

For Image 1 (Bubble Sort):

//In BubbleUp Method

Comment 1: endIndex // We have to traversal from endIndex to startIndex

Comment 2: < //Compare current index to previous index values to swap.

//In BubbleSort Method

Comment 3: 0 //Initialize current with 0 as starting index for the array

Comment 4: numValues - 1 //Find bubble till the last index

For Image 2 (Selection Sort):

//In MinIndex Method

Comment 1: startIndex //Initialize with startIndex, consider as it has minimum value

Comment 2: values[indexOfMin] //Compare current index to minimum index values to find index of minimum value

//In SelectionSort Method

Comment 3: numValues - 1 //Initialize with endIndex to iterate all elements of array

Comment 4: current++ //Increase current by one

Comment 5: endIndex //Find MinIndex from current to endIndex

For Image 3(Heap Sort):

//In HeapSort Method

Comment 1: numValues / 2 -1 //Initialization

Comment 2: min_heap //call Min_heap method to make the minimum heap

Comment 3: values[0] //Swap the first element with index element

Comment 4: min_heap //Again call Min_heap method

Here is Min_heap method:

template<class ItemType>

void min_heap(ItemType values[], int rootElement, int bottomElement)

{

int max;

int right;

int left;

left = rootElement * 2 + 1;

right = rootElement * 2 + 2;

if(left <= bottomElement)

{

if(left == bottomElement)

{

max = left

}

else

{

if(values[left] <= values[right])

{

max = right;

}

else

{

max = left;

}

}

if(values[root] < values[max])

{

//Swap method called for swaping values

Swap(values[root], values[max]);

min_heap(values, max, bottomElement)

}

}

}