Source: https://ocw.mit.edu/courses/6-006-introduction-to-algorithms-spring-2008/aa3e9625cd91ee9a3c93944f340fcaa1_lec24.pdf