One of the most efficient sorting algorithms is Merge Sort. The task is to implement this.
In the file merge.py we have provided a skeleton of the algorithm. Modify this file.
You can run the program with the command:
python3 merge.py input.text
where input.txt is a text file containing the numbers to be sorted. The program will automatically read this into an array. You can assume that only natural numbers are present and each number appears at most once.
The merge_sort function implements the divide-and-conquer principle: it splits into two the given section of an array and recursively calls itself on these two parts. The section to be divided is between the indices l and r.
The task is to write the merge function, which merges two subarrays of the received array. These subarrays are between indices l--m and (m+1)--r.
The result of the merge should be copied in the original array instead of returning it in a new array.
If necessary, you can modify other parts of the program as well.
The program will print the sorted list to the terminal.
You can test the completed program, for example, on the file array1.text.