Depth First Search – Traversal Of The Graph

A Quick Overview

DFS is an algorithm for traversing a graph by exhaustively visiting all nodes. It involves moving forward on path until there are no more unvisited nodes, then backtracking or move on to unvisited path.

Introduction to Depth First Search (DFS)

Given an undirected, unweighted graph, print the DFS traversal of the graph.

Problem Statement

1. Start at any node, such as the root node.  2. Mark the current node as visited. 3. If immediate children of the node are not visited, recursively call function for that child.

Algorithm

Time Complexity: O(|V| + |E|), where V = no. of vertices, E = no. of edges  Space Complexity: O(|V|)

Time and Space Complexity

How to implement this approach in different programming languages?