% bigO functions
% calculate and plot several functions used in comparing growth rates

figure

n = 1:100;          % the x axis
y1 = n-n+1;			% O(1)
y2 = log2(n);		% O(log2(n))
y3 = n;				% O(n)
y4 = n.*log2(n);	% O(nlog2(n))
y5 = n.^2;			% O(n^2)
y6 = 2.^n;			% O(2^n)

plot(n,y1,'y','LineWidth',2)
hold on
plot(n,y2,'r','LineWidth',2)
plot(n,y3,'g','LineWidth',2)
plot(n,y4,'b','LineWidth',2)
plot(n,y5,'m','LineWidth',2)
plot(n,y6,'c','LineWidth',2)

legend('O(1)','O(log_2 n)','O(n)','O(n log_2 n)','O(n^2)','O(2^n)',2)

hold off
