Algorithm
Algorithm
Algorithm
It’s simply an implementation of an algorithm in the form of annotations and informative text written in plain
English. It has no syntax like any of the programming language and thus can’t be compiled or interpreted by the
computer.
Designing an Algorithm: Once the problem is cleared then a solution method for solving the
problem has to be analyzed. There may be several methods available for obtaining the required
solution. The best suitable method is designing an Algorithm. To improve the clarity and
understandability of the program flowcharts are drawn using algorithms.
Coding: The actual program is written in the required programming language with the help of
information depicted in flowcharts and algorithms.
Development Of An Algorithm
Debugging: There is a possibility of occurrence of errors in program. These errors must be removed for proper working of programs. The process of
checking the errors in the program is known as ̳Debugging‘.
Syntactic Errors: They occur due to wrong usage of syntax for the statements.
Ex: x=a*%b
Here two operators are used in between two operands.
Runtime Errors : They are determined at the execution time of the program
Logical Errors : They occur due to incorrect usage of instructions in the program. They are neither displayed during compilation or execution
nor nor cause any obstruction to the program execution. They only cause incorrect outputs.
Development Of An Algorithm
Testing and Validating: Once the program is written , it must be tested and then
validated. i.e., to check whether the program is producing correct results or not for
different values of input.
Documentation and Maintenance: Documentation is the process of collecting,
organizing and maintaining, in written the complete information of the program for
future references.
Maintenance is the process of upgrading the program, according to the changing
requirements.
ALGORITHM COMPLEXITY
Suppose X is an algorithm and n is the size of input data, the time and space used by the algorithm
X are the two main factors, which decide the efficiency of X.
● Time Factor − Time is measured by counting the number of key operations such as
comparisons in the sorting algorithm.
● Space Factor − Space is measured by counting the maximum memory space required by
the algorithm.
The complexity of an algorithm f(n) gives the running time and/or the storage space required by the
algorithm in terms of n as the size of input data.
Space Complexity
Space complexity of an algorithm represents the amount of memory space required by the algorithm in its life cycle. The space
required by an algorithm is equal to the sum of the following two components −
● A fixed part that is a space required to store certain data and variables, that are independent of the size of the problem. For
example, simple variables and constants used, program size, etc.
● A variable part is a space required by variables, whose size depends on the size of the problem. For example, dynamic
memory allocation, recursion stack space, etc.
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. Following is a simple example that tries to explain the concept −
Algorithm: SUM(A, B)
Step 1 - START
Step 2 - C ← A + B + 10
Step 3 - Stop
Here we have three variables A, B, and C and one constant. Hence S(P) = 1 + 3. Now, space depends on data types of given
variables and constant types and it will be multiplied accordingly.
Time Complexity
Time complexity of an algorithm represents the amount of time required by the algorithm to
run to completion. Time requirements can be defined as a numerical function T(n), where
T(n) can be measured as the number of steps, provided each step consumes constant time.
For example, addition of two n-bit integers takes n steps. Consequently, the total
computational time is T(n) = c ∗ n, where c is the time taken for the addition of two bits. Here,
we observe that T(n) grows linearly as the input size increases.
ALGORITHM ANALYSIS
Efficiency of an algorithm can be analyzed at two different stages, before implementation and
after implementation. They are the following –
We shall learn about a priori algorithm analysis. Algorithm analysis deals with the execution or
running time of various operations involved. The running time of an operation can be defined as
the number of computer instructions executed per operation.
ALGORITHM ANALYSIS
Analysis of an algorithm is required to determine the amount of resources such as time and
storage necessary to execute the algorithm. Usually, the efficiency or running time of an
algorithm is stated as a function which relates the input length to the time complexity or space
complexity.
Algorithm analysis framework involves finding out the time taken and the memory space required
by a program to execute the program. It also determines how the input size of a program
influences the running time of the program.