API Reference¶
Sorting¶
-
pyalgos.sorting.
insertion
(elements)[source]¶ Returns the sorted values using insertion sort algorithm.
The best case is when the input is an array that is already sorted. In this case, insertion sort has a linear running time O(n).
The worst case is when the input is an array sorted in reverse order. In this case, insertion sort has a quadratic running time O(pow(n,2)).
Parameters: elements (list/tuple) – A list/tuple of values provided by the user. Returns: A list/tuple of elements sorted in ascending order. Return type: list/tuple New in version 0.1.0.
Changed in version 0.1.1: Added validation for checking whether every element in the list is a string (when strings are provided in the list).
Changed in version 0.1.2: Added support for tuples. Now the user can also provide a tuple of values.
Changed in version 0.2.0: insertion() can now return the list when the size of list is less than or equal to 1.
-
pyalgos.sorting.
selection
(elements)[source]¶ Returns the sorted values using selection sort algorithm.
Selection sort has O(pow(n, 2)) time complexity in all the three cases (Best, Average and Worst).
Parameters: elements (list/tuple) – A list/tuple of values provided by the user. Returns: A list/tuple of elements sorted in ascending order. Return type: list/tuple New in version 0.1.0.
Changed in version 0.1.1: Added validation for checking whether every element in the list is a string (when strings are provided in the list).
Changed in version 0.1.2: Added support for tuples. Now the user can also provide a tuple of values.
Changed in version 0.2.0: selection() can now return the list when the size of list is less than or equal to 1.
-
pyalgos.sorting.
merge
(elements)[source]¶ Returns the sorted values using merge sort algorithm.
The time complexity will always be O(n * log(n)).
Parameters: elements (list/tuple) – A list/tuple of values provided by the user. Returns: A list/tuple of elements sorted in ascending order. Return type: list/tuple New in version 0.2.0.