Learnerslesson
   JAVA   
  SPRING  
  SPRINGBOOT  
 HIBERNATE 
  HADOOP  
   HIVE   
   ALGORITHMS   
   PYTHON   
   GO   
   KOTLIN   
   C#   
   RUBY   
   C++   
   HTML   
   CSS   
   JAVA SCRIPT   
   JQUERY   




ALGORITHMS

Algorithms can be defined as step by step instructions to solve a problem.


Example :

Say you are asked to add two numbers. Now, steps needed to add these numbers is an algorithm .

Below is the algorithm :


1. Get the first number from the user.

2. Get the second number from the user.

3. Add two numbers.

4. Give the result back to the user.


Looks simple. But we might also have complex algorithms that solves puzzels like Rubik Cube .


Now, just think for a moment. We might also have a simpler way of writing an algorithm. i.e. A puzzle can be solved by many ways. There can be bad ways and good ways as well.


What is an efficient Algorithm ?

So, we are writing Algorithms from Computer Science perspective. Now, an efficient Algorithm would be the one which solves a problem taking minimum space (i.e RAM) and would take minimal time to solve it.


Just imagine, you wanted to search something in google and you got the result after 5 minutes. To make our life easier goole engineers write the most efficient algorithms, so that we get the search results within mili seconds.


How do we measure the running time of an Algorithm?


And we are done checking the efficiency of an Algorithm .


But the above technique comes with certain disadvantage. i.e. The system in which we will be testing this program might be slow or a fast computer. And depending on that the efficiency of our Algorithm will vary, which we don't want.


A better solution to find the efficiency of an Algorithm .

We can find the efficiency of an Algorithm by inspecting each and every operations closely.

i.e.


1.  Say a program can have assignment operation


   int x = 10;.

2.  Can have a loop


  while(x<15) {
   ...
  }

3.  Also it can have branching operation


  if(x==9) {
   ...
  }

By counting all the above operations in a program, we can determine the time taken by the algorithm .


We will make it simpler in the next lesson when we learn about sorting.