#5.Write a program to find minimum and maximum value in an array using divide and conquer.
def find_min_max(arr, low, high):
# Base case: if there is only one element
if low == high:
return arr[low], arr[low]
# Base case: if there are two elements, return min and max
elif high == low + 1:
if arr[low] < arr[high]:
return arr[low], arr[high]
else:
return arr[high], arr[low]
# Recurse on left and right halves
mid = (low + high) // 2
min1, max1 = find_min_max(arr, low, mid)
min2, max2 = find_min_max(arr, mid + 1, high)
# Combine results
return min(min1, min2), max(max1, max2)
# Example usage
arr = [3, 5, 1, 8, 9, 2, 7, 6]
min_val, max_val = find_min_max(arr, 0, len(arr) - 1)
print("Minimum value:", min_val)
print("Maximum value:", max_val)