The merge sort algorithm presented below sorts uses the merge method which is partially shown below. Select the condition that would be needed to complete the method so that the elements are sorted in descending order. private static void merge(int[] first, int[] second, int[] a) { int iFirst = 0; int iSecond = 0; int j = 0; while (iFirst < first.length && iSecond < second.length) { if (_____________________________) { a[j] = first[iFirst]; iFirst++; } else { a[j] = second[iSecond]; iSecond++; } j++; } // rest of the method follows here }单项选择题

A

first[iFirst] < second[iSecond]

B

iFirst > iSecond

C

first[iFirst] > second[iSecond]

D

iFirst < iSecond

登录即可查看完整答案

我们收录了全球超50000道真实原题与详细解析,现在登录,立即获得答案。

类似问题

When executing merge, within mergesort, what is true of the sequences being merged?

When executing merge, within mergesort, what is the worst case time cost on two sequences of length n? Select the tightest bound that holds.

Question at position 21 Consider the following mergeSortHelper method, which is part of an algorithm to recursively sort an array of integers. The merge method is used to merge two halves of an array (arr[from] through arr[middle], inclusive, and arr[middle + 1] through arr[to], inclusive) when each half has already been sorted into ascending order. For example, consider the array arr1, which contains the values {1, 3, 5, 7, 2, 4, 6, 8}. The lower half of arr1 is sorted in ascending order (elements arr1[0] through arr1[3], or {1, 3, 5, 7}), as is the upper half of arr1 (elements arr1[4] through arr1[7], or {2, 4, 6, 8}). The array will contain the values {1, 2, 3, 4, 5, 6, 7, 8} after the method call merge(arr1, 0, 3, 7, temp). The array temp is a temporary array declared in the calling program. Consider the following code segment, which appears in a method in the same class as mergeSortHelper and merge. int[] vals = {80, 50, 30, 20, 60, 70}; int[] temp = new int[vals.length]; mergeSortHelper(vals, 0, vals.length - 1, temp); Which of the following represents the arrays merged the last time the merge method is executed as a result of the code segment above?{20, 30, 50} and {60, 70, 80} are merged to form {20, 30, 50, 60, 70, 80}.{20, 50, 70} and {30, 60, 80} are merged to form {20, 30, 50, 60, 70, 80}.{20, 50, 70} and {30, 60, 80} are merged to form {20, 50, 70, 30, 60, 80}.{30, 50, 80} and {20, 60, 70} are merged to form {20, 30, 50, 60, 70, 80}.

_____ is a sorting algorithm that divides a list into two halves, recursively sorts each half, and then merges the sorted halves to produce a sorted list.

更多留学生实用工具

加入我们,立即解锁 海量真题独家解析,让复习快人一步!