The largestPosition method below returns the index of the largest element in the tail range of an array of integers. Select the expression that would be needed to complete the selectionSort method below, so that it sorts the elements in descending order. /**
Finds the largest element in the tail range of an array.
@param a the array to be searched
@param from the first position in a to compare
@return the position of the largest element in range a[from]..a[a.length - 1]
*/
Private static int largestPosition(int[] a, int from)
{
Int maxPos = from;
For (int j = from + 1; j < a.length; j++)
{
If (a[j] > a[maxPos])
{
MaxPos = j;
}
}
Return maxPos;
}
Public static void selectionSort(int[]A) (int i = 0; i < a.length - 1; i++)
A) {
For ____________________________________
{
Int maxPos = largestPosition(a, i) ;
ArrayUtil.swap(a, maxPos, i) ;
}
}
B) (int i = 0; i < a.length; i++)
C) (int i = a.length; i > 0; i--)
D) (int i = a.length - 1; i > 0; i--)
Correct Answer:
Verified
Q6: Suppose an array has n elements. We
Q7: Consider the swap method shown below from
Q8: In big-Oh notation, suppose an algorithm requires
Q9: After 9 iterations of selection sort working
Q10: After one iteration of selection sort working
Q12: Consider the minimumPosition method from the SelectionSorter
Q13: After 5 iterations of selection sort working
Q14: The performance of an algorithm is most
Q15: Suppose you wanted to test your sort
Q16: What type of algorithm places elements in
Unlock this Answer For Free Now!
View this answer and more for free by performing one of the following actions
Scan the QR code to install the App and get 2 free unlocks
Unlock quizzes for free by uploading documents