Optimize the Merge Sort #12842
Conversation
76ce355 to
7eb0988
Compare
for more information, see https://pre-commit.ci
MrittikaDutta
left a comment
There was a problem hiding this comment.
Docstring Edge Case Note
You could note in the main docstring that this implementation is not in-place and uses additional memory due to list slicing and merging.
Yeah true Thus, it is just about to spread knowledge that correctly matches with the practical (code) one. |
|
Closing tests_are_failing PRs to prepare for Hacktoberfest |
Describe your change:
After reviewing the code, I noticed that while storing the sorted elements in the result one by one by comparing two lists, left and right, the pop() function was used to reduce the lines of code. I wanted to highlight a concern about the pop() function. In Python, the pop() function removes an element at a specified valid index from the list (defaulting to the last element if no index is provided). However, popping the first element has a time complexity of O(n) (where n is the length of the list), leading to additional time complexity and potentially creating a worst-case scenario for an already sorted list.
Checklist: