100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached 4.2 TrustPilot
logo-home
Class notes

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

Rating
-
Sold
-
Pages
3
Uploaded on
04-03-2023
Written in
2022/2023

When analyzing an algorithm, we often consider its best case, worst case, and average case scenarios. The best case scenario is the input that results in the fastest running time, while the worst case is the input that results in the slowest running time. The average case is the expected running time when input is randomly distributed. These analyses can help us understand the performance of an algorithm under different circumstances. It's important to note that the worst case scenario is usually the most important, as it guarantees that the algorithm will never perform worse than a certain running time.

Show more Read less
Institution
Course








Whoops! We can’t load your doc right now. Try again or contact support.

Written for

Course

Document information

Uploaded on
March 4, 2023
Number of pages
3
Written in
2022/2023
Type
Class notes
Professor(s)
Sanket salvi
Contains
All classes

Subjects

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
$2.99
Get access to the full document:

100% satisfaction guarantee
Immediately available after payment
Both online and in PDF
No strings attached

Get to know the seller
Seller avatar
sanketsalvi

Also available in package deal

Get to know the seller

Seller avatar
sanketsalvi Freelancer
Follow You need to be logged in order to follow users or courses
Sold
0
Member since
2 year
Number of followers
0
Documents
3
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

Frequently asked questions