Recursive Searching and Sorting (Binary Search, Merge Sort)

AP Computer Science A· difficulty 3/5

int[] a = {6, 3, 8, 5, 2, 7, 4, 1};
int mid = a.length / 2;
int[] left = new int[mid];
int[] right = new int[a.length - mid];
for (int i = 0; i < mid; i++) left[i] = a[i];
for (int i = mid; i < a.length; i++) right[i - mid] = a[i];

What is left after the divide step?

  • A

    {2, 7, 4, 1}

  • B

    {6, 3, 8, 5, 2}

  • C

    {}

  • D

    {6, 3, 8, 5}

    check_circle

Explanation

The left half contains the first mid=4 elements.

Want 10 more like this — adaptive to your weak spots?

Related questions

AP Computer Science A · Recursive Searching and Sorting (Binary Search, Merge Sort) Practice Question | Acemy