3 Sorting Algorithms All Programmers Should Learn

Writing efficient algorithms is the most important factor that determines how effective a programmer truly is. At the end of the day you can have the most powerful computer in the world, but if your code is unable to run efficiently your code will be useless. It is no wonder why big companies such as Google and Apple test job applicants on their ability to create effective algorithms.

While reading this article please keep in mind that you should not memorize each algorithm by heart. But rather you should learn to think algorithmically and understand the thought process behind developing these efficient algorithms. This is truly a skill that separates great programmers from average programmers.

Merge Sort

Merge Sort Algorithm

The merge sort algorithm utilizes the divide and conquer strategy. First you start with one large array and then divide the array into smaller subarrays. Each subarray is divided until there is only one element in each subarray. Then you start merging each subarray back together based on the value it contains. This process is repeated until you arrive at the original array however this time it is in sorted order.

Selection Sort

Selection Sort Algorithm

The selection sort algorithm repeatedly finds the minimum element from an array and adds the minimum element to the beginning. This process is repeated for the entire unsorted portion of the array until it has been sorted in ascending order. It should be noted that the selection sort algorithm is extremely inefficient for large data sets since you must iterate through each element within the array.

Insertion Sort

Insertion Sort Algorithm

The insertion sort algorithm operates on the same principles as the selection sort algorithm. However, once the insertion sort algorithm arrives at an element in the unsorted portion of the array, it inserts this element at its correct position within the sorted portion of the array. Unlike selection sort, the insertion sort algorithm does not look for the minimum element but rather it looks for the next element within the unsorted portion of the array.

Conclusion

At the end of the day you do not need to memorize each algorithm or data structure. However it is very useful to practice thinking algorithmically so that you can effectively solve problems in a short duration of time. A great resource for learning how to solve problems using algorithms is LeetCode (no I’m not sponsored).

Practicing algorithms and data structures each day will make you a much more employable programmer due to your ability to pass technical interviews.

One More Thing

For business inquiries or general questions feel free to reach me at officialnatelee@gmail.com

--

--

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