Coder Social home page Coder Social logo

iamabhii1 / mergesort Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ayushi0901/mergesort

0.0 0.0 0.0 9 KB

This is source code of performing merge sorting through Python.

Home Page: https://ayushi0901.github.io/MergeSort/

Python 100.00%

mergesort's Introduction

Merge Sort

This is Merge Sort Python Program.

About :

Merge Sort is a Divide &Conquer Alogrithm.

It divides input array in two halves,calls itself for the two halves. the merge(arr,l,m,r) is key process that assumes that arr{i....m} and arr{m+1...r} are sorted and merge the two sorted is sub arrays into one.

What do you mean by " Divide and Conquer approach"?

A Divide-and-conquer Algorithm works by recursively breaking down a problem into two or more 
sub-problems of the same or related type, until these become simple enough to be solved directly. 

The solutions to the sub-problems are then combined to give a solution to the original problem.

The array is split in half and the process is repeated with each half until each half is of size 1 or 0. 

The array of size 1 is trivially sorted.

Now the two sorted arrays are combined into one big array. And this is continued until all the elements are combined and the array is sorted. 

Time complexity

The algorithm works in O(n.logn). This is because the list is being split in log(n) calls and the merging process takes linear time in each call.

Auxiliary Space: O(n)

Algorithmic Paradigm: Divide and Conquer

Sorting In Place: No in a typical implementation

Stable: Yes

Applications :

1) Merge Sort is useful for sorting linked lists in O(nLogn) time.
2)Inversion Count Problem
3)Used in External Sorting

Pseudocode :

MergeSort(arr[], l,  r)
If r > l
     1. Find the middle point to divide the array into two halves:  
             middle m = (l+r)/2
     2. Call mergeSort for first half:   
             Call mergeSort(arr, l, m)
     3. Call mergeSort for second half:
             Call mergeSort(arr, m+1, r)
     4. Merge the two halves sorted in step 2 and 3:
             Call merge(arr, l, m, r)

mergesort's People

Contributors

ayushi0901 avatar iamabhii1 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.