![]() |
VOOZH | about |
Given a Directed Graph and two vertices src and dest, check whether there is a path from src to dest.
Example:
Consider the following Graph: adj[][] = [ [], [0, 2], [0, 3], [], [2] ]
👁 Lightbox
Input : src = 1, dest = 3
Output: Yes
Explanation: There is a path from 1 to 3, 1 -> 2 -> 3
Input : src = 0, dest = 3
Output: No
Explanation: There is no path from 0 to 3.
The idea is to start from the source vertex and explore as far as possible along each branch before moving backFind if there is a path between two vertices in a directed graphFind if there is a path between two vertices in a directed graph. If during this traversal we encounter the destination vertex, we can conclude that there exists a path from source to destination.
Step by step approach:
Yes
The idea is to start from the source vertex and explore all neighboring vertices at the present depth before moving on to vertices at the next level.
Step by step approach:
Yes