rotated head/tail order in graph methods, added topological_sort() function