pysorting.shellsort =================== .. py:module:: pysorting.shellsort .. autoapi-nested-parse:: This module implements the Shell Sort algorithm in Python. Shell Sort is a comparison-based sorting algorithm that generalizes the Shell Sort algorithm. It starts by sorting pairs of elements far apart from each other and then progressively reduces the gap between elements to be compared, ultimately achieving a sorted list. @author: Siddarth Subrahmanian Functions --------- .. autoapisummary:: pysorting.shellsort.shell_sort Module Contents --------------- .. py:function:: shell_sort(arr: list[float], ascending: bool = True) -> list[float] Sorts an array using the Shell Sort algorithm. Shell Sort repeatedly compares elements separated by a specific gap and rearranges them in the correct order. The gap is reduced over iterations until it becomes 1, at which point the list is fully sorted. The sorting order can be controlled using the `ascending` parameter. :param arr: The array of numeric values to be sorted. :type arr: list[float] :param ascending: If `True` (default), sorts the array in ascending order. If `False`, sorts the array in descending order. :type ascending: bool, optional :returns: A sorted array in ascending order if `ascending=True`, or in descending order if `ascending=False`. :rtype: list[float] :raises TypeError: If the input is not a list. :raises InvalidElementTypeError: If the list contains non-numeric elements or string values. :raises NonUniformTypeError: If the list contains more than one form of data type. :raises InvalidAscendingTypeError: If the `ascending` parameter is not a boolean. .. rubric:: Notes - Shell Sort is an improvement over Bubble Sort and Insertion Sort, with a time complexity of O(n^2) in the worst case. - This algorithm is more efficient than Bubble Sort for larger datasets. .. rubric:: Examples Sorting in ascending order (default): >>> shell_sort([5, 2, 8, 3, 1]) [1, 2, 3, 5, 8] Sorting in descending order: >>> shell_sort([3.5, 1.2, 2.8, 0.5], ascending=False) [3.5, 2.8, 1.2, 0.5]