Skip to content

Conversation

@Siddhram
Copy link
Contributor

This PR introduces a fully documented implementation of Exponential Search in R, designed for efficient search in sorted numeric arrays.

Overview

The exponential_search function first identifies a search range by exponentially increasing indices (1, 2, 4, 8, …) until it finds a range where the target may reside. It then performs a binary search within that range to locate the target efficiently. The algorithm returns the 1-based index of the target if found, or -1 if the target is absent.

Features

  • Searches for a target value in a sorted numeric vector
  • Uses exponential index doubling to quickly narrow down the search range
  • Performs binary search within the identified range
  • Returns -1 if the target is not found
  • Includes a demonstration example
  • Follows consistent API style with other R search algorithm modules

Complexity

  • Time Complexity: O(log n)
  • Space Complexity: O(1)

Demonstration

Run the included example to search for a value in a sorted array. The algorithm outputs the index of the target if present, or indicates that the element is not found.

@Siddhram Siddhram changed the title Add Exponential Search in R Add Exponential Search Algorithm in R Oct 18, 2025
@siriak siriak requested a review from Copilot October 23, 2025 15:07
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds an implementation of the Exponential Search algorithm for efficiently searching sorted numeric arrays in R. The algorithm uses exponential index doubling to quickly identify a search range, then performs binary search within that range.

Key Changes:

  • Adds a new exponential_search() function with O(log n) time complexity
  • Includes a helper function .binary_search_range() for the binary search phase
  • Provides a demonstration example showing usage on a sorted array

@siriak siriak merged commit f3cb0ba into TheAlgorithms:master Oct 23, 2025
2 checks passed
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