runtime analysis of bubble sort similar algorithm -
i'm having lot of trouble finding running time of following algorithm. thank if me solve explicitly line per line corresponding cost , amount of times executed. biggest problem calculating amount of times while-loop executed. algo: (a,n) tmp = 0; ready = 0; = n-1 1 if a[i-1]>a[i] temp=a[i-1]; a[i-1] = a[i]; a[i] = tmp; ready = 1; = 1 n-1 if a[i-1]>a[i] temp=a[i-1]; a[i-1] = a[i]; a[i] = tmp; ready = 1; while ready = 1; thank much the worst case bubble sort o(n^2). the problem bubble sort n times iterate whole array. the amount of times , rest sounds home me.