Python 3 version
Formal definition:
Formal definition:
Formal definition:
Couting inversion means that
Finding "similarity" between two rankings. Given a sequence of n numbers 1..n (assume all numbers are distinct). Define a measure that tells us how far this list is from being in ascending order. The value should be 0 if
Utilized linearity of Expectation and decomposition principle
Rule of thumb for checking independene of random variables:
So, for those of you without much practice with independence, here's my rule of thumb for whether or not you treat random variables as independent. If things are independent by construction, like, for example, you define it in your algorithm, so the two different things are independent. Then you can proceed with the analysis under the assumption that they're independent. If there's any doubt, if it's not obvious the two things are independent, you might want to, as a rule of thumb, assume that they're dependent until further notice.
A good exercise is the birthday problem with the solution in Introduction of Algorithms