Given an array $A$ of $N$ integers, each element in the array can be increased by a fixed number $b$ with some probability $p[i]$, $0 \leq i < n$. I have to find the expected number of swaps that will take place to sort the array using bubble sort.
I've tried the following:
The probability for an element $A[i] > A[j]$ for $i < j$ can be calculated easily from the given probabilities.
Using the above, I have calculated the expected number of swaps as:
double ans = 0.0; for ( int i = 0; i < N-1; i++ ){ for ( int j = i+1; j < N; j++ ) { ans += get_prob(A[i], A[j]); // Computes the probability of A[i]>A[j] for i < j.
Basically I came to this idea because the expected number of swaps can be calculated by the number of inversions of the array. So by making use of given probability I am calculating whether a number $A[i]$ will be swapped with a number $A[j]$.
Note that the initial array elements can be in any order, sorted or unsorted. Then each number can change with some probability. After this I have to calculate the expected number of swaps.
I have posted a similar question before but it did not had all the constraints.
I did not get any good hints on whether I am even on the right track or not, so I listed all the constraints here. Please give me some hints if I am thinking of the problem in an incorrect way.