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