G = [ [0,0,1,0,1,1,0], [0,0,1,1,0,1,0], [1,1,0,1,1,1,0], [0,1,1,0,0,0,0], [1,0,1,0,0,0,1], [1,1,1,0,0,0,0], [0,0,0,0,1,0,0] ] visited = [ 0 for i in range(len(G)) ] def DFS(G, current): visited[current] = 1 print(current, end=" ") for i in range(len(G)): if G[current][i] == 1 and visited[i] == 0: DFS(G, i) DFS(G, 0)