| written 6.8 years ago by |
An algorithm is a set of steps of operations to solve a problem performing calculation, data processing, and automated reasoning tasks. An algorithm is an efficient method that can be expressed within finite amount of time and space.
An algorithm is the best way to represent the solution of a particular problem in a very simple and efficient way. If we have an algorithm for a specific problem, then we can implement it in any programming language, meaning that the algorithm is independent from any programming languages.
PERFORMANCE ANALYSIS
Performance analysis of an algorithm depends upon two factors i.e. amount of memory used and amount of compute time consumed on any CPU. Formally they are notified as complexities in terms of:
- Space Complexity.
- Time Complexity
.Space Complexity of an algorithm is the amount of memory it needs to run to completion i.e. from start of execution to its termination. Space need by any algorithm is the sum of following components:
1. Fixed Component: This is independent of the characteristics of the inputs and outputs. This part includes: Instruction Space, Space of simple variables, fixed size component variables, and constants variables.
2. Variable Component: This consist of the space needed by component variables whose size is dependent on the particular problems instances(Inputs/Outputs) being solved, the space needed by referenced variables and the recursion stack space is one of the most prominent components. Also this included the data structure components like Linked list, heap, trees, graphs etc.
Therefore the total space requirement of any algorithm 'A' can be provided as Space(A) = Fixed Components(A) + Variable Components(A)
Example: Space Complexity
Algorithm Sum(number,size)\ procedure will produce sum of all numbers provided in 'number' list
{
result=0.0;
for count = 1 to size do \will repeat from 1,2,3,4,....size times
result= result + number[count];
return result;
}
Time Complexity of an algorithm(basically when converted to program) is the amount of computer time it needs to run to completion. The time taken by a program is the sum of the compile time and the run/execution time .
The compile time is independent of the instance(problem specific) characteristics. following factors effect the time complexity:
Characteristics of compiler used to compile the program.
Computer Machine on which the program is executed and physically clocked.
Multiuser execution system.
Number of program steps.
Therefore the again the time complexity consist of two components fixed(factor 1 only) and variable/instance(factor 2,3 & 4), so for any algorithm 'A' it is provided as:
Time(A) = Fixed Time(A) + Instance Time(A)
Here the number of steps is the most prominent instance characteristics and The number of steps any program statement is assigned depends on the kind of statement like
Example: Time Complexity
In above example if you analyze carefully frequency of "for count = 1 to size do" it is 'size +1' this is because the statement will be executed one time more die to condition check for false situation of condition provided in for statement.

and 5 others joined a min ago.