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 right after the divide step?

  • A

    {1, 4, 7, 2}

  • B

    {6, 3, 8, 5}

  • C

    {6, 3, 8, 5, 2, 7, 4, 1}

  • D

    {2, 7, 4, 1}

    check_circle

Explanation

The right half of an 8-element array is the second 4 elements.

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

Related questions