#search #iot #C #esp32 #sorts #bigo #shots #dfs Depth-first search (DFS) is a search algorithm that explores as far as possible along each branch before backtracking. The basic idea behind DFS is to start at a given vertex (or node) and explore as deep as possible along each branch before backtracking. The algorithm uses a stack to keep track of the vertices to be visited and a visited array to keep track of the vertices that have already been visited. The basic structure of the DFS algorithm is as follows. Here, the DFS() function takes a starting vertex v, an adjacency list adj, and a visited array visited as its input. The function marks the current vertex as visited, prints it, and then recursively calls itself for each adjacent vertex that has not been visited yet. DFS has a time complexity of O(V plus E) where V is the number of vertices, and E is the number of edges in the graph. In the worst case, DFS may take O(V degree 2) time if the graph is represented as an adjacency matrix. DFS is useful for traversing a graph, finding a path between two nodes, solving puzzles like mazes, and other problems that require exhaustive search of a tree or graph. It can be used to solve various problems such as finding the number of connected components in a graph, finding the strongly connected components in a directed graph, solving puzzles like mazes, testing the existence of a cycle in a graph, and solving problems that require exhaustive search of a tree or graph. It's important to mention that DFS can be implemented in both recursive and non-recursive ways, the former is more simple to understand but it may cause stack overflow if the depth is too deep while the later can handle large depth but it may be more complex to understand.