diff --git a/docs/docs/algorithms/graphs/breadthfirstsearch.md b/docs/docs/algorithms/graphs/breadthfirstsearch.md new file mode 100644 index 0000000..9552fb5 --- /dev/null +++ b/docs/docs/algorithms/graphs/breadthfirstsearch.md @@ -0,0 +1,71 @@ +# DepthFirstSearch Class + +**Class for performing Depth-First Search (DFS) on a graph.** + +## Class Members + +```csharp +DepthFirstSearch(Dictionary> graph) +``` + +Initializes a new instance of the DepthFirstSearch class. + +### Parameters + +- `graph` (Type: `Dictionary>`): The graph represented as an adjacency list. + +```csharp +ExecuteDfs(T start) +``` + +Executes Depth-First Search (DFS) starting from the specified vertex. + +### Parameters + +- `start` (Type: `T`): The starting vertex for DFS. + +### Returns + +- Type: `List` +- Description: A list of vertices visited in DFS order. + +### Example + +```csharp +using NetPlus.Algorithms.Graphs; + +// Example graph +Dictionary> graph = new Dictionary> +{ + { "A", new List { "B", "C" } }, + { "B", new List { "A", "D", "E" } }, + { "C", new List { "A", "F" } }, + { "D", new List { "B" } }, + { "E", new List { "B", "F" } }, + { "F", new List { "C", "E" } } +}; + +// Initialize DFS +var dfs = new DepthFirstSearch(graph); + +// Execute DFS from vertex A +List visitedVertices = dfs.ExecuteDfs("A"); + +// Display visited vertices +foreach (var vertex in visitedVertices) + Console.WriteLine(vertex); +``` + +### Usage + +To use the `DepthFirstSearch` class, initialize it with the graph represented as an adjacency list, then call the `ExecuteDfs` method with the starting vertex. + +```csharp +// Example usage +var dfs = new DepthFirstSearch(graph); +List visitedVertices = dfs.ExecuteDfs("A"); +``` + +### Remarks + +The `DepthFirstSearch` class performs Depth-First Search (DFS) on a graph represented as an adjacency list. It returns a list of vertices visited in DFS order.