elementary graph algorithms