Mergesort is a complicated process, but what is it actually doing? We are going to take a closer look at the process in this exercise. You are given the merge sort algorithm and you need to add some print statements so that you can see what actually is happening. Add a print statement at each step, as well as print out the array each time. Your output needs to match the sample below. Here is a portion of a sort as an example: Unsorted: 5 3 4 1 6 9 2 7 Splitting ... *** Left: 5 3 4 1 *** Right: 6 9 2 7 Splitting ... *** Left: 5 3 *** Right: 4 1 Splitting ... *** Left: 5 *** Right: 3 Merging ... *** Current: 3 5 ... Merging ... *** Current: 2 6 7 9 Merging ... *** Current: 1 2 3 4 5 6 7 9 Sorted: 1 2 3 4 5 6 7 9
Mergesort is a complicated process, but what is it actually doing? We are going to take a closer look at the process in this exercise.
You are given the merge sort
Add a print statement at each step, as well as print out the array each time. Your output needs to match the sample below. Here is a portion of a sort as an example:
Unsorted: 5 3 4 1 6 9 2 7 Splitting ... *** Left: 5 3 4 1 *** Right: 6 9 2 7 Splitting ... *** Left: 5 3 *** Right: 4 1 Splitting ... *** Left: 5 *** Right: 3 Merging ... *** Current: 3 5 ... Merging ... *** Current: 2 6 7 9 Merging ... *** Current: 1 2 3 4 5 6 7 9 Sorted: 1 2 3 4 5 6 7 9
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 1 images