In honor of International Jazz Day (April 30), it's time to bring some harmony to your code! In this challenge you are asked to implement the merge sort algorithm to sort an array of integers in ascending order. In addition to returning the sorted array, your implementation should also count and return the number of comparisons made during the sorting process.
Write a function that takes an array of integers as input and returns an object (or a tuple, based on your language) containing:
Note: Do not use built-in sort functions. Implement merge sort (or another divide-and-conquer sorting algorithm) to solve this problem.
For input: [5, 2, 9, 1]
, a possible output could be:
{
sorted: [1, 2, 5, 9],
comparisons: X // where X is the number of comparisons your algorithm made
}
Your task is to complete the function with the starter code provided below for your language.