You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Does Exercise 4 Merge Sort implementation require an in-place variant or the driver code requires a small update to facilitate out-of-place merge-sort by replacing mergeSort(arr) with arr = mergeSort(arr)?
The text was updated successfully, but these errors were encountered:
Hello, I implemented the code by creating left and right subarrays in each call and then merging them back into the original array. The driver code worked fine and gave the correct sorted array when I tested it, but I haven’t tried it with other examples yet.
I got the correct answer, so I didn’t change the driver code. I didn't know that I could update it because the code provided already seemed to work. Since the merge function updates the array directly, I didn't think it was necessary to modify the driver code.
Now, I understand that for an out-of-place merge-sort, the driver code would need a small update with arr = mergeSort(arr) to store the result properly. To improve, I think I can look into making it more efficient by using in-place merge sort with indices instead of creating new subarrays every time. Let me know if there’s a better way or any trick I should try, and I can work on it further?
PreCourse-2/Exercise_4.py
Line 16 in 40d0458
Does Exercise 4 Merge Sort implementation require an in-place variant or the driver code requires a small update to facilitate out-of-place merge-sort by replacing mergeSort(arr) with arr = mergeSort(arr)?
The text was updated successfully, but these errors were encountered: