https://www.cs.stevens.edu/~jschauma/615/s16-hw3.html and https://www.cs.stevens.edu/~jschauma/cgi-bin/CS615-04.cgi