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

Read the following Selection Sort function and determine the correct answer for

ID: 3900634 • Letter: R

Question

Read the following Selection Sort function and determine the correct answer for blank #2.

           

                        template<class ItemType>

                        int MinIndex(ItemType values[], int startIndex, int endIndex)

                        // Post: Returns the index of the smallest value in

                        //       values[startIndex]..values[endIndex].

                        {

                           int indexOfMin = __________;                                                  // 1

                           for (int index = startIndex + 1; index <= endIndex; index++)

                                if (values[index] < ________________)                                            // 2

                                   indexOfMin = index;

                           return indexOfMin;

                        }

           

                        template<class ItemType>

                        void SelectionSort(ItemType values[], int numValues)

                        // Post: The elements in the array values are sorted by key.

                        {

                           int endIndex = ____________;                                                             // 3

                           for (int current = 0; current < endIndex; ___________)               // 4

                                Swap(values[current],

                                   values[MinIndex(values, current, __________)]);               // 5

           

                        }

A) values[indexOfMin]

B) indexOfMin

C) values[startIndex]

Explanation / Answer

From the question

Selection Sort function and determine the correct answer for blank #2.

for (int index = startIndex + 1; index <= endIndex; index++)

if (values[index] < ________________)                                            // 2

Answer:

                                if (values[index] < values[indexOfMin])

In this the current element is compared values[indexOfMin])

values[indexOfMin]) is the starting element.

indexOfMin is starting position of values array

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Chat Now And Get Quote