algorithm 4th edition python implementation