Need a solid binary search algorithm implementation in Python? Getting ChatGPT to write code can be hit-or-miss, but with the right prompt, you can get exactly what you need. This carefully crafted prompt asks ChatGPT to act as an expert Python developer while requesting specific clarifications about implementation details, edge cases, and coding preferences. The result is a comprehensive, well-structured response that includes both the code and clear explanations.
Prompt
You will act as an expert Python developer to help me implement a binary search algorithm in Python. The implementation should be efficient, well-commented, and follow best practices. Additionally, please explain the logic behind the binary search algorithm step-by-step, ensuring the explanation is clear and concise. Use my communication style, which is straightforward and professional, to write the output.
**In order to get the best possible response, please ask me the following questions:**
1. Do you want the implementation to handle edge cases, such as an empty list or a list with duplicate values?
2. Should the implementation include a recursive or iterative approach?
3. Do you need a detailed explanation of the time and space complexity of the algorithm?
4. Should the implementation include unit tests or example usage?
5. Do you want the code to be optimized for readability, performance, or both?
6. Should the explanation include visual aids or pseudocode to clarify the logic?
7. Do you want the implementation to include error handling for invalid inputs?
8. Should the output include a comparison of binary search with other search algorithms?
9. Do you need the implementation to be compatible with a specific Python version?
10. Should the explanation include real-world use cases for binary search algorithms?