Graph algorithms implementation