function = bubblesort(X)
% Bubble sort implementation
len = length(X);
S=X;
% t0=tic;
sorted = false;
while (~sorted)
sorted = true;
for i=1:len-1
if S(i) > S(i+1)
tmp = S(i);
S(i) = S(i+1);
S(i+1) = tmp;
sorted = false;
end
end
end
0% t1=toc;
% runtime = t0-t1;
Good evening everyone. i am doing a algorithm analysis of this simple bubble sort and I am looking for the proper way to do the probability of the if function occurring in its total n loops. Any suggestions are welcome. Thank you.
% Bubble sort implementation
len = length(X);
S=X;
% t0=tic;
sorted = false;
while (~sorted)
sorted = true;
for i=1:len-1
if S(i) > S(i+1)
tmp = S(i);
S(i) = S(i+1);
S(i+1) = tmp;
sorted = false;
end
end
end
0% t1=toc;
% runtime = t0-t1;
Good evening everyone. i am doing a algorithm analysis of this simple bubble sort and I am looking for the proper way to do the probability of the if function occurring in its total n loops. Any suggestions are welcome. Thank you.