Skip to content

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

Open
wew036 wants to merge 1 commit intoadnanaziz:masterfrom
wew036:master
Open

A merge sort of list with O(1) memory overhead#219
wew036 wants to merge 1 commit intoadnanaziz:masterfrom
wew036:master

Conversation

@wew036
Copy link
Copy Markdown

@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.

1 participant