This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: [10][7][2][11][14][38] void sort( int a, int n){ int I,j; for(i=0;i<n1;i++) for(j=i+1;<n;h++){ if(a[i]>a[j]){ int temp =a[i]; a[i]=a[j]; a[j]=temp; } } bubble sort int main(void) { int i; int a={38,7,14,2,11,10}; sort(a,6); for (i=0;i<6;i++) printf(“%d\n”,a[i])’ return 0; } time complexity outer loo: for(i=0;i<n=1;i++) overall time up to A(overhead)+B(n1), increment & test + repeat body n1 times inner loop for(j=i+1;j<n;j++) time C(overhead) + D ( n(i+1))> depends on total time (up to) A+B(n1) + c(n1) + D((n1)+(n2)+…1) =A + (B+C)(n1) + D sum, I to n1, i =A + (B+C)(n1) + Dn(n^1)/2 =O(n^2)...
View
Full Document
 Fall '10
 Clarke
 Computer Science, Bubble Sort, Insertion Sort, Big O notation, main(void), body n1 times

Click to edit the document details