Types of Algorithms analysis

To analyse the given algorithm we need to know on which inputs the algorithm will takes less time and long time. We have already seen that an algorithm can be represented in the form of an expression.  That means we represent the algorithm with multiple expressions: one of the case where it takes less time and other for the case where it takes the more time.
In general the first case is called the ‘Best Case’ and second case is called the ‘Worst Case’ of the algorithm. To analyse an algorithm we need some kind of syntax and that forms the base for asymptotic analysis/notation.


There are three types of analysis:
  1. Worst Case:
    • Defines the input for which the algorithm takes long time.
    • Input is the one for which the algorithm runs the slower.
  2. Best Case:
    • Defines the input for which the algorithm takes lowest time.
    • Input is the one for which the algorithm runs the fastest.
  3. Average Case:
    • Provides a prediction about the running time of the algorithm.
    • Assumes that the input is random.
Lower Bound <= Average Time <= Upper Bound
For a given algorithm, we can represent the best, worst and average cases in the form of expression. As an example, let f(n) be the function, which represents the given algorithm.

                    f(n) = n2 + 500, for worst case
                    f(n) = n + 100n + 500, for best case

Similarly for average case too. The expression defines the inputs with which the algorithm takes the average running time f(n).

Popular posts from this blog

Hibernate auto increment with example

how to count the page views by using JSP

Multithreading in java with example

How to retrieve data from table by using JDBC with example

Prime, Fibonacci and Factorial number with example in java

How to insert images into database using JDBC?

How to sort list of objects in java with examples

String interview questions and answers

Exception in thread "main" java.lang.NoClassDefFoundError: javax/transaction/SystemException

Store file into table by using JDBC with example