int visited[max{ }int adj[max][max]ijprintf("\ enter the adjacency matrix")for( maxi++for( maxj++scanf("% "&adj[ ][ ])breadth_first_search(adj,visited, )return output enter the adjacency matrix depth-first search algorithm the depth-first search algorithm (fig progresses by expanding the starting node of and then going deeper and deeper until the goal node is foundor until node that has no children is encountered when dead-end is reachedthe algorithm backtracksreturning to the most recent node that has not been completely explored in other wordsdepth-first search begins at starting node which becomes the current node thenit examines each node along path which begins at that iswe process neighbour of athen neighbour of neighbour of aand so on during the execution of the algorithmif we reach path that has node that has already been processedthen we backtrack to the current node otherwisethe unvisited (unprocessednode becomes the current node the algorithm proceeds like this until we reach dead-end (end step set status (ready statefor each node in step push the starting node on the stack and set of path on reaching the deadits status (waiting stateendwe backtrack to find another step repeat steps and until stack is empty path cthe algorithm terminates step pop the top node process it and set its status (processed statewhen backtracking leads back to the step push on the stack all the neighbours of that starting node in this algorithmare in the ready state (whose status and edges that lead to new vertex are set their status (waiting state[end of loopcalled discovery edges and edges that step exit lead to an already visited vertex are called back edges figure algorithm for depth-first search observe that this algorithm is similar to the in-order traversal of binary tree its implementation is similar to that of the breadth-first search algorithm but here we use stack instead of queue againwe use variable status to represent the current state of the node example consider the graph given in fig the adjacency list of is also given suppose we want to print all the nodes that can be reached from the node (including itselfone alternative is to use depth-first search of starting at node the procedure can be explained here