Should it be in math?
If you are trying to sort with an array of sorting bubbles, it is already sorted, then you can check if this movement through the array checks something. If not, everything is okey - we are done.
Moreover, for the best case you will have an O (n) -composition (n-1, to be precise), for the worst case (an inverse array) you will have O (n ^ 2) -selections (n โโ(n-1) ) / 2, to be precise).
More complex example. Find the maximum element of the array. Obviously, you will always do n-1 fights, but how many tasks are there on average? Complex math answers: H (n) -1.
This is usually easy for your best and worst scenarios in Answerget, but on average a lot of math is required.
I would advise you to read Whip, Volume 1. But who would not?
And the formal definition:
f (n) โO (g (n)) means the existence of nโN: for all m> nf (m)
In fact, you should read the O-notation about wikis.
source share