# What is Merge sort?

• Merge sort is a sorting technique which works based on DIVIDE AND CONQUER method • This method uses recursion principle • Merge sort is the typical example of Divide and Conquer

Divide and Conquer
This is a 3 phase technique
3. Divide step:- Divide input data S into disjoint subsets S1 ,S2,… 4. Recur:- Solve the Subsets S1,S2,… 5. Combine:- Combine the subset solutions

How it is Merge sort done?
Merge sort is done in 3 main steps:1. Subdividing the main problem till the problem becomes small enough. 2. Solving the sub problem recursively 3. Combining the solutions (merging) to get the complete solution.

Technical stuff
The Algorithm for Merge_sort() can be written as:Merge_sort(input, start, limit) { if(start<limit) //if problem is large enough { div=(start + limit)/2;// here divided into 2 subpbms Merge_sort(input, start, div); Merge_sort(input, div+1,limit); Merge(input, output, start, div, limit); } }

Technical stuff
Similarly Algorithm for Merge() can be written as:Merge(input, output, start, div, limit) { j=0; while(start<div||div<limit) { if (input[start] < input[div]) // smaller one first {output[j] = input[limit]; start++;} else {output[j] = input[div]; div++} j++; }}

Time Complexity
There are three phases in this sorting techinique; The division phase, the conquer phase and finally combining the sub solutions. Division an combine takes O(n) while the Conquer step is O(log n) That is:- T(n) = 2T (n/2) + O(n) yielding a net time of O(nlogn)

Time Complexity

Comparison

Non Divide and Conquer algorithms

Why this?
1.Speed 2.High efficiency 3.Better than Heap sort in the case of large arrays

Short-comings
1.Efficiency not high for small arrays 2.Additional memory needed for the merge() 3.Usage of recursion means need of dynamic memory

References
3. www.wikipedia.org 4. Introduction to algorithms By Thomas Cormen Charles Leiserson Ronald Rivest 7. http://linux.wku.edu/~lamonml/algor/sort/sort.html

8. http://www.personal.kent.edu/~rmuhamma/Algorithms/MyAlgorithms/Sorting/m
{"found_math": false, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 0, "mathjax_display_tex": 0, "mathjax_asciimath": 0, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0, "url": "https://www.scribd.com/doc/17606116/Merge-Sort", "fetch_time": 1505921854000000000, "content_mime_type": "text/html", "warc_filename": "crawl-data/CC-MAIN-2017-39/segments/1505818687324.6/warc/CC-MAIN-20170920142244-20170920162244-00383.warc.gz", "warc_record_offset": 888694400, "warc_record_length": 23596, "token_count": 534, "char_count": 2044, "score": 3.859375, "int_score": 4, "crawl": "CC-MAIN-2017-39", "snapshot_type": "latest", "language": "en", "language_score": 0.6900941133499146, "file_path": "/sailhome/yjruan/project/latent-lm/data/processed/finemath-4plus/finemath-4plus/train-00004-of-00064.parquet"}