Tuesday, 13 October 2015

Necessity of Algorithms

Algorithms play a great role solving problems in faster and easier ways...

With the introduction, you might be wandering, why the hell you would study another subject and stuff your brain with knowledge...

Well, if I tell you that there are many things you do on a day to day basis, those you do by following an algorithm, then ?

Hmm, baking a cake is following an algorithm, I agree.
What about a more simple stuff like applying shampoo on your hair ?

HOW ???
Well, most of the shampoo container comes with the instruction to wash your hair, something like: wet hair, lather, rinse, repeat

Do you find the consequence and the problem with the algorithm ?
You are most likely to be running out of your shampoo and your time.

How ?
Well, as a human being, you can assume that, you have to repeat just once. So, this works fine for you. But computers have no brain to think or assume. Just take a look on this article.

Consequently, it fails for a computer and you are most likely to avoid this algorithm.

Ohh no, all my works are gone ?
Of course not, you can think better strategy and device a new algorithm.

Can you think an alternative ?
What about this one, wet hair, lather, rinse, repeat once ?

Perfect one.

Feeling happy to device the new algorithm ?

Well,  what did I do ? Can you call it an algorithm ?
Yes, it is a modified algorithm which considers a boundary to the steps to be followed. So, it is an algorithm.

Wow !!!
Yeah, exactly the same feeling I had when I first solved this problem in the days of my algorithm classes.

Seriously, when you think of anything, you get a better way to do it. Not only this simple Shampoo Algorithm, you everyday perform executions of lots of other algorithms as well. Only thing is that, you do not know that it was an algorithm. Again, if you think closely to subject, you can find better algorithms to solve a problem.

So, what are the criteria it should meet to be an algorithm ?
You simply has to find the answers, if you find all the answers as 'YES', it is an algorithm.
  • Is it unambiguous? 
  • Does it have defined inputs and outputs? 
  • Is it guaranteed to terminate? 
  • Does it produce the correct result? 

Now my question to you is, how am I going to be benefited by algorithms ?
Well, there are multiple reasons, you should know about algorithms. When you study about algorithms, your work is influenced by the knowledge you gain. So you will always try to find a better way to do your stuffs.
Let's discuss with some examples,
  • First of all, take the shampoo algorithm. If the wrapper editor would have thought about the problem himself, he was supposed to device the modified algorithm.
  • In many situations, you have to work with collections of data. You can decide which one to use, an Array, a List or a Queue depending on the requirement. Assuming you will be using a list, which one is better in that, a linked list or Hashed Linked List etc.
  • How you achieve a requirement with less number of operations or memory usage.
  • How to device an algorithm for a better unique key design.
And many more you can do with the knowledge of algorithms.

In fact, there are many real time applications that use algorithms to get the output in minimal steps and minimal resource use.
Below are some,
  1. How does Google find billions of search results that too most perfect according to your need ?
    Google use PageRank algorithm.
  2. How does Hangout/Skype sends/receives video over network so fast ?
    They use Compression algorithm.
  3. How does Facebook maintains so many user data and that too perfectly ?
    Facebook use News Feed Algorithm.
So, you see, whatever you think is very complex, there always remains a algorithm to help the stuff and team always to improve their algorithms to stick to the market.

Well, most of the times you will not find a direct impact of Algorithmic study in your coding. Because, almost all the popular language comes with built in API to deal with the stuffs like searching, hashing, sorting etc. But you will find yourself writing a better implementation.

Well, if time permits for you, take a look into this video

Prev   Next

Palash Kanti Kundu

Monday, 12 October 2015

Introduction to Algorithms

Let's try to gain some knowledge on Algorithm...

Hey what ?
Al-go-rith-um ?

Yes, You have correctly pronounced it.
And take a note, 'An algorithm is just another recipe.'

Recipe for what ?

Are you going to teach me different cake baking recipes ?
Not at all. I am not going to teach you how to cook a good mutton dish or bake a Chocolate Cake. Instead I am going to discuss something related to Programming.

Hey Palash, have you gone out of your mind ?
No dear, I am completely in a stable state of my mind and  I am writing this article with all my senses working.

Then how can a programming stuff be a recipe ?
Well, if you think of any recipe, it eventually becomes a set of steps to follow with some ingredients, to give you a delicious food/drink.

Wait, let me think of that Chocolate Shake.

  • Take a glass of milk
  • Take some sugar
  • Take some ice
  • Take some Cocoa Powder
  • Mix sugar into milk
  • Continuously stir the sugar into the milk until the sugar gets dissolved
  • Mix some cocoa powder into the milk
  • Continuously stir the sugar into the milk until the powder gets dissolved and the content becomes thick
  • Add ice cubes into the milky solution
  • Sprinkle some coca powder as toppings
Hmm, you are correct. It is a set of some steps which involves some ingredients.
Oh dear, I am glad that you are agreeing with me and thanks for confirming that to me.

But, what's the point here ? How it is related to programming ?
It is 100% related. Just take look on this article to know why.

Hmm, it is good to know that a program runs my computer and my computer has nothing special without it. Now I understand why you are repeatedly telling about recipe.

Great !!!

Now, again if you think, how many ways you know to perfectly blend a deliciously glass of Chocolate Shake, you will know what algorithm is.

Hmm, I have a better alternatives to make chocolate shake.

Hmm, not only the banana shake recipe, we use different algorithms for our day to day activities.Just go through this article. You will get some funny examples to compare with.

With all these keeping in mind, let's dive into a formal informal definition of Algorithm,

Algorithm: Informally, an algorithm is any well-defined computational procedure that takes some value, or set of values, as input and produces some value, or set of values, as output. An algorithm is thus a sequence of computational steps that transform the input into the output.

Well, with this, I am going to put an end for the day. We'll discuss more in our subsequent sessions.

Keep watching this space for more !!!
Palash Kanti Kundu