| preferred AP College board partner for AP classes
AP Computer Science A/Unit 6: Array
Start Practice Test
Share
medium Solved by 13 students
Logical Error In Partial Bubble Sort
< Prev
Next >

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.

Hint
Did You Know?
Explain Why
Explain All Answers
Check Answer
Show Correct Answer

Question Leaderboard

Rank
User
Correct Count
Attempt Count
Time
Score
#1bommasam00033 2m 32s 148
#2the.ronzono11 0m 00s 100
#3y.seong202711 1m 10s 30
#4winstonhou110712 2m 49s -79
#5suhanakochhar00611 3m 16s -96
#6geethasailaja11 20m 08s -1,108
#7sathilak00013 23m 00s -1,300
#8singhris00012 26m 25s -1,495
APFIVE © 2020.
Email: apfive@apfive.org|Privacy Policy