Algorithms can be defined as step by step instructions to solve a problem.
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.
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.
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.
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
2. Can have a loop
3. Also it can have branching operation
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.