Common Sorting Algorithms Explained

Computer science is fascinating because it shows us the many different tasks we can improve upon using computers. One of the simplest tasks that any of us have to do is sort data by some order: alphabetical, numerical, or otherwise. What algorithms are used to sort data?
Like any other algorithm, sorting algorithms consist of a set of instructions that are intended to take in various types of data and perform an operation. Sorting can be used to not just present data in this desired state but also to make solving problems easier. It takes less time and resources to search a sorted directory (like a phone book or dictionary) than to search one that is unsorted.

One of the simplest sorting algorithms is the bubble sort. This algorithm works by taking in a list of unsorted data and checking each subsequent data pair. Imagine you have an array (just a list of data) that looks like this: [1,3,2,4,5]. The bubble sort will check that 1 is less than 3 and it is. This means it can move to compare 3 and 2. Since 3 > 2, this pair is swapped. The algorithm does this to the end of the array before starting again. If it makes no changes on one run through the array, then the sort is done.
While the bubble sort is commonly used on smaller datasets like the one above, the need to check so much data can cause large amounts of data to take too long to run. We can use a selection sort to speed up this process. We begin at the beginning and choose the value 1 to be the “smallest”. If we find a smaller value later in the array, we swap the two elements and begin at the second element.

This process gives us the same results but is significantly faster on most data. Similarly, other sorting algorithms like insertion sort allow us to better suit the types of data we have. Applying different operations to reach the same result shows us the power of algorithms in computing and the need to explore multiple options for the most optimal programming experience.

Picture Source: gadgetronicx.com

Picture Source: gadgetronicx.com

Keshav Santhanam- CuriouSTEM Staff

CuriouSTEM Content Creator- Computer Science

Previous
Previous

HTTPS and the Rise of Internet Security

Next
Next

Computer Networking