Explanation for the article: www.geeksforgeeks.org/detect-c... This video is contributed by Illuminati.
Пікірлер: 42
@BrianKeeganMusic6 жыл бұрын
Honestly the best video I have seen on this so far. Other videos did not explain the parent node.
@GeeksforGeeksVideos6 жыл бұрын
Thanks Brian Keegan :)
@asadsbhatti5 жыл бұрын
Sir , aap nain kamaaal kr dyaa........... What a Explanation.....!
@ionuttrif83783 жыл бұрын
I made a function that detect if there is a cycle in a graph using bfs, but i don't know how to make it print the members of the cycle, any tips?
@ishitamittal15463 жыл бұрын
Does this code work for non continuous graph?
@nitishgupta68025 жыл бұрын
Isn't it sufficient to check that if the number of edges in the connected graph is more than n-1 (where n is the number of vertices), then it must have a cycle.
@evapine27954 жыл бұрын
no
@brkekr3 жыл бұрын
@Ash Win Yes I totally agree with you, but in the case that E>n-1, that would be a smart move to place an if to check whether it has more than n-1 edges at the very beginning of the function isCyclicUtil.
@tarekadel76312 жыл бұрын
This approach makes assumptions that may not hold true: 1) The graph is connected --> But it could have more than 1 connected component 2) Edges >= Vertices
@parishapranayraj99786 жыл бұрын
can you please put the proof of correctness of the algorithm .
@greerhanshaw7 жыл бұрын
Thanks for the great video!
@GeeksforGeeksVideos7 жыл бұрын
You're welcome, Greer! :)
@MushafAli-rc2su Жыл бұрын
A great explanation thankfull to you❤
@kmishy2 жыл бұрын
3:00 Should you change it to- For any visited vertex
@parthgupta50584 жыл бұрын
wouldnt it just stuck in an infinite loop if there is an edge with u v equal
@coderbuddy38753 жыл бұрын
Nice explanation 👍
@mohitsoni49255 ай бұрын
It will be better if we also explain why the statement is sufficient enough to justify a cycle in graph. This will help us to not memorise the statement but visualise it.
@mohammedelhag7565 Жыл бұрын
thank you, appreciate the hard work
@shubhammalhotra7244 Жыл бұрын
For every visited vertex v, if there is an adjacent u. Such that u is already visited & u is not the parent of v. So, cycle in the graph is present/
@mujtabaamer65425 жыл бұрын
What is the output
@ela23163 ай бұрын
true if there's a cycle otherwise false
@anirudhreddybasani35555 жыл бұрын
Then why didn't we used the same logic for directed graphs..there we've used a recursion stack and here we're just using a parent variable...
@soumavanag50255 жыл бұрын
Anirudh reddy Basani consider the following directed graph and do a dry run: (1,2),(2,3),(1,3) Note: there is no directed edge in undirected graph, so tracking of parent is enough which is not the case in directed graphs.
@Aditya-pl3xg2 жыл бұрын
you can all you need to do is run a dfs for each vertex in a loop and that's it. actually this way will cover for case of both the undirected graph (since it'll exit in first iteration itself) and for non-connected graphs too. (but don't tell GfG of this common sense they will write a shitty code full of classes and OOPS on their website that'll confuse everyone 😁)
@rohitk26294 жыл бұрын
Wrong! After backtracking from 1 to 0. 0 will again check its each connected node if its visited or not. since 1 is visited and not parent it will return true.
@sumanthchakravarthi68533 жыл бұрын
why would you check for 1 again it will move to 2 right?
@brkekr3 жыл бұрын
Well it does not; because in isCyclicUtil, the first if checks if there is any UNVISITED node, if yes, it recurs from there without evaluating the else if (else if checks if there is a visited children, what you said would be true in case of else-if and if statements swapping places )
@vaibhavimacherla16036 жыл бұрын
it checks only for triangles???
@LawZist6 жыл бұрын
i would like also to know
@KjellBoeije6 жыл бұрын
It detects a cycle whenever a node has a child node that's already visited, and is not it’s parent. If I'm correct this would work for cycles with any number of nodes.
@GalibFida5 жыл бұрын
the cycles in this graph are triangles but they don't have to be cycle of three vertices; a cycle can have any number of vertices and this algorithm will still work
@akhilvegunta62634 жыл бұрын
No it will check for any figure if it forms a cycle.
@hamidansari93314 жыл бұрын
@@akhilvegunta6263 you r late
@xuantungnguyen97192 жыл бұрын
your code failed in this case g = Graph(3) g.addEdge(1, 2) g.addEdge(2, 3) g.addEdge(3, 1)
@sjrohan4042 Жыл бұрын
bahut loud video hai🤣
@jdleanne4 жыл бұрын
This is wrong. He is indeed using BFS not DFS, as it was traversing around the neighbor
@kasyapdharanikota85702 жыл бұрын
i also felt that he is using bfs instead of DFS
@dylankrejci996510 ай бұрын
@@kasyapdharanikota8570 this graph is kinda weird in that the way its laid out, BFS and DFS are essentially the same. It's DFS in the sense that each node visited follows directly from its parent, but the organization of this particular graph also means that you are in a sense checking the parent and then all of its children in order. The best way to distinguish from within the context of this video is the fact that the parent of node 4 is 3, whereas in BFS it would be 2. Hope this helps
@adnanhaque1871Ай бұрын
@@dylankrejci9965 well BFS uses a queue FIFO while DFS uses stack LIFO. so not the same!