Algorithm
Published: 2021-05-27 22:30:00

An algorithm has been such a pain in the neck for me since the course began. It made me feel back in time when I was 13 and started learning complex math at school.

I did not think the meaning of algorithm until now, or rather, I  did not have a space in my brain to wonder.
So, I researched.
<br>
**What is an algorithm?** -- It is a way and procedure to solve problems.
It sounds very mathematical. However, you are using algorithms in your everyday life.

When you go to school, you
1. leave your house.
2. walk to a train station.
3. take a train.
4. get off the train.
5. walk to school.

When you want to make a sandwich, you
1. peel and wash lettuce.
2. slice tomato.
3. paste mayonnaise on breads.
4. put lettuce and tomato on a bread.
5. sandwich with another bread.

Just like these examples, we use algorithms unconsciously.
When coding, it can be illustrated as if you are telling someone to cook pasta, and this person doesn't know how to cook.
In this case, the person is a computer and your direction is a code.
Okay, it sounds less scary now.
<br>
**What is it used for in our daily lives?** --Many many things.
They range from dating apps to solar panels on ISS. Probably, the most popular one is Google search.

Google search uses an algorithm to optimise search result. It is updated on a regular basis and number of variables is enormous. It is almost impossible to understand all.

Another one that we use often is a navigation app. It searches the fastest route to go to one place from another.

Social networks such as twitter and Facebook also uses an algorithm to show information that is assumed to be important to you. This information is based on what you post, your friends and browsing history.

Lastly, dating apps, which are similar to the above. They gather data from you, whether you like someone tall/short, with/without beard, outgoing/stay-at-home type, etc. Based on these, a computer suggests people you might like.
<br>
**More detailed explanation**
Let's pick navigation apps to take a look in detail. The algorithm used for navigation is called Dijkstra method.

Here is how it works:
A is the current location and E is the destination. Numbers are time that needed to go to each nodes connected with paths.
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wwh6yyp7b8po0xxla0ed.png)

1. There are three paths from node A, and we look for the closest node.
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jz39v9bso5mrb1k0taug.png)

2. The closest is node D. From there, there is only one path. So we calculate time, which is 5 + 9 = 14.
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wgu14ahxg5ceog6rnn0t.png)

3. Second closest node is B. There are two paths, but we can go to node C directly from A. In this case, we discard that path and only calculates the path to E, 6 + 6 =12. The sum is smaller than 14, so we keep this route as the fastest.
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fylifs95844uk5rcmbwr.png)

4. We do the same with third path from node A. We can go to node B directly from A, and only the path to node E is calculated, which is 8 + 5 = 13. This route is also longer than the one before.
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qewa86tph73k28ulvcf9.png)

5. The result will be A - B - E route.
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/c3po81yd2wc8v6h4p8um.png)
<br>
**Knowing what algorithms are used for gave me a clear view to study them.**
There are tons of things that can be done with them and they make me wonder what I can do in the future.
<br>
**One last thing before going back to studying...*
While researching, I suddenly recalled a song that is played in a TV show for toddlers in Japan. The song is called "Algorithm Koshin" (Algorithm March).
One website taught me that this march falls into a pipeline processing. It reduces time for running algorithm, and it is also used for improving CPU capability.
<br>
It is surprising that I could learn algorithm from a song!