Looking for Programming Homework Help?

In each iteration, selection sort places which element in the correct location?

Free

Multiple Choice

Answer:

Answer:

B

After 5 iterations of selection sort working on an array of 10 elements, what must hold true?

Free

Multiple Choice

Answer:

Answer:

B

After one iteration of selection sort working on an array of 10 elements, what must hold true?

Multiple Choice

Answer:

Consider the sort method shown below for selection sort: public static void sort(int[]
A) {
For (int i = 0; i < a.length - 1; i++)
{
Int minPos = minimumPosition(i);
Swap(minPos, i);
}
}
Suppose we modify the loop condition to read i < a.length. What would be the result?

Multiple Choice

Answer:

Consider the sort method shown below for selection sort: public static void sort (int[]
A) {
For (int i = 0; i < a.length - 1; i++)
{
Int minPos = minimumPosition(i);
Swap(minPos, i);
}
}
Suppose we modify the call to the swap method call to read swap(i, minPos). What would be the result?

Multiple Choice

Answer:

Consider the sort method for selection sort shown below: public static void sort (int[]
A) {
For (int i = 0; i < a.length - 1; i++)
{
Int minPos = minimumPosition(i);
Swap(minPos, i);
}
}
Suppose we modify the loop control to read int i = 1; i < a.length - 1; i++. What would be the result?

Multiple Choice

Answer:

Consider the minimumPosition method from the SelectionSorter class. Complete the code to write a maximumPosition method that returns the index of the largest element in the range from index from to the end of the array. private static int minimumPosition(int[] a, int from)
{
Int minPos = from;
For (int i = from + 1; i < a.length; i++)
{
If (a[i] < a[minPos]) { minPos = i; }
}
Return minPos;
}
Private static int maximumPosition(int[] a, int from)
{
Int maxPos = from;
For (int i = from + 1; i < a.length; i++)
{
________________
}
Return maxPos;
}

Multiple Choice

Answer:

Consider the swap method shown below from the SelectionSorter class. If we modified it as shown in the swap2 method shown below, what would be the effect on the sort method? private static void swap(int[] a, int i, int j)
{
Int temp = a[i];
A[i] = a[j];
A[j] = temp;
}
Private static void swap2(int[] a, int i, int j)
{
A[i] = a[j];
A[j] = a[i];
}

Multiple Choice

Answer:

Suppose you wanted to test your sort on an array filled with different elements each time the code is run. What is an efficient technique for creating an array of 1,000 elements for each run?

Multiple Choice

Answer:

After 9 iterations of selection sort working on an array of 10 elements, what must hold true?

Multiple Choice

Answer:

Which selection sort iteration guarantees the array is sorted for a 10-element array?

Multiple Choice

Answer:

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) {
For ____________________________________
{
Int maxPos = largestPosition(a, i);
ArrayUtil.swap(a, maxPos, i);
}
}

Multiple Choice

Answer:

The code segment below is designed to add the elements in an array of integers. Select the expression needed to complete the code segment so that it calculates the running time elapsed. long start = System.currentTimeMillis();
Int sum = 0;
For (int k = 0; k < values.length; k++)
{
Sum = sum + values[k];
}
Long runningTime = ____________________________;

Multiple Choice

Answer:

Consider an array with n elements. If we visit each element n times, how many total visits will there be?

Multiple Choice

Answer:

Suppose an array has n elements. We visit element #1 one time, element #2 two times, element #3 three times, and so forth. How many total visits will there be?

Multiple Choice

Answer:

Suppose an algorithm requires a total of 3n

^{3}+ 2n^{2}- 3n + 4 visits. In big-Oh notation, the total number of visits is of what order? Multiple Choice

Answer:

In big-Oh notation, when we consider the order of the number of visits an algorithm makes, what do we ignore?
I power of two terms
II the coefficients of the terms
III all lower order terms

Multiple Choice

Answer:

In big-Oh notation, suppose an algorithm requires an order of n

^{3}element visits. How does doubling the number of elements affect the number of visits? Multiple Choice

Answer: