Graphs in C#
Problems to practice
- Number of Islands
- Course Schedule
- Clone Graph
- Topological Sort
- BFS and DFS traversal
- Shortest path in unweighted graph
- Union-Find connectivity
Example: BFS using queue
var queue = new Queue<int>();
var visited = new HashSet<int>();
queue.Enqueue(start);
visited.Add(start);
while (queue.Count > 0) {
int node = queue.Dequeue();
foreach (var neighbor in graph[node]) {
if (!visited.Contains(neighbor)) {
visited.Add(neighbor);
queue.Enqueue(neighbor);
}
}
}Can you explain it without the notes?
Graphs in C#
Use your own words. Explain an example and one limitation before checking the explanation.
Check your explanation
Common questions
Turn this concept into a clear answer.
Practice this conceptAdapted from 17_DSA_DOTNET.md · “9. Graphs in C#”. Examples are study fragments; framework behavior can depend on your version.