0% found this document useful (0 votes)
2 views

Algorithm complexity

The document discusses the analysis of algorithms, emphasizing the importance of efficiency through Priori and Posterior analysis. It defines algorithm complexity in terms of space and time, detailing how to calculate both types of complexity. Space complexity considers fixed and variable memory requirements, while time complexity assesses constant and variable execution times.

Uploaded by

Sneha Soni
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Algorithm complexity

The document discusses the analysis of algorithms, emphasizing the importance of efficiency through Priori and Posterior analysis. It defines algorithm complexity in terms of space and time, detailing how to calculate both types of complexity. Space complexity considers fixed and variable memory requirements, while time complexity assesses constant and variable execution times.

Uploaded by

Sneha Soni
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Analyse an Algorithm

For a standard algorithm to be good, it must be efficient. Hence the efficiency


of an algorithm must be checked and maintained. It can be in two stages:
1. Priori Analysis:
“Priori” means “before”. Hence Priori analysis means checking the algorithm
before its implementation. In this, the algorithm is checked when it is written in
the form of theoretical steps. This Efficiency of an algorithm is measured by
assuming that all other factors, for example, processor speed, are constant and
have no effect on the implementation. This is done usually by the algorithm
designer. This analysis is independent of the type of hardware and language of
the compiler. It gives the approximate answers for the complexity of the
program.
2. Posterior Analysis:
“Posterior” means “after”. Hence Posterior analysis means checking the
algorithm after its implementation. In this, the algorithm is checked by
implementing it in any programming language and executing it. This analysis
helps to get the actual and real analysis report about correctness (for every
possible input/s if it shows/returns correct output or not), space required, time
consumed, etc. That is, it is dependent on the language of the compiler and the
type of hardware used.

What is Algorithm complexity and how to find it


Complexity of an algorithm is defined by the amount of Space and Time it
consumes. Hence the Complexity of an algorithm refers to the measure of the
time that it will need to execute and get the expected output, and the Space it
will need to store all the data (input, temporary data, and output). Hence these
two factors define the efficiency of an algorithm.

The two factors of Algorithm Complexity are:


complexity of an algorithm can be divided into two types:
1. Space Complexity: The space complexity of an algorithm refers to the
amount of memory required by the algorithm to store the variables and get the
result. This can be for inputs, temporary operations, or outputs.
How to calculate Space Complexity?
The space complexity of an algorithm is calculated by determining the
following 2 components:
 Fixed Part: This refers to the space that is required by the algorithm. For
example, input variables, output variables, program size, etc.
 Variable Part: This refers to the space that can be different based on the
implementation of the algorithm. For example, temporary variables,
dynamic memory allocation, recursion stack space, etc.
Therefore Space complexity S(P) of any algorithm P is S(P) = C + SP(I),
where C is the fixed part and S(I) is the variable part of the algorithm,
which depends on instance characteristic I.

2. Time Complexity: The time complexity of an algorithm refers to the


amount of time required by the algorithm to execute and get the result. This can
be for normal operations, conditional if-else statements, loop statements, etc.
How to Calculate, Time Complexity?
The time complexity of an algorithm is also calculated by determining the
following 2 components:
 Constant time part: Any instruction that is executed just once comes
in this part. For example, input, output, if-else, switch, arithmetic
operations, etc.
 Variable Time Part: Any instruction that is executed more than once,
say n times, comes in this part. For example, loops, recursion, etc.
 Therefore Time complexity of any algorithm P is T(P) = C + TP(I),
where C is the constant time part and TP(I) is the variable part of the
algorithm, which depends on the instance characteristic I.

You might also like