Sitemap
Rishi Krishnan Natarajan

Rishi Krishnan Natarajan

Engineer

Merge Sort

1 min readOct 12, 2020

In this article I will try my best to explain merge sort in much easier way using C programming. Merge sort is a bit complicated, but it is rewarding in the end with respect to time complexity. Merge sort has a time complexity of O(nlogn). Merge sort is a divide and conquer method that was invented by John von Neumann in 1945, the idea was to divide it into individual elements, sort it and merge it together in the end.

Get Rishi Krishnan Natarajan’s stories in your inbox

Join Medium for free to get updates from this writer.

In this code I have solved merge sort using Recursion in c programming

MERGE SORT

The key idea was to break up the array into individual elements recursively using divide and conquer approach and sort it, In the code given above I have broke the array into single elements 1,2,45,78,9; then in that case all the elements are already sorted, once the individual elements are sorted , I am merging the sorted array with other array until I get final array with full length. The key is to work it on a board before stepping up on the code. Feel free to let me know if you any questions

Merge sort: time complexity is 0(nlogn) in the worst case and has a space complexity of O(n)

--

--