how to calculate Bubble sort Time Complexity

前端 未结 7 1244
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-05 12:29

I was trying to understand the Data Structure and different algorithm, then i got confused to measure the Bubble sort time complexity.

for (c = 0; c < ( n         


        
相关标签:
7条回答
  • 2020-12-05 12:56

    O(n^2) = n(n-1)/2 is the right one.

    As in the above example of 5 elements.

    5(5-1)/2 == 10.
    
    5(5+1)/2 != 10. 
    
    0 讨论(0)
提交回复
热议问题