Online Courses
Free Tutorials  Go to Your University  Placement Preparation 
Goeduhub's Online Courses @ Udemy in Just INR 570/-
Online Training - Youtube Live Class Link
0 like 0 dislike
112 views
in Python Programming by Goeduhub's Expert (8.3k points)

Goeduhub's Top Online Courses @Udemy

For Indian Students- INR 570/- || For International Students- $12.99/-

S.No.

Course Name

 Coupon

1.

Tensorflow 2 & Keras:Deep Learning & Artificial Intelligence

Apply Coupon

2.

Natural Language Processing-NLP with Deep Learning in Python Apply Coupon

3.

Computer Vision OpenCV Python | YOLO| Deep Learning in Colab Apply Coupon
    More Courses

1 Answer

0 like 0 dislike
by Goeduhub's Expert (8.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)

 

3.3k questions

7.1k answers

393 comments

4.5k users

Related questions

0 like 0 dislike
0 answers 91 views
0 like 0 dislike
1 answer 137 views
0 like 0 dislike
1 answer 326 views
0 like 0 dislike
1 answer 210 views

 Goeduhub:

About Us | Contact Us || Terms & Conditions | Privacy Policy || Youtube Channel || Telegram Channel © goeduhub.com Social::   |  | 
...