feat: add jump search with O(sqrt(n)) and unit tests#1567
Open
koutsovasilis-tech wants to merge 2 commits intoTheAlgorithms:masterfrom
Open
feat: add jump search with O(sqrt(n)) and unit tests#1567koutsovasilis-tech wants to merge 2 commits intoTheAlgorithms:masterfrom
koutsovasilis-tech wants to merge 2 commits intoTheAlgorithms:masterfrom
Conversation
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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
Code Quality: Added Doxygen-style documentation and clear comments for logic flow.
References
Checklist
Notes: