Written by students who passed Immediately available after payment Read online or as PDF Wrong document? Swap it for free 4.6 TrustPilot
logo-home
Summary

Summary Best Case, Worst Case and Average Case Analysis of an Algorithm

Rating
-
Sold
-
Pages
2
Uploaded on
23-02-2023
Written in
2022/2023

Information about Best Case, Worst Case, and Average Case Analysis of an Algorithm can be referred to by the student who starts to learn the basics of Data Structures and Algorithms. DSA PART 4

Institution
Course

Content preview

Best Case, Worst Case and Average Case Analysis of an Algorithm
To define an algorithm, To define the events in the life of an algorithm , We have , Best Case
Worst Case and Expected Case. And along with that, I 've packed one more thing into this
video : The definition of Log. If you watch this video till the end , Then you will find out what this
'Log ' really is. 1. . . 5. . . 7. . . 9 and 24 are the numbers in it; They 're in ascending order , You
can see for yourself. If you know even a bit of maths, You 'll know that it is in an ascending order.
Now what I say is that I 'll give a number : 'A' And I 'd like you to tell me If this number exists
within the array , or not. Suppose the value of A is 8. So what will be your answer ? Yes.
Meaning 1. If A is. . . Sorry, your answer will be no , because it is n't there. If the value is 9, What
will the answer be ? Your answer will Algo 1 is a simple person. It does n't have much of a brain.
It is comparing it with all the numbers. Is this the best way to do this work ? Obviously not.
Because Algo. 1 is lucky , He will get A=1. It will tell us in the first comparison itself. In one
comparison only.


If Algo 1 is in luck, The time needed is ' k ' - T=k. This means that it does n't depend on 'n '. Take
a 10-element array, take a single element array or take a 10,000 element array. It only has to
make one comparison because it is only searching for the first element in the array. Now, AlGo 1
's luck is bad. Till now, he was fortunate ; But now he 's not so lucky anymore. Average Case
complexity is equal to. . . the sum of the run time for the total number of possibilities. The O
( Sum of all possible run times divided by the number of possibility ) is O ( n ) The average case
complexity is the sum. Average Case is equal. to. . . The sum of all. possible run. times divided.
by the total. number of possible run time. So for an array size of 5, We saw six cases. 't ' ; I 'll
calculate ' O ' later. n+1 If 'n ' is the size of the array , Then there is 'n+1 '' number of
possibilities. 'n' possibilities is when there is 1st element, 2nd element, 3rd element, 4th
element, 5th element and 6th element. If the element is here, How many comparisons will it
have to make ? It will have to do. . . 1. . . 2. . . 3 comparisons. I 've taken ' k ' as common out of
everything. I removed this because this is different. And this I have added separately.


AP is Arithmetic Progression and GP is a geometric progression. AP is used in 'O ' a lot. APs are
made as well as GPs sometimes. When there are questions on 'O' APs and GPs are used in the
answers to questions on O. The formula of Average Case Complexity is All possible run times
divided by the total number of possibilities. The Average Case Time is not generally asked for a
unique algorithm. It can be asked for this type of algorithm , A simple algorithm that compares
all of these. So what is the Average Case. Complexity ? O ( n ). Algo 1 was making 'n '
comparisons. Now we 'll see how many comparisons this will make. Algo 2 is a cunning person.
It will match the first and last element and match it first. It made one comparison For a size of
10 array , As well as for an array of size 100. It is making the same comparison for all sizes of
array.


The midpoint between 1 and 100 will be 50. Then you will discard this entire array that has
elements greater than 50. If there are an even number of elements here, there are 2-2-4,2-6

Written for

Course

Document information

Uploaded on
February 23, 2023
Number of pages
2
Written in
2022/2023
Type
SUMMARY

Subjects

$8.49
Get access to the full document:

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Get to know the seller
Seller avatar
adityashrivastav

Get to know the seller

Seller avatar
adityashrivastav Thakur College of Science and Commerce
Follow You need to be logged in order to follow users or courses
Sold
-
Member since
3 year
Number of followers
0
Documents
8
Last sold
-

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions