In this article, I try to exploit all the features of Golang so that we do merge sort in the most optimized way which utilizes the multicores of the processor.

Merge sort is one of the most optimized ways of sorting with running time complexity O(n log n). The underlying principle is that it is cheaper to break the array into 2 parts and sort them individually and merge them at the end.

Color coding: Red -> split & sort. Green -> merge

Let us code the most rudimentary form:


In this article, I attempt to analyze (explain) the different concurrency design patterns by solving the Wordcount problem in a MapReduce fashion.

Developers at Google LLC built Golang in an attempt to solve concurrency issues in a scalable manner across the distributed setup.

Wordcount problem basically demands the count of each word across multiple documents. This could be directly solved by keeping a counter for each word and incrementing the same on its occurrence. This solution is however not scalable over millions of files (sending the files’ content from each node to the master is not feasible).
Hence we apply the MapReduce paradigm to solve this.

Here the Map part would be to collect the Wordcount from each file and the Reduce part would be to digest this list across all the files to generate the final Wordcount (shuffle is implicitly handled).

Example:


So all this started during the winter of 2017 when I started preparing myself for the internship I secured for the summers of 2018. During a call with the host of the internship project, I was intimated that my work would demand good skills in Golang.

A quick introduction: Golang(Go) was developed by Google and is very powerful and the language allows better coding & design patterns for concurrency and parallelism.

As a newbie, I obviously started with the official Golang tour https://tour.golang.org/welcome/ and https://exercism.io/my/tracks/go was also a good track to practice and get my hands dirty.

But one the…

Jayaganesh Kalyanasundaram

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store