I know there are two ways to represent my graph: one is using a matrix, and the other one is using a list.
If I use a matrix, I have to flip all the bits in the matrix.
Since I see a couple of comments asking about an in place graph transpose (reversal), here is my version of it. Please note this will only work on DAGs.Feedback and suggestions for improvement would be welcome
def transpose(G):
"""
Return the transpose of a directed graph i.e. all the edges are reversed (In Place)
"""
#note this is not a standard lib function afaik and you would have to
#implement topological sort but that should be easy
topsort = topological_sort(G)
topsort.reverse() # we want to process starting from sink node
for v in topsort:
for node in G[v]:
G[node].append(v)
# remove all older members of the vertex 'v'
G[v] = []
print(G)