Depth First Search (DFS)

Published on
Embed video
Share video
Ask about this video

Scene 1 (0s)

Depth First Search (DFS). Graph Traversal Algorithm.

Scene 2 (11s)

Graphs in Computer Science. A graph is a non-linear data structure consisting of nodes (vertices) and edges Vertices represent entities, edges represent relationships Graphs can be: Directed (edges have direction) Undirected (no direction) Used in: Social networks Maps & navigation Dependency systems Represented as: G = (V, E).

Scene 3 (27s)

Introduction to Depth First Search. [image] DFS Source Node Output: O, 1. 4. 5, 2. 6, 3, 7.

Scene 4 (47s)

DFS Traversal Example. Consider a graph with nodes: A, B, C, D Edges: A–B, B–D, A–C Starting from node A, DFS traversal is: A → B → D → C DFS explores one path completely before moving to another.

Scene 5 (1m 3s)

DFS and the Stack Data Structure. DFS uses a Stack (LIFO – Last In, First Out) The most recently visited node is explored first Helps in backtracking when no unvisited nodes remain DFS can be implemented using: Stack (iterative method) Recursion.

Scene 6 (1m 17s)

[image] unmark au t be Ct•xose any unmark Mark •E Stop do-ot it z R G throuö R.

Scene 7 (1m 33s)

DFS Pseudocode. [image]. DFS can be written using a recursive approach It follows the idea of visiting a node and exploring its neighbors A visited array ensures nodes are not revisited DFS(v): mark v as visited for each neighbor u: if u is not visited: DFS(u).

Scene 8 (1m 48s)

Complete DFS Code Structure. Code: #include <vector> using namespace std; vector<int> adj[100]; bool visited[100]; void DFS(int v).

Scene 9 (1m 58s)

Time and Space Complexity of DFS. Time Complexity: O(V + E) Space Complexity: O(V) Efficient for traversing large graphs Visits each vertex and edge only once.

Scene 10 (2m 11s)

Applications of Depth First Search. Maze solving and path finding Cycle detection in graphs Web crawling and search engines Game AI and decision making Topological sorting in directed graphs Finding connected components in a graph Detecting strongly connected components Solving puzzles like sudoku and backtracking.