# What is an Algorithm...?

Now , this is something you can easily get on the google search.

But let us talk about what is an algorithm in simple words so that every one can understand.

So an algorithm is basically a list of some steps for achieving something. These steps should strictly followed in sequential order that is one after the another.

let us take real life example to understand it even better. let suppose you want to go from one location to another location. You will first get out of your house , then take a cab or a taxi to desired location and then pay the driver his fees step out of the car and reach your location successfully right.

Now imagine can you randomly follow the above steps to reach your desired location successfully...? The answer is no you can't do that. in order to reach your location you first have to get out of your location then search for the taxi and so on and so fourth. you can't first reach your desired location by walking and then paying the taxi driver and then booking it , right.

it will all become a mess , and even if you achieve your desired result here it won't be the best way for achieving it.So i hope it is clear now that what is an algorithm , an algorithm is a sequence of steps that is being performed for achieving desired result.

## What is Consensus Algorithm...?

Now , in the above image you can see different types of Algorithm but i am going to talk about Consensus Algorithm i have used for my blockchain development that uses Proof of Work to mine new blocks.

So a consensus algorithm is something that provides us a way for comparing one node with another inside the whole network to know whether the data on the node is correct or not.

Now different blockchain use different consensus Algorithm but what i have used is also being used by the BITCOIN blockchain network itself.

So the algorithm follows the longest chain rule.

## Longest chain rule and it's Advantages

In longest chain rule , the chain on the current node is compared to all of the other nodes chain in the network present.

So while comparison if a longer chain is found in the network then the chain that was initially being compared with all the other chains is replaced by the longest chain found.

In the above image you can see a ataacker trying to send three blocks together to the network but as soon as these blocks are recieved they ll follow the longest chain rule and get replaced by the longest chain reducing the chances of attacker to be successful.

So why is the chain being replaced by the longest chain...?

It is because the longest chain on the network is that chain to which every node must have contributed and that's why the number of blocks in this chain is more.

As it has the more number of blocks that would have mined using proof of work , we can assume that the whole network contributed to this node because of how muc work went into this chain.

So , obviously longest chain rule in our consensus algorithm also protects the blockchain from attackers as well.

So that's it for today , i hope i was able to explain this concept well and everyone here would have learnt something new.

Thank you , se you all soon with my next post.