http://www.inf.ed.ac.uk/teaching/courses/dmmr/slides/14-15/Ch6.pdf