14 Cycle Detection In Undirected Graph Using DFS | Graph

Опубликовано: 11 Октябрь 2024
на канале: Aditya Verma
449
21

Code and explanation: https://www.patreon.com/posts/14-cycl...

Practice Link: https://www.geeksforgeeks.org/problem...

Given an undirected graph with V vertices labelled from 0 to V-1 and E edges, check whether it contains any cycle or not. Graph is in the form of adjacency list where adj[i] contains all the nodes ith node is having edge with.

NOTE: The adjacency list denotes the edges of the graph where edges[i] stores all other vertices to which ith vertex is connected.

Examples:

Input: V = 5, E = 5
adj = [[1], [0, 2, 4], [1, 3], [2, 4], [1, 3]]
Output: 1
Explanation:
------------------------------------------------------------------------------------------
Here are some of the gears that I use almost everyday:

🖊️ : My Pen (Used in videos too): https://amzn.to/38fKSM1
👨🏻‍💻 : My Apple Macbook pro: https://amzn.to/3w8iZh6
💻 : My gaming laptop: https://amzn.to/3yjcn23
📱 : My Ipad: https://amzn.to/39yEMGS
✏️ : My Apple Pencil: https://amzn.to/3kMnKYf
🎧 : My Headphones: https://amzn.to/3kMOzM7
💺 : My Chair: https://amzn.to/385weqR
🛋 : My Table: https://amzn.to/3TyU2IU
⏰ : My Clock: https://amzn.to/3slFUV3
🙋🏻‍♀️ : My girlfriend: https://amzn.to/3M6zLDK ¯\_(ツ)_/¯

PS: While having good gears help you perform efficiently, don’t get under the impression that they will make you successful without any hard work.