Skip to content

Added Solution for Binary Search in Java (issue #5529) #5542

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed

Added Solution for Binary Search in Java (issue #5529) #5542

wants to merge 2 commits into from

Conversation

Sidhesh-Goud
Copy link

Enhancements:

Overflow Prevention: The mid-point calculation is optimized to avoid overflow when dealing with large arrays. Instead of using (left + right) / 2, we use left + (right - left) / 2.

Edge Case Handling: The algorithm checks if the input array is null or empty and handles it gracefully by returning -1 early.

Debugging Statements: Added debug statements to show the mid index and mid element during the execution, useful for understanding how the algorithm works step-by-step.

Readability: The code is organized with clear comments explaining each step, which is helpful when understanding or modifying the algorithm.

Time Complexity:
Best case: O(1) (if the target is at the middle)
Average and worst case: O(logn), where n is the number of elements in the array.

@Sidhesh-Goud Sidhesh-Goud deleted the Binary-Search-Solution branch October 3, 2024 11:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants