Skip to content

Conversation

@Siddhram
Copy link
Contributor

This PR introduces a fully documented implementation of Interpolation Search in R, designed to efficiently find elements in a sorted numeric vector with approximately uniform distribution.

Overview

The interpolation_search function estimates the likely position of the target using linear interpolation instead of binary halving. This allows faster searches on uniformly distributed data compared to traditional binary search. The algorithm returns the 1-based index of the target if found, or -1 if the target is not present.

Features

  • Searches for a target value in a sorted numeric vector
  • Uses linear interpolation to estimate the search position
  • Efficient on uniformly distributed arrays
  • Returns -1 if the target is not found
  • Includes a simple demonstration example
  • Follows consistent API style with other R search algorithm modules

Complexity

  • Average-case Time Complexity: O(log log n)
  • Worst-case Time Complexity: O(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 Interpolation Search in R Add Interpolation Search Algorithm in R Oct 18, 2025
@siriak siriak requested a review from Copilot October 23, 2025 15:04
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 interpolation search algorithm implementation to the repository's search algorithms collection. Interpolation search is an alternative to binary search that uses linear interpolation to estimate the target's position, making it more efficient for uniformly distributed sorted data.

Key Changes

  • Introduces a new interpolation_search() function with comprehensive documentation
  • Implements the algorithm with proper edge case handling (empty arrays, out-of-bounds targets, duplicate values)
  • Includes a demonstration example showing basic usage

@siriak siriak merged commit 304eb46 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