As you might have guessed, a sorting algorithm takes a list of items and sorts them— normally in alphabetical or numerical order.
Learning sorting algorithms is a great way to improve your craft and demand as a software engineer. These are a great way to practice time and space complexity analysis, and come up with clever solutions to simple problems. Working on these skills now will drastically help you when you start interviewing for your next job.
This is especially true if you’re applying for any of the larger tech companies that require you to strongly understand algorithms and data structures.
In addition to the time and space complexity of sorting algorithms, the below properties help define sorting algorithms.
Adaptability: An adaptive sort’s performance improves the more sorted the list is initially
In-place: An in-place sort requires a constant amount of additional space
Parallelism: A parallel sort can split its workload between multiple workers
Stability: A stable sort preserves the order of items in the list that evaluate to the same value
This is a common algorithmic pattern based on recursion, which is implemented in both merge sort and quick sort. It breaks one main problem into many sub-problems that are similar to the original problem. It then recursively solves the sub-problems, and finally combines the solutions at the end. Remember, divide-and-conquer can have many more than two subproblems which means we’re really utilizing recursion. If you don’t yet feel comfortable with recursion, I highly recommend this article by Anton Arboleda.
There are three parts to a divide and conquer solution:
This is a pretty straightforward approach to problem solving, and one I’m sure you’re familiar with. It’s considered one of the easiest to apply to small problems. As you might have guessed, this is not normally the most efficient approach that we want to take with our algorithms.
Some examples of brute force sort algorithms include bubble sort and selection sort.
Having worked across sites raking in over 50 billion website visits annually, Michael Mitrakos can help your business to crush the web game with an award winning website.
I also created Wanderlust Extension to discover the most beautiful places across the world with highly curated content. Check it out!
If you’re a beginner to sorting algorithms, I highly suggest you start with bubble sort.