graph methods from thinkcomplexity