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

BFS vs DFS Explained: How to Search a Graph (and Escape a Maze)

Bitwise Tales

0:00 / 0:00

BFS vs DFS Explained: How to Search a Graph (and Escape a Maze)

110 просмотров · 1 день назад
Bitwise Tales
36 подписчиков
110 просмотров · 1 день назад
Two explorers, one maze. One dives as deep as it can and takes 24 steps; the other spreads out like a ripple and takes 4. This animated explanation shows what a graph is (nodes and edges, directed and weighted), how to store one (adjacency matrix vs adjacency list), and how depth-first search and breadth-first search explore it, step by step on a network of seven friends. Plus: why you need a "seen" set, why BFS marks nodes when they join the queue, why BFS finds the shortest path, Java code for both, O(V + E), when to use which, the classic "number of islands" interview question, and where graph search shows up in the real world. Chapters: 0:00 Intro: one maze, two explorers 0:47 What a graph is 1:36 Storing a graph: adjacency matrix 1:57 Adjacency list 2:16 Depth-first search 3:28 Breadth-first search and the queue 4:53 Back to the maze: why BFS finds the shortest path 5:32 DFS vs BFS: O(V + E) and memory 6:12 Interview: number of islands 7:00 Who invented them 7:28 Graph search in the real world 8:02 Recap in one breath Bitwise Tales: tech explained like a story, not a textbook.