Skip to content

feat: add jump search with O(sqrt(n)) and unit tests#1567

Open
koutsovasilis-tech wants to merge 2 commits intoTheAlgorithms:masterfrom
koutsovasilis-tech:feature/jump-search
Open

feat: add jump search with O(sqrt(n)) and unit tests#1567
koutsovasilis-tech wants to merge 2 commits intoTheAlgorithms:masterfrom
koutsovasilis-tech:feature/jump-search

Conversation

@koutsovasilis-tech
Copy link
Copy Markdown

@koutsovasilis-tech koutsovasilis-tech commented Mar 27, 2026

Description of Change: Implemented the Jump Search algorithm in C. This algorithm provides a middle ground between Linear Search and Binary Search, with a time complexity of O(n​).

Optimal Step Size: sqrt(n) as jumping interval to minimize number of comparisons.

Memory Safety: Implemented strict bounds checking to handle cases where the jump exceeds the array size, preventing Buffer Overflows.

Unit Testing: Integrated a comprehensive test suite in main() using <assert.h> to verify:

Target at the start (index 0).

Target in the middle.

Target at the end (last index).

Target not present in the array.

Code Quality: Added Doxygen-style documentation and clear comments for logic flow.

References

Checklist

  • Added description of change
  • Added file name matches File name guidelines
  • Added tests and example, test must pass
  • Relevant documentation/comments is changed or added
  • PR title follows semantic commit guidelines
  • Search previous suggestions before making a new one, as yours may be a duplicate.
  • I acknowledge that all my contributions will be made under the project's license.

Notes:

@koutsovasilis-tech
Copy link
Copy Markdown
Author

Hi! I have updated this PR to provide a more robust version of Jump Search.

The main fix: The existing implementation in the repo crashes with a Segmentation Fault (accessing arr[-1]) when an empty array (n=0) is passed. My version handles this edge case safely.

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.

1 participant