I understood the whole implementation, however at 7:05 duration, it is said that the parent of the node should not be equal to the neighbor. I didn’t really understand this part. Please explain.
Undirected Graph Is a Tree or Not
hello @gptradhika1208
consider this ->
1–2--3–4
let say u started running dfs from 1 so u marked it visited then u checked for its neighbors .
it is 2 and not visited , so u call on 2, now again from u check all its neigbour (1 and 3).
here 1 is visited right? as per logic visited neigbour node means cycle right? ,but it fails here why? becuase 1 is parent node.
so here we have 2 things to consider for cycle ->
a) neighbour node must be visited
b) it should not be a parent node