Перейти к содержимому

Is Graph Bipartite – LeetCode 785 in Kotlin | Graphs from Zero Ep 5

SeniorMobileDev

0:00 / 0:00

Is Graph Bipartite – LeetCode 785 in Kotlin | Graphs from Zero Ep 5

18 просмотров · 2 нед. назад
SeniorMobileDev
89 подписчиков
18 просмотров · 2 нед. назад
Is Graph Bipartite (LeetCode 785) in Kotlin: can you split a graph into two groups so that every edge goes across? We paint it with only two colors using BFS. The visited array from the last episodes becomes a color array (0 = not visited, 1 = red, -1 = blue), so the opposite color is just minus the color. Then we add one edge and see why an odd cycle makes a graph NOT bipartite. Graphs from Zero (Kotlin) series: Ep 1 · DFS and BFS:    • Graph for beginners (Ep 1)   Ep 2 · Grids:    • Grid Graphs Problems in Kotlin (Graphs fro...   Ep 3 · Find if Path Exists (LeetCode 1971):    • Find if Path Exists in Graph | Graphs from...   Ep 4 · Number of Provinces (LeetCode 547):    • Count Groups Straight From the Matrix | Gr...   Next: Clone Graph (LeetCode 133) Chapters 0:00 Is Graph Bipartite (LeetCode 785) 0:05 The problem: split nodes into two groups 0:38 Paint with two colors · visited becomes color 1:14 Dry run: BFS coloring 2:12 Add one edge: the odd cycle 2:45 Kotlin code 3:17 Time and memory #leetcode #kotlin #graphs #bfs #dsa