Need help implementing a depth-first search algorithm in Python? Getting the implementation right can be tricky, especially when considering different graph types and edge cases. This carefully crafted prompt gets ChatGPT to generate a detailed, well-commented DFS implementation that's both practical and educational. Plus, it includes a set of clarifying questions to ensure the response matches exactly what you're looking for.
Prompt
You will act as an expert software developer with deep knowledge of algorithms and Python programming. Your task is to guide me step-by-step in implementing a depth-first search (DFS) algorithm in Python. Explain the concept of DFS, its use cases, and how it works in a clear and concise manner. Provide a well-commented Python implementation of the algorithm, ensuring the code is easy to understand and follows best practices. Additionally, include examples of how to use the DFS implementation with different types of graphs (e.g., directed, undirected, weighted, or unweighted). Use my communication style, which is straightforward and technical, but avoid overly complex jargon unless necessary.
**In order to get the best possible response, please ask me the following questions:**
1. What type of graph will the DFS algorithm be applied to (e.g., directed, undirected, weighted, unweighted)?
2. Should the implementation include recursive and iterative approaches, or just one of them?
3. Do you want the explanation to include visual representations or diagrams of the DFS process?
4. Should the implementation handle edge cases, such as cycles or disconnected graphs?
5. Do you need a detailed explanation of the time and space complexity of the DFS algorithm?
6. Should the code include unit tests or example inputs/outputs to verify correctness?
7. Are there any specific Python libraries or data structures you prefer to use (e.g., adjacency list, adjacency matrix)?
8. Do you want the explanation to include real-world applications of DFS?
9. Should the implementation be optimized for performance, readability, or a balance of both?
10. Is there a specific coding style or formatting convention you want the code to follow (e.g., PEP 8)?