Hi, ineed to analize some bubble sort algorithms for a special project, and calculate the probability of each, while, if, for statements. Please help me
bubble sort analysis and probability
Page 1 of 16 Replies - 1065 Views - Last Post: 14 December 2012 - 09:08 PM
Replies To: bubble sort analysis and probability
#2
Re: bubble sort analysis and probability
Posted 13 December 2012 - 02:31 PM
special project.. homework.
What language is it in?
Have you written the bubblesort yet?
What language is it in?
Have you written the bubblesort yet?
#3
Re: bubble sort analysis and probability
Posted 13 December 2012 - 02:33 PM
Its on matlab, ill write them down for u
#4
Re: bubble sort analysis and probability
Posted 13 December 2012 - 02:43 PM
function [S] = bubblesortWMem(X)
% Bubble sort implementation with memory
len = length(X);
S=X;
% t0=tic;
sorted = false;
last=1;
while (~sorted)
sorted = true;
for i=last:len-1
if S(i) > S(i+1)
tmp = S(i);
S(i) = S(i+1);
S(i+1) = tmp;
sorted = false;
last=i;
end
end
end
% t1=toc;
% runtime = t0-t1;
function [S] = bubblesortSE(X)
% Bubble sort implementation with Stop Early
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;
break
end
end
end
% t1=toc;
% runtime = t0-t1;
function [S] = 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
% t1=toc;
% runtime = t0-t1;
function [S] = bubblesortWMemSe(X)
% Bubble sort implementation with memory and Stop Early
len = length(X);
S=X;
% t0=tic;
sorted = false;
last=1;
while (~sorted)
sorted = true;
for i=last:len-1
if S(i) > S(i+1)
tmp = S(i);
S(i) = S(i+1);
S(i+1) = tmp;
sorted = false;
last=i;
break
end
end
end
% t1=toc;
% runtime = t0-t1
Its 4 different codes
This post has been edited by macosxnerd101: 14 December 2012 - 12:12 PM
Reason for edit:: Please use code tags
#5
Re: bubble sort analysis and probability
Posted 13 December 2012 - 03:19 PM
Please help
#6
Re: bubble sort analysis and probability
Posted 14 December 2012 - 07:34 PM
What do you mean by calculate the probability of each while, if, and for statement?
Doesn't the fact that a particular keyword exists in an implementation indicate that it has a probability of 100%?
Doesn't the fact that a particular keyword exists in an implementation indicate that it has a probability of 100%?
#7
Re: bubble sort analysis and probability
Posted 14 December 2012 - 09:08 PM
Algorithms aren't analyzed based on the probability of an if statement, but rather on their efficiency. Bubblesort has a runtime complexity of O(n^2), regardless of your implementations.
Page 1 of 1
|
|

New Topic/Question
Reply


MultiQuote







|