double sort Algorithm

The double sort algorithm is a unique approach to sorting a given set of data, typically an array or list, by applying two different sorting methods simultaneously or in a combined manner. This technique aims to improve the efficiency and speed of the sorting process by utilizing the advantages of both sorting methods and minimizing their limitations. The selection of the sorting methods depends on the type of data, its distribution, and the desired output. Common sorting algorithms used in double sort include bubble sort, selection sort, insertion sort, and quick sort, among others. In the double sort algorithm, the data set is divided into two parts, and each part is sorted using a different sorting method. Once both parts are sorted individually, they are merged together to form the final sorted result. The key to the double sort algorithm's effectiveness lies in selecting the appropriate sorting methods that complement each other and work efficiently with the given data set. For instance, if one part of the data is nearly sorted, using insertion sort would be advantageous, while the other part might benefit from quick sort if it has a more random distribution. By leveraging the strengths of both sorting methods, the double sort algorithm can lead to a significant improvement in the overall sorting process's performance and efficiency.
def double_sort(lst):
    """this sorting algorithm sorts an array using the principle of bubble sort,
    but does it both from left to right and right to left,
    hence i decided to call it "double sort"
    :param collection: mutable ordered sequence of elements
    :return: the same collection in ascending order
    Examples:
    >>> double_sort([-1 ,-2 ,-3 ,-4 ,-5 ,-6 ,-7])
    [-7, -6, -5, -4, -3, -2, -1]
    >>> double_sort([])
    []
    >>> double_sort([-1 ,-2 ,-3 ,-4 ,-5 ,-6])
    [-6, -5, -4, -3, -2, -1]
    >>> double_sort([-3, 10, 16, -42, 29]) == sorted([-3, 10, 16, -42, 29])
    True
    """
    no_of_elements = len(lst)
    for i in range(
        0, int(((no_of_elements - 1) / 2) + 1)
    ):  # we don't need to traverse to end of list as
        for j in range(0, no_of_elements - 1):
            if (
                lst[j + 1] < lst[j]
            ):  # applying bubble sort algorithm from left to right (or forwards)
                temp = lst[j + 1]
                lst[j + 1] = lst[j]
                lst[j] = temp
            if (
                lst[no_of_elements - 1 - j] < lst[no_of_elements - 2 - j]
            ):  # applying bubble sort algorithm from right to left (or backwards)
                temp = lst[no_of_elements - 1 - j]
                lst[no_of_elements - 1 - j] = lst[no_of_elements - 2 - j]
                lst[no_of_elements - 2 - j] = temp
    return lst


if __name__ == "__main__":
    print("enter the list to be sorted")
    lst = [int(x) for x in input().split()]  # inputing elements of the list in one line
    sorted_lst = double_sort(lst)
    print("the sorted list is")
    print(sorted_lst)

LANGUAGE:

DARK MODE: