TheAlgorithms/C++ 1.0.0
All the algorithms implemented in C++
|
Depth First Search Algorithm (Depth First Search) More...
#include <algorithm>
#include <iostream>
#include <vector>
Go to the source code of this file.
Namespaces | |
namespace | graph |
Graph Algorithms. | |
Functions | |
void | graph::addEdge (std::vector< std::vector< size_t > > *adj, size_t u, size_t v) |
Adds and edge between two vertices of graph say u and v in this case. | |
void | graph::explore (const std::vector< std::vector< size_t > > &adj, size_t v, std::vector< bool > *visited) |
Explores the given vertex, exploring a vertex means traversing over all the vertices which are connected to the vertex that is currently being explored. | |
void | graph::depth_first_search (const std::vector< std::vector< size_t > > &adj, size_t start) |
initiates depth first search algorithm. | |
int | main () |
Depth First Search Algorithm (Depth First Search)
Depth First Search also quoted as DFS is a Graph Traversal Algorithm. Time Complexity O(|V| + |E|) where V is number of vertices and E is number of edges in graph.
Application of Depth First Search are
And there are many more...
start exploring from some starting vertex.
While exploring vertex we mark the vertex as visited and start exploring the vertices connected to this vertex in recursive way.
Definition in file depth_first_search.cpp.
int main | ( | void | ) |
Main function
creating graph
taking input for edges
running depth first search over graph
Definition at line 109 of file depth_first_search.cpp.