Find if Path Exists in Graph | Graphs from Zero Ep 3
SeniorMobileDev
0:00 / 0:00
Find if Path Exists in Graph | Graphs from Zero Ep 3
19 просмотров · 3 нед. назад
SeniorMobileDev
89 подписчиков
19 просмотров · 3 нед. назад
Find if Path Exists in Graph (LeetCode 1971) explained step by step in Kotlin. The graph comes as an edge list, so first we build an adjacency list (both directions), then run BFS from the source and check if we reach the destination. We also see why BFS is safer than recursive DFS here (n can be 200,000), and we dry run every step of the queue and the visited array.
Graphs from Zero (Kotlin) playlist:
Ep 1 · BFS and DFS Explained: • Graph for beginners (Ep 1)
Ep 2 · Grid Graphs (Number of Islands, Rotting Oranges): • Grid Graphs Problems in Kotlin (Graphs fro...
Ep 3 · Find if Path Exists in Graph (this video)
▶ Next: Number of Provinces (LeetCode 547): • Count Groups Straight From the Matrix | Gr...
Chapters
0:00 Find if Path Exists in Graph
0:06 The problem
0:34 Same graph, different disguise
1:09 Build the adjacency list
1:38 DFS or BFS?
2:11 Dry run 0 → 2
2:48 Dry run 0 → 5
3:07 Kotlin code
3:48 Time and memory
Time: O(V + E) · Memory: O(V + E)
#leetcode #kotlin #graphs #bfs #dsa