Skip to content

/sorts/merge_sort_fastest.py is NOT fast at all #328

@tom5610

Description

@tom5610

Hi @harshildarji & @yesIamHasi ,

Thanks for sharing algorithm source code and I really like them.

Just want to raise an issue on '/sorts/merge_sort_fastest.py' that it is not an merge_sort option as there are dependencies on python built-in functions - remove(), max() & min(), which makes 'merge_sort_fastest' like O(n^2) [ (n*(n+1)) / 2 * 2 as one max()/min() with remove()] instead of O(n log n).

For example, while sorting 50,000 random numbers with below list:
unsorted = random.sample(range(0, 100000), 50000)

The running result will be like:
(venv) $ time python3 merge_sort.py
real 0m0.361s
user 0m0.347s
sys 0m0.011s

(venv) $ time python3 merge_sort_fastest.py
real 0m49.306s
user 0m49.103s
sys 0m0.099s

thanks!
Tom

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions