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.


Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -