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

A merge sort of list with O(1) memory overhead #219

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

wew036
Copy link

@wew036 wew036 commented Oct 10, 2021

This change solves the sort_list problem without recursion,
which reduces its memory usage from O(log N) to O(1).

It merges the data in a bottom up fashion, by building sorted
runs of length 1, 2, 4, 8, etc. The sorted runs are put onto
two lists alternatively so that it makes the next iteration of
sorting easier.

It also runs about 40% faster than the previous solution based
on the average run time printed by "make sort_list".

This change solves the sort_list problem without recursion,
which reduces its memory usage from O(log N) to O(1).

It merges the data in a bottom up fashion, by building sorted
runs of length 1, 2, 4, 8, etc. The sorted runs are put onto
two lists alternatively so that it makes the next iteration of
sorting easier.

It also runs about 40% faster than the previous solution based
on the average run time printed by "make sort_list".
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

Successfully merging this pull request may close these issues.

None yet

1 participant