Common search and sort algorithms

Let’s go over some common search and sort algorithms you can apply to your projects or possible avoid using due to performance impact.

01. Linear search
This is the most basic form of searching and something most projects use with smaller arrays . But using this type of search with larger arrays can have a huge performance impact. Imagine you have an array of 10,000 objects and the object you are looking for is the last one. This would mean you have go through 9999 items before getting to it. The two upsides with this type of search is that it is quick to implement and the array does not need to be sorted.

Example:

02. Binary search
This is one of the most efficient search algorithms and still fairly straightforward to implement. The only downside with this search is that the data set must be sorted. This algorithm compares the value in the middle of the dataset with the highest value to the left and the lowest value to the right and then makes a new search based on which side has the value. It then repeats the same processes until the value is found.

Example:

03. Bubble Sort
Similar to linear search the bubble sort is very good in best case scenario i.e array is mostly sorted and small but it can have a huge performance impact if array is large and not sorted at all. But it has the same benefit as linear search, meaning it is the easiest algorithm to implement for sorting. The algorithm iterates through the array and compares the value at the current index with the next index and if it is higher than the next swap them. It will continue to compare the values until no values have been swapped meaning array has been fully sorted.

04. Merge Sort
This is one of the most efficient sorting algorithms. The list gets divided in half until each element is individual. The process is then reversed but the values in each list is sorted when it is merged into a new list.

Example:

Good luck!

--

--

--

Unity / C# Game developer

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Data binding for android beginners.

Monads in Scala by example

Adding Colliders to Tilemaps in Unity

How to Use Unity’s Native Audio Plugin SDK on macOS

Terraform Implementation framework for AWS

Managed Services Provides a Pathway to the Cloud and Composability.

🌐 2020 🔥 hot web technologies 🌐

Can You Do Financial Planning and Analysis With Python?

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
Niklas Bergstrand

Niklas Bergstrand

Unity / C# Game developer

More from Medium

Joker, the sense of laughter

Algorithms are Feelings Too

Insufferable

Getting into Good Trouble to Enhance Justice Innovation

Getting into Good Trouble to Enhance Justice Innovation