Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
100% found this document useful (1 vote)
58 views

Analysis of Algorithm

Uploaded by

sayan.pal.23
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
58 views

Analysis of Algorithm

Uploaded by

sayan.pal.23
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Design and Analysis of Algorithm

Topperworld.in

Analysis of Algorithm

• Analysis of algorithms is the process of finding the computational


complexity of any algorithm.
• By computational complexity, we are referring to the amount of time
taken, space, and any other resources needed to execute(run) the
algorithm.
• The goal of algorithm analysis is to compare different algorithms that are
used to solve the same problem.
• This is done to evaluate which method solves a certain problem more
quickly, efficiently, and memory-wise.

❖ Types of Algorithm Analysis:


There are four types of analysis of algorithms. They are stated below :
➢ Best case
➢ Average case
➢ Worst case
➢ Amortized analysis
Let us look at each of them in detail.

©Topperworld
Design and Analysis of Algorithm

Best Case Analysis of Algorithms


• The best case analysis of algorithms gives us the lower bound on the
running time of the algorithm for any given input.
• In simple words, it states that any program will need at least (greater
than or equal to) that time to run.
For example, suppose we have an algorithm that has the best case time
complexity is O(N), then we can say that the program will take a minimumof
O(N) time to run, it can never take sometime less than that.
The best case time or space complexity is often represented in terms of the
Big Omega (Ω) notation.

Now suppose, the number you are searching for is present at the very
beginning index of the array. In that case, your algorithm will take O(1) time
to find the number in the best case. So, the best case complexity for this
algorithm becomes O(1), and you will get your output in a constant time.

Worst Case Analysis of Algorithms


• The worst-case analysis of algorithms gives us the upper bound on the
running time of the algorithm for any given input.

©Topperworld
Design and Analysis of Algorithm

• In simple words, it states that any program will need maximum that
time (less than or equal to) to run.
For example, suppose we have an algorithm that has the worst-case time
complexity is O(N ^2), then we can say that the program will take a maximum
of O(N ^2 ) time to run, for an input of size N it can never take more time than
that to run.
The worst-case time or space complexity is often represented in terms of the
Big Oh (O) notation.

In this example, the target element is 10, which is located at the end of the
array. The linear search function has to iterate through the entire array before
finding the target at the last index. This scenario represents the worst-case
time complexity of a linear search algorithm, which is O(n), where n is the
length of the array.

©Topperworld
Design and Analysis of Algorithm

Average Case Analysis of Algorithms


• As the name suggests, the average case analysis of algorithms takes
the sum of the running time on every possible input, and after that, it
takes the average.
• So, in this case, the execution time of the algorithm acts as both the
lower and upper bound.
• In simple terms, we can get an idea of the average running time of the
algorithm through it.
• Generally, the average case of the algorithms is as high as the worst-
case running of it.
• Hence, it roughly gives us an estimation of the worst case itself.
• The average case time or space complexity is often represented in
terms of the Big theta(Θ) notation.

©Topperworld
Design and Analysis of Algorithm

In the average-case analysis, we assume that the target element is equally


likely to be at any position in the array. In an unsorted array, each position
has a 1/n probability of containing the target element.
The average-case time complexity is then calculated by considering the
average number of comparisons made by the algorithm. In a linear search,
the average number of comparisons is approximately n/2. This is because, on
average, the target is expected to be found after examining half of the array.

Amortized Analysis of Algorithms


• The amortized analysis of the algorithms mainly deals with the overall
cost of the operations.
• It does not mention the complexity of any one particular operation in
the sequence.
• The total cost of the operations is the major focus of amortized
analysis.
• In times when only a few operations are slow but a majority of other
operations are quicker, we perform an amortized analysis.
• Through this, we return the average running time per operation in the
worst case

©Topperworld

You might also like