Introduction To Algorithms

What is Algorithm?
Algorithm is some sequence of steps which are required to be executed in order to solve problems. We can solve a particular problem in numerous ways, we always try to achieve the best way we can find using our knowledge and intellect.
One can perceive algorithm as devising a recipe, a fast way of cooking the same thing.
Lets see a simple algorithm for filling water in a bottle, how will you achieve it? What do you require? How can you do it efficiently? How much time will it take? Lets start the preparation of the algorithm.

Algorithm 1:
  1. Turn on the knob.
  2. Take the bottle.
  3. Put the bottle below the tap.
  4. After the bottle fills remove it from below the knob.
  5. Turn off the knob.

Algorithm2:
  1. Take the bottle.
  2. Put the bottle below the tap.
  3. Turn on the knob.
  4. Keep it on until it fills.
  5. Turn off the knob.


As you can see, from the above example there are numerous ways to do the same thing but finding efficient algorithms is our main goal. We want to improve efficiency as well as productivity and speed of our algorithm. A simple change in algorithm can change a lot in the performance of algorithm, for e.g., if we interchange the steps 2 and 3 we would waste a lot of water , hence reducing our efficiency and thus productivity. Now the question arises why do you need to learn algorithms for becoming a computer scientist, or a computer engineer? 
Well, base of a computer scientist is algorithms. The better the algorithm a computer scientist develops the better computer scientist he is, well it basically tells how efficient you are. It tells your thinking capability, and it makes your work more and more efficient. 

There are different approaches for achieving good results, (note:- one cannot rely only on those algorithm techniques , remember algorithm is thinking, fast in a unique way and a faster way…). Some of the approaches in algorithm are, Divide and conquer, Dynamic Programming, Randomisation, etc.

Divide and Conquer:
In divide and conquer, we try to break and solve the problem. It makes the problem easier and easier and thus improving efficiency, for e.g. suppose you have been given two numbers, 225 and 740, how can you add these numbers up with ease? In basic level? 700+200 , 40+20, 5
Now we just add up these three subproblems… its easy right? Thats divide and conquer…

Dynamic programming:
In Dynamic programming, we keep track of a memo table, like a notebook if we have already seen similar problem before we use the memo table to find the answer…
Classic example of Dynamic programming would be for finding fibonacci series , we keep previous and a number before previous number in the memo table to find the nth term. 
e.g. for finding 4th term, 
0, 1, 1, 2
Now we know for 4th term is 2 and 3rd term is 1. We write it down in the memo table.
Now when we calculate next number, eg 7th term, we can calculate from 4th term. Thats not the optimal way but you can get the sense of how Dynamic Programming works. 


Randomisation:- Randomisation is a process in which we use some special randomised algorithm, we will see this topic in detail out ahead…



In Brief:

Algorithms is a cookbook, your recipe, you need to develop a recipe that utilise as much as Resources available to us. that is called a great algorithm. There are different topics inside of Algorithms and different methods into which we will dig deep slowly and steadily.

Written By, Sarvesh Bhatnagar.

Popular Posts