Update Binary search in C++
Improvements:
Use of <bits/stdc++.h>: This header includes all standard library headers, which can increase compilation time unnecessarily. It is better to include only the specific headers you need, in this case,
Pass large arrays by reference: While this is not strictly necessary in this small example, for large arrays, it is generally more efficient to pass them by reference rather than by value.
Variable naming: Use more descriptive variable names, such as left, right, and mid, instead of abbreviations like l, r, and m. This enhances code readability.
Edge case handling: The code does not have any significant flaws in logic, but ensuring that it's applied only on sorted arrays is important in practice. Perhaps adding a comment about it or including an assertion that checks if the array is sorted might help in larger projects.