def isCyclicUtil(graph,v,visit,parent):
visit[v]= True
for i in graph[v]:
if visit[i]==False :
if(isCyclicUtil(graph,i,visit,v)):
return True
elif parent!=i:
return True
return False
def isCyclic(graph,n):
visited =[False]*(n)
for i in range(n):
print(visited,i)
if visited[i] == False:
if(isCyclicUtil(graph,i,visited,-1)) == True:
return True
return False
print(isCyclic({0: [1], 1: [0], 2: [3, 4], 3: [2, 4], 4: [3, 2]},5))
At each iteration visited array is updated
OUTPUT:
index : 0 visited array : [False, False, False, False, False]
index : 1 visited array : [True, True, False, False, False]
index : 2 visited array : [True, True, False, False, False]
In the above code, values of visited array are being changed without any explicit modification to the visited array. what is the reason behind this?