Merge Sort

    0

    0

    HARIGOVIND VALSAKUMAR

    PythonMergeSort
    HGV Public Cookbook

    Function to perform Merge sort.

    def merge_sort(collection):
        def merge(left, right):
            result = []
            while left and right:
                result.append((left if left[0] <= right[0] else right).pop(0))
            return result + left + right
        if len(collection) <= 1:
            return collection
        mid = len(collection) // 2
        return merge(merge_sort(collection[:mid]), merge_sort(collection[mid:]))
    
    Codiga Logo
    Codiga Hub
    • Rulesets
    • Explore
    • Cookbooks
    • Playground
    soc-2 icon

    We are SOC-2 Compliance Certified

    G2 high performer medal

    Codiga – All rights reserved 2022.