I don't know if bubble sort is optimal under the condition that only adjacent swaps are allowed? Is there a more optimal algorithm that can directly determine the parity of the minimum number of swaps without performing the actual sorting?
Note that there may be duplicates in the sequence, so a trivial swap number may have a different parity than the minimum number.
You can assume that the sequence is full of positive integers, allowing non-adjacent comparisons, but for the actual sorting operation, only the exchange of two adjacent numbers is allowed.