Logical Error In Partial Bubble Sort
The following bubbleSortPartial method is intended to sort a segment of an array. Which statement best describes the logical error in the method?
public class BubbleSortPartial {
public static void bubbleSortPartial(int[] arr, int start, int end) {
for (int i = start; i < end; i++) {
for (int j = start; j < end - i - 1; j++) {
if (arr[j] > arr[j+1]) {
int temp = arr[j];
arr[j] = arr[j+1];
arr[j+1] = temp;
}
}
}
}
}
A
The algorithm does not perform swaps when elements are equal.
B
The outer loop should begin at index 0 regardless of the start parameter.
C
There is an off-by-one error in the outer loop’s termination condition.
D
The inner loop’s boundary calculation fails to account for the ‘start’ index, leading to incorrect sorting of the specified segment.
Question Leaderboard
| Rank | |||||
|---|---|---|---|---|---|
| #1 | bommasam000 | 3 | 3 | 2m 32s | 148 |
| #2 | the.ronzono | 1 | 1 | 0m 00s | 100 |
| #3 | y.seong2027 | 1 | 1 | 1m 10s | 30 |
| #4 | winstonhou1107 | 1 | 2 | 2m 49s | -79 |
| #5 | suhanakochhar006 | 1 | 1 | 3m 16s | -96 |
| #6 | geethasailaja | 1 | 1 | 20m 08s | -1,108 |
| #7 | sathilak000 | 1 | 3 | 23m 00s | -1,300 |
| #8 | singhris000 | 1 | 2 | 26m 25s | -1,495 |
APFIVE