Winter Bootcamp in ML and IoT in Jaipur
 Course content (For Bootcamp & Winter Training):- Machine Learning (ML) || Internet of Things (IoT) || Register for winter bootcamp
0 like 0 dislike
in Tutorial & Interview questions by (3.3k points)

1 Answer

0 like 0 dislike
by (3.3k points)
 
Best answer

Merge Sort is a Divide and Conqure algorithm. It divides input array in two halves, calls itself for the two halves and then merges the two sorted halves. The merge() function is used for merging two halves. 

Auxiliary Space  :   O(n)

Time complexity :  θ(nlog(n))

merge-sort-python-program

Python program for implementation of Merge Sort:

def mergeSort(arr):

    if len(arr) >1:

        mid = len(arr)//2 

        L = arr[:mid]

        R = arr[mid:]

         mergeSort(L)

        mergeSort(R)

         i = j = k = 0

         # Copy data to temp arrays L[] and R[]

        while i < len(L) and j < len(R):

            if L[i] < R[j]:

                arr[k] = L[i]

                i+=1

            else:

                arr[k] = R[j]

                j+=1

            k+=1

        while i < len(L):

            arr[k] = L[i]

            i+=1

            k+=1

         

        while j < len(R):

            arr[k] = R[j]

            j+=1

            k+=1        

a=[12,11,8,5,3,20]

mergeSort(a)

print(a)

 

Winter 10 Days boot-camp classes(7 HRS Daily) will start from 5, 20 & 27 December 2019 in:
1) Internet of things(IoT) Using RASPBERRY-PI
2) Machine Learning (ML)

70% OFF| Fee-INR 3,000/-

Limited seats!! Hurry up!!

[[ CALL - 07976731765 ]]

Some Study Resources are compiled from original Stack Overflow Documentation, the content is developed by the different experts at Stack Overflow. Study resources are released under Creative Commons BY-SA. Images may be copyright of their respective owners. This website is for self-learning and not affiliated with Stack Overflow. All trademarks and registered trademarks are the property of their respective company owners. Please send feedback and corrections to chandwaglobal@gmail.com.

...