Created
April 12, 2011 16:58
-
-
Save jweslley/915913 to your computer and use it in GitHub Desktop.
Running time of common time complexities
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
big_O.plot <- function(count,log="") { | |
n <- seq(count) | |
plot(n, n*n, log=log, type='l', col='red', | |
ylab="Running time", xlab='n (# of elements)') | |
lines(n, n*log(n), col='green') | |
lines(n, n, col='blue') | |
lines(n, log(n), col='black') | |
title('Running time of common time complexities') | |
legend('topleft', lty=1, cex=0.8, inset=.025, | |
title='Big O notation', | |
c( | |
expression(paste("O(", n^2, ")")), | |
expression(paste("O(", n*log(n), ")")), | |
expression(paste("O(", n, ")")), | |
expression(paste("O(", log(n), ")")) | |
), | |
col=c('red','green','blue','black') | |
) | |
} | |
png('time_complexity_10.png') | |
big_O.plot(10) | |
png('time_complexity_1000.png') | |
big_O.plot(1000) | |
png('time_complexity_10000.png') | |
big_O.plot(10000) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment