Skip to content

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

vieriloh
Copy link

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.

@codecov-commenter
Copy link

Codecov Report

Attention: Patch coverage is 0% with 21 lines in your changes missing coverage. Please review.

Project coverage is 73.70%. Comparing base (f53bc00) to head (8b86539).

Files with missing lines Patch % Lines
...a/com/thealgorithms/searchs/ExponentialSearch.java 0.00% 21 Missing ⚠️
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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Collaborator

@DenizAltunkapan DenizAltunkapan left a 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;
Copy link
Collaborator

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 {
Copy link
Collaborator

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;
Copy link
Collaborator

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;
Copy link
Collaborator

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;
Copy link
Collaborator

@DenizAltunkapan DenizAltunkapan Apr 12, 2025

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

@siriak
Copy link
Member

siriak commented Apr 12, 2025

Please also check these gates
image

@DenizAltunkapan
Copy link
Collaborator

DenizAltunkapan commented Apr 12, 2025

Please also check these gates image

these gates should pass after he implements the requested changes above but i recommend you to run clang formatter manually @vieriloh

@huseynovvusal
Copy link
Contributor

huseynovvusal commented Apr 17, 2025

Hello, @vieriloh! You can simply remove the unused java.util.Arrays import, add a private constructor to the utils class so it can’t be instantiated, and wrap all your if-else blocks in braces. Hope it will help you. :)

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.

5 participants