Presentation is loading. Please wait.

Presentation is loading. Please wait.

Complexity of a Bubble Sort

Similar presentations


Presentation on theme: "Complexity of a Bubble Sort"— Presentation transcript:

1 Complexity of a Bubble Sort
How many comparisons are made on each pass? n-1 n-2 n-3 2 1 How many comparisons are made altogether? = [(n-1) + 1](n-1) / 2 Sum of an arithmetic series = [n2 - n] / 2 = n2 /2 - n/2 = O(n2 ) [n2 /2 is the dominant term and the coefficient 1/2 may be ignored - it is just some constant]

2 Suppose n = 10, n2 /2 = 50,000,000 n/2 = ,000 Suppose n = 1,000, n2 /2 = 500,000,000,000 n/2 = ,000 If n = 1,000,000,000 n2 /2 = 500,000,000,000,000,000 n/2 = ,000,000


Download ppt "Complexity of a Bubble Sort"

Similar presentations


Ads by Google