Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

In-place asked or minor error. #254

Open
being-aerys opened this issue Dec 21, 2020 · 1 comment
Open

In-place asked or minor error. #254

being-aerys opened this issue Dec 21, 2020 · 1 comment

Comments

@being-aerys
Copy link

mergeSort(arr)

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)?

@ChiragK22
Copy link

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants