MergeSort

MergeSort#

class MergeSort#

Bases: SortingAlgorithm

__init__()#

Methods

__init__()

get_worst_case_arguments(input_size)

Generates range of integers from 1 to input_size with two sorted subsections and descending keyword argument as True.

increment_n_comparisons([increment])

rtype:

None

increment_n_ops([increment])

Convenience method to increment n_ops count of the given complexity object.

increment_n_swaps([increment])

rtype:

None

reset_all_counters()

rtype:

None

reset_n_comparisons()

rtype:

None

reset_n_ops()

Convenience method to reset n_ops count of the given complexity object.

reset_n_swaps()

rtype:

None

run_algorithm(input_instance[, ...])

Run function of the merge sort algorithm implemented in the bottom-up fashion.

Attributes

property algorithm_family: AlgorithmFamily#
Return type:

AlgorithmFamily

property algorithm_properties: SortingAlgorithmProperties#
Return type:

SortingAlgorithmProperties

property average_case_time_complexity: str#
Return type:

str

property best_case_description: str#
Return type:

str

property best_case_time_complexity: str#
Return type:

str

get_worst_case_arguments(input_size)#

Generates range of integers from 1 to input_size with two sorted subsections and descending keyword argument as True.

Parameters:

input_size (int) – Size of the range to generate.

Returns:

run_algorithm_kwargs – A dictionary with keyword arguments for the input_instance and descending parameters of the run_algorithm method.

Return type:

dict[str, Any]

increment_n_comparisons(increment=1)#
Return type:

None

increment_n_ops(increment=1)#

Convenience method to increment n_ops count of the given complexity object.

Return type:

None

increment_n_swaps(increment=1)#
Return type:

None

property is_deterministic: bool#
Return type:

bool

property n_ops: int#
Return type:

int

property name: str#
Return type:

str

reset_all_counters()#
Return type:

None

reset_n_comparisons()#
Return type:

None

reset_n_ops()#

Convenience method to reset n_ops count of the given complexity object.

Return type:

None

reset_n_swaps()#
Return type:

None

run_algorithm(input_instance, verbosity_level=0, descending=True, *args, **kwargs)#

Run function of the merge sort algorithm implemented in the bottom-up fashion.

Parameters:
  • input_instance (Iterable[Comparable]) – Iterable input instance of comparable objects to run the sorting algorithm on. It is copied and then returned as a sorted list.

  • verbosity_level (int (default 0)) – Select the amount of information to print throughout run of the algorithm. One of 0, 1, 2 with 0 referring to no printing, 1 leading to print of the iterable before and after and 2 meaning print after every swap.

  • descending (bool (default True)) – Whether to sort in descending order. Note that the algorithm is built in a stable manner, so that the relative order of items with equal value remains intact.

  • args (Any) – Additional arguments passed to the running function.

  • kwargs (Any) – Additional keyword arguments passed to the running function.

Returns:

result – Returns boolean value representing whether the algorithm terminated successfully (always True in this case) and List copy of the given input instance iterable sorted in the required order.

Return type:

tuple[bool, list[Comparable]]

property space_complexity: str#
Return type:

str

property worst_case_description: str#
Return type:

str

property worst_case_time_complexity: str#
Return type:

str