A problem can have
many algorithms and an algorithm can have many programs of one language as well
as different languages.
A good algorithm:
1.
It must be time-efficient.
2.
It uses less space.
3.
solves problems in the minimum possible results.
4.
uses a minimum resource to reach the solution.
5.
It must be easily understood:
6.
can be maintained at a minimum cost.
7.
It must be flexible.
8.
manages all types of exceptions and errors.
9.
is self-sufficient.
10. can be applied to a
wide variety of similar problems.
11. should be balanced.
According to Coreman's
book, algorithms are just like technology. We all use the latest and greatest
processors but we need to run implementations of the good algorithms on that computer
to properly take benefit of the money that we spent to have the latest
processor.
Example – Computer A running
a sorting algorithm whose running time grows like n2 against a
slower computer B running a sorting algorithm whose running time grows like n
log n.
They each must sort an array of 10 lakh numbers. (Input n is 10 lakh numbers)
Computer A | Computer B |
---|---|
Executes 100 crore instruction per sec |
Executes 1 crore instructions per sec |
Algorithm for Computer A requires n^2 instructions |
Algorithm for Computer B requires 25nlogn instructions |
Time taken = ((10^6)^2)/10^9 |
Time taken = 25(10^6 log10^6)/10^7 |
It will take 16.66 minutes | It will take 15 seconds |
1 Comments
thanks sir
ReplyDelete