Implementation of some graph algorithms and KMP in Python