sorts.merge_sort

This is a pure Python implementation of the merge sort algorithm.

For doctests run following command: python -m doctest -v merge_sort.py or python3 -m doctest -v merge_sort.py For manual testing run: python merge_sort.py

Attributes

user_input

Functions

merge_sort(→ list)

Sorts a list using the merge sort algorithm.

Module Contents

sorts.merge_sort.merge_sort(collection: list) list

Sorts a list using the merge sort algorithm.

Parameters:

collection – A mutable ordered collection with comparable items.

Returns:

The same collection ordered in ascending order.

Time Complexity: O(n log n)

Examples: >>> merge_sort([0, 5, 3, 2, 2]) [0, 2, 2, 3, 5] >>> merge_sort([]) [] >>> merge_sort([-2, -5, -45]) [-45, -5, -2]

sorts.merge_sort.user_input