Chapter Two - DS Algorithm Analysis
Chapter Two - DS Algorithm Analysis
Algorithm Analysis
What is an Algorithm?
• An algorithm is a process or a set of rules required to perform calculations
or some other problem-solving operations especially by a computer.
• Performance: The real-world is not easily broken down into smaller steps.
If the problem can be easily broken into smaller steps means that the
problem is feasible.
Algorithm - a real-world example
• Suppose we want to make a lemon juice, so following are the steps required to make a lemon
juice:
• Step 1: First, we will cut the lemon into half.
• Step 2: Squeeze the lemon as much you can and take out its juice in a container.
• Step 3: Add two tablespoon sugar in it.
• Step 4: Stir the container until the sugar gets dissolved.
• Step 5: When sugar gets dissolved, add some water and ice in it.
• Step 6: Store the juice in a fridge for 5 to minutes.
• Step 7: Now, it's ready to drink
Factors of an Algorithm
• The following are the factors that we need to consider for designing an algorithm:
• Modularity: If any problem is given and we can break that problem into small-small modules or small-
small steps, which is a basic definition of an algorithm, it means that this feature has been perfectly
designed for the algorithm.
• Correctness: The correctness of an algorithm is defined as when the given inputs produce the desired
output, which means that the algorithm has been designed algorithm. The analysis of an algorithm has
been done correctly.
• Maintainability: Here, maintainability means that the algorithm should be designed in a very simple
structured way so that when we redefine the algorithm, no major change will be done in the algorithm.
• The following are the factors that we need to consider for designing an
algorithm:
• Robustness: Robustness means that how an algorithm can clearly define our problem.
• User-friendly: If the algorithm is not user-friendly, then the designer will not be able to
• Extensibility: If any other algorithm designer or programmer wants to use your algorithm
• Search: Algorithm developed for searching the items inside a data structure.
• Delete: Algorithm developed for deleting the existing element from the data structure.
• Update: Algorithm developed for updating the existing element inside a data structure.
Algorithm Analysis
• The algorithm can be analyzed in two levels, i.e., first is before
creating the algorithm, and second is after creating the algorithm.
• The following are the two analysis of an algorithm:
1. Priori Analysis: Here, priori analysis is the theoretical analysis of an
algorithm which is done before implementing the algorithm. Various factors
can be considered before implementing the algorithm like processor speed,
which has no effect on the implementation part.
• From the above calculation, it is observed that most of the time is taken by 12.
• But, we have to find the growth rate of f(n), we cannot say that the maximum amount of time is taken by 12.
How to calculate f(n)?
• Let's assume the different values of n to find the growth rate of f(n).