# Analysis of Algorithms

Last updated on September 4th, 2023 at 09:49 pm

Here, We will learn about algorithms analysis, types of analysis – priori and posterior analysis, how to two compare algorithms, algorithm complexity – time complexity and space complexity, runtime analysis of algorithms.

### Algorithms Analysis:

Algorithms Analysis help us to determine which algorithms are more efficient.

The goal of algorithms analysis is to compare algorithms in terms of running time and space consumed.

Efficiency of an algorithm can be analyzed at two different stages, before implementation and after implementation. They are following :

#### Priori Analysis :

This is a theoretical analysis of an algorithm. Efficiency of an algorithm is measured by assuming that all other factors, for example, processor speed, are constant.

#### Posterior Analysis :

This is an empirical analysis of an algorithm. The selected algorithm is implemented using programming language and then executed on target computer machine. In this analysis, actual statistics like running time and space required, are collected.

Running time of an operation can be defined as number of computer instructions executed per operation.

### Types of Analysis in Algorithm

To analyze the given algorithms, we need to know with which inputs the algorithms takes less time (performing well) and with which inputs the algorithms takes a long time.

There are three types of analysis:

1. Worst Case: Defines the input for which the algorithm takes a long time (slowest time to complete).
2. Best Case: Defines the input for which the algorithm takes the least time (fastest time to complete).
3. Average Case: Provides a prediction about running time of the algorithms with random inputs.

### How to Compare two Algorithms?

To compare algorithms, few objective are :

1. Execution times ? execution times are specific to a particular computer.
2. Number of statements executed ? the number of statements varies with the programming language as well as the style of the individual programmer.
3. Ideal solution ? running time of a given algorithm as a function of the input size n (i.e., f(n))

### Algorithm Complexity

Efficiency of an algorithm is depend upon time and space used by the algorithm.

Space Complexity How much memory is used?

Time Complexity – How many primitive operations are executed?

#### Space Complexity:

Space Complexity of an algorithm represents the amount of memory space required by algorithm in its life cycle.

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 which depends on instance characteristics I.

#### Time Complexity :

Time Complexity of an algorithm represents the amount of time required by the algorithm to run to completion.

Computational Time is T(n) = c*n where c is the time taken for addition of 2 bits and n is the number of steps.

### Runtime Analysis of algorithms

Running time analysis is the process of determining how processing time increases as the size of the input elements increases.

Some common types of inputs are :

• Size of an array
• Polynomial degree
• Number of elements in a matrix
• Number of bits in the binary representation of the input
• Vertices and edges in a graph.

### Want to Contribute:-

If you like “To The Innovation” and want to contribute, you can mail your articles to 📧 contribute@totheinnovation.com. See your articles on the main page and help other coders.😎

Scroll to Top