Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我了解到冒泡排序的比较次数是
(n - 1) + (n - 2) + (n - 3) + ... + 2 + 1
怎么会变成这样?
(n - 1) * n/2
你能解释一下吗?
总和
1 + 2 + 3 + 4 + .... + n = n * (n + 1)/2
所以总和
1 + 2 + 3 + .. + (n-1) = (n - 1) * n/2