Skip to content

Instantly share code, notes, and snippets.

@0xKD
Created November 23, 2014 03:35
Show Gist options
  • Save 0xKD/8e30ceb411b67772af56 to your computer and use it in GitHub Desktop.
Save 0xKD/8e30ceb411b67772af56 to your computer and use it in GitHub Desktop.
Simple Complexity chart (IPython notebook & matplotlib)
import math
import matplotlib.pyplot as plt
%matplotlib inline
a = range(1,100)
b = map(lambda x:x*math.log(x,2), a)
c = map(lambda x:x*x, a)
d = map(lambda x:2**x, a)
p = plt.figure()
sbp = p.add_subplot(1,1,1)
sbp.plot(a,b,'r', label=r'$n\log n$')
sbp.plot(a,a,'b', label=r'$n$')
sbp.plot(a,c,'c', label=r'$n^2$')
sbp.plot(a,d,'m', label=r'$2^n$')
sbp.set_ylim([0, 1000])
sbp.legend(loc=1)
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment