-
Notifications
You must be signed in to change notification settings - Fork 19.9k
Add exponential search algorithm #6218
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
base: master
Are you sure you want to change the base?
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #6218 +/- ##
============================================
- Coverage 73.79% 73.70% -0.09%
Complexity 5303 5303
============================================
Files 672 673 +1
Lines 18357 18378 +21
Branches 3549 3554 +5
============================================
Hits 13546 13546
- Misses 4264 4285 +21
Partials 547 547 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There needs to be a fix for the unused import, the addition of a private constructor to the utility class, and the inclusion of curly braces for all 'if'/'else' blocks to improve readability and consistency and pass the actions that failed
@@ -0,0 +1,48 @@ | |||
package com.thealgorithms.searchs; | |||
|
|||
import java.util.Arrays; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think there might be an unused import. Is this necessary?
|
||
import java.util.Arrays; | ||
|
||
public class ExponentialSearch { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you need to insert a private constructor because the default constructor from the Object class is public
int n = arr.length; | ||
|
||
// If the element is present at the first position | ||
if (arr[0] == x) return 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's recommended to use curly braces for 'if' blocks, even for single statements
while (low <= high) { | ||
int mid = low + (high - low) / 2; | ||
|
||
if (arr[mid] == x) return mid; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there are also here curly braces needed
|
||
if (arr[mid] == x) return mid; | ||
|
||
if (arr[mid] < x) low = mid + 1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's necessary to use curly braces for 'if' and 'else' blocks, even for single statements
these gates should pass after he implements the requested changes above but i recommend you to run clang formatter manually @vieriloh |
Hello, @vieriloh! You can simply remove the unused |
This pull request adds a new implementation of the Exponential Search algorithm under the searchs package (com.thealgorithms.searchs).
Exponential Search is an efficient algorithm for searching sorted arrays. It works by finding a range where the element is likely to be and then performing Binary Search within that range.
Key Details:
Method: search(int[] arr, int x)
Includes a helper binarySearch method
Added test logic in main method for quick verification
This feature is part of my assignment for software configuration and quality practices, demonstrating version control, branching, and collaborative workflow.