input: Write a python function to implement merge sort.
  assert merge_sort([3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5])==[1, 1, 2, 3, 3, 4, 5, 5, 5, 6, 9]
  assert merge_sort([10, 7, 8, 9, 1, 5])==[1, 5, 7, 8, 9, 10]
  assert merge_sort([])==[]
  assert merge_sort([1])==[1]
  assert merge_sort([2, 1])==[1, 2]
output: def merge_sort(arr):
      if len(arr) <= 1:
          return arr
  
      def merge(left, right):
          merged = []
          left_idx, right_idx = 0, 0
  
          while left_idx < len(left) and right_idx < len(right):
              if left[left_idx] < right[right_idx]:
                  merged.append(left[left_idx])
                  left_idx += 1
              else:
                  merged.append(right[right_idx])
                  right_idx += 1
  
          merged.extend(left[left_idx:])
          merged.extend(right[right_idx:])
          return merged
  
      mid = len(arr) // 2
      left_half = merge_sort(arr[:mid])
      right_half = merge_sort(arr[mid:])
  
      return merge(left_half, right_half)