Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Merge Implementation Issue in Merge Sort #11434

Robertation256 started this conversation in General
Discussion options

I think popping from the beginning of the list might be very expensive here and can cause the sorting complexity to deteriorate to O(n^2)

You must be logged in to vote

Replies: 1 comment 1 reply

Comment options

Popping from the front can indeed be expensive for large lists. Bu int his case we are popping from the list which is referenced in the merge function which is called recursively thus it doesn't affect the overall time complexity.
In case we are popping without recursion it can prove to be expensive

You must be logged in to vote
1 reply
Comment options

Not sure what you mean by that but if you consider the last merge pass where you merge two sorted sublists of size N/2, popping from the front of the list in this pass alone immediately yields in O(N^2) overhead.

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

AltStyle によって変換されたページ (->オリジナル) /