Challenge: Find All Paths Between Two Nodes
Given a graph, find all paths that exist between two nodes.
We'll cover the following
Problem statement
Implement a function that prints all paths that exist between two nodes (source to destination).
Input
A graph, a source value, and a destination value
Output
A 2D list having all paths
Sample input
Graph:
Vertex | Edges |
---|---|
0 | 1, 2 |
1 | 3, 4 |
2 | 5 |
3 | 5 |
4 | 5 |
5 | None |
source = 0 destination = 5
Sample output
The output should be a list of lists. Each list indicates a path between two nodes.
result = [[0, 2, 5],
[0, 1, 4, 5],
[0, 1, 3, 5]]
Level up your interview prep. Join Educative to access 70+ hands-on prep courses.