Complete the code to split the array into two halves.
mid := len(arr) [1] 2
We divide the length by 2 to find the middle index for splitting.
Complete the code to recursively sort the left half of the array.
left := divideAndConquer(arr[:[1]])We pass the left half slice up to the middle index to the recursive call.
Fix the error in the merge function call to combine sorted halves.
result := merge(left, [1])The merge function combines the left and right sorted halves.
Fill both blanks to complete the base case check and return.
if len(arr) [1] 1 { return [2] }
The base case returns the array itself if its length is <= 1.
Fill all three blanks to complete the divide and conquer function.
func divideAndConquer(arr []int) []int {
if len(arr) [1] 1 {
return [2]
}
mid := len(arr) [3] 2
left := divideAndConquer(arr[:mid])
right := divideAndConquer(arr[mid:])
return merge(left, right)
}This completes the base case check (len <= 1), return, and middle index calculation for divide and conquer.
