`

complexity of judging n numbers is sorted or not

阅读更多
my analysis:
n! permutations.
i times comparation for a permutation.
i=1: 1*sikma(k=n to 2)* C(k-1,1)*(n-i-1)! comparations
...
i=t: t*sikma(k=n to i+1)*C(k-1,t)*(n-t-1)!
...
i=n-1: (n-1)*sikma(k=n to n)*C(k-1,n-1)*(n-(n-1)-1)!=n-1

so the answer is:

sikma(t=1 to n-1)[ (t*sikma(k=n to i+1)*C(k-1,t)*(n-t-1)! ) ] / n!

<!-- google_ad_client = "pub-4697687764463140"; //龙思csdn博客之adsense, 创建于 07-12-11 google_ad_slot = "9918311208"; google_ad_width = 728; google_ad_height = 15; //-->
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics