Are you taking CLEP classes? Try clep.ai
| preferred AP College board partner for AP classes
AP Computer Science A/Unit 6: Array
Start Practice TestPractice Test
About Exam
hard Solved by 2 students

Quicksort Partition Method Execution

Mark
< Prev
Next >

Given the partition method below, what is the resulting state of the array {9, 3, 4, 8, 2} after the method is called with low = 0 and high = 4?

public class QuickPartition {
    public static int partition(int[] arr, int low, int high) {
         int pivot = arr[high];
         int i = low - 1;
         for (int j = low; j < high; j++) {
              if (arr[j] < pivot) {
                   i++;
                   int temp = arr[i];
                   arr[i] = arr[j];
                   arr[j] = temp;
              }
         }
         int temp = arr[i+1];
         arr[i+1] = arr[high];
         arr[high] = temp;
         return i+1;
    }
}
A

{2, 8, 4, 3, 9}

B

{2, 3, 4, 8, 9}

C

{3, 2, 4, 8, 9}

D

{9, 3, 4, 8, 2}

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

Question Leaderboard

Not enough data yet to show leaderboard.

AI Tutor

How can I help?

APFIVE © 2020.
Email: apfive@apfive.org|Privacy Policy|