# Beauty of Algorithms

Have you ever considered why algorithms are highly valued and learnt by many? Some might even question that if learning these topics will provide them any benefit in projects and work.

Let’s get to

solving these doubts!

# Algorithms

**Algorithms are nothing but a set of steps or rules one follows to achieve a task.** What do I mean? Let’s start with a very simple example. We all dress up nicely everyday right? And only when we are dressed, we know to go outside.* This is an algorithm*. Simple isn’t it? Even learning how to tie our shoes is an algorithm.

Now, let’s take a more practical example. Let’s say you had to find the number “12546” in a book with 5000 pages arranged in increasing order of numbers [1, 100000]. Here are 3 possible ways you can approach this:

- Randomly flip through pages in the book (too much time)
- Search in a sequential manner (too much time)
- First turning to a page (e.g. 2500), then seeing if your number is lower/higher than the numbers listed on that page. Going x number of pages up or down as necessary and in a few minutes you’ll eventually find “12546”

All 3 approaches listed will eventually lead you to the final goal but only the last one does this in a more efficient manner. This last approach is actually what we call the *“Binary Search Algorithm”.*

# But…why Algorithms?

Now you might be getting some idea of why algorithms are valued. Main idea is that we want to make our **lives simpler.**

Let’s do a quick math analogy here!

Let’s say we want to find the roots of a quadratic function. *We can solve by using the quadratic formula, factoring, completing the square or graphing the function right? *But, out of these 4 ways, **only the quadratic formula is simple, efficient, and always works in any given situation.** This technique also has no limitations like factoring does and is much easier to implement than graphing. Hopefully it’s making more sense now.

Knowing when and where to use data structures like Hash Tables, Trees, Tries, Graphs, and various algorithms gives you a strong edge. It’s like a car mechanic who knows how to fix a car quick and well without damaging it. In fact, in most high-level projects, engineers/developers actually spend more time on the design, algorithm selection, quality assurance and efficiency than the actual implementation (only 25–40% approx.).

# Few Helpful Algorithm Categories

From here on out, the article will get a little more technical so get ready for the ride!

**I would like to share with everyone what I think are 4 helpful categories of algorithms to know.**

*Please note that this is my opinion and are based off what I have personally worked with. Use this as a reference and please do not solely depend on it.*

**They are,**

*Sort Algorithms**Search Algorithms**Hashing**Dynamic Programming*

**We’ll briefly cover each one.**

Sort Algorithms: My favourite! To put it simply, we use sort algorithms to try arrange items in a list with a particular order. Merge Sort, Quick Sort, Bucket Sort, Heap Sort, and Counting Sort are all powerful techniques to grasp. It is important to note that learning is not the biggest part when dealing with algorithms. Knowing when and where to use them in use cases is what matters most. *Remember, practice makes perfect!*

Search Algorithms: These algorithms are made to retrieve or check for a given element in a data structure (e.g. list). With a quick google search on “search algorithm examples” you’ll see a list of them. Each search algorithm works with different data structures and are used for different use cases. For example, earlier in this article we looked at the *binary search algorithm. This algorithm is used when working with linear data structures. *Don’t worry if this doesn’t make sense to you. Main takeaway is that search algorithms help locate data easily and save the developer a lot of time and effort.

Hashing: You might’ve heard this term in the world of computer science a lot. This is because it is one of the most used techniques in finding data by “key” or “ID”. We call it “Hash-Map”, “Hash-Table” or Dictionary and it is called those terms since it maps keys to values. If you have no idea what “keys” and “values” are, here is a simple look at it with Python.

dictExample = {1: ‘USA’, 2: ‘Canada’, 3: ‘Malaysia’}

**My numbers** are the **keys** and the ** countries** are my

**. Idea is that I can get “USA” by simply calling for “1”. This is what we call**

*values**key-value pair mapping.*You can probably imagine how much time this saves by now!

Dynamic Programming (DP): “Dynamic Programming” sounds very complex but it’s actually a very simple concept. The idea is to break a complicated problem into several easier sub-problems and remembering the results to get to the final solution. Let’s give an example to make our understanding more firm.

*Let’s say a friend asks you “Hey! What’s 2 + 3 + 4 + 5?”.*

*For that you will add the numbers together and answer 14 right?*

*Now he says “Add + 6 to the end of the sequence. Now tell me the answer”.*

*You would immediately remember that “2 + 3 + 4 + 5” was 14 so adding 6 to the sequence is nothing but adding “14 + 6” and you’ll quickly answer “it’s 20!”.*

*As a result of you remembering, you were able to solve quickly and more efficiently. This technique is Dynamic Programming.*

From personal experience these 4 categories of algorithms have appeared in some way or another in every project and work of mine. It is beneficial to learn more about this by reviewing other sources but now you should have a preliminary understanding of how algorithms work in programming.

# Conclusion

**Congrats! You’ve reached the end!**

This article did take a more technical turn but hopefully I was able to show you the importance and beauty of algorithms in programming. Learning algorithms is definitely not a MUST in order to develop programs but it can take you so far if you do so.

Algorithms are really fun to learn so why not give it a shot!

As always, please feel free to leave any remarks, comments and suggestions on the article. If you’d like to reach me, please contact me at barathvelmu@gmail.com. Have a wonderful day :)