pyufunc.algo_insertion_sort#

pyufunc.algo_insertion_sort(array, verbose=False)#

Sort the input array using insertion sort algorithm.

Parameters:
  • array (Iterable) – iterable object to be sorted.

  • verbose (bool, optional) – whether to print out running time. Defaults to False.

Raises:

ValueError – Input should be iterable.

Returns:

sorted array

Return type:

Iterable

Example

>>> from pyufunc import insertion_sort
>>> insertion_sort([3, 6, 8, 10, 1, 2, 1])
[1, 1, 2, 3, 6, 8, 10]
>>> insertion_sort([3, 6, 8, 10, 1, 2, 1], verbose=True)
Running time of insertion_sort: O(n^2)
[1, 1, 2, 3, 6, 8, 10]