Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

search: add search_rotated_sorted_array with tests #922

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
bivekk51 wants to merge 3 commits into TheAlgorithms:master
base: master
Choose a base branch
Loading
from bivekk51:master

Conversation

@bivekk51
Copy link

@bivekk51 bivekk51 commented Oct 5, 2025

Description

  • Summary: Implemented search_rotated_sorted_array which finds a target in a rotated, ascending-sorted slice and returns Option<usize>.
  • Motivation: This algorithm complements existing searching implementations by handling arrays that were rotated after sorting.
  • Implementation method: A modified binary search that detects which half of the current range is normally ordered and narrows the search into the half that can contain the target. Assumes distinct elements.
  • Complexity: O(log n) time, O(1) extra space.
  • Notes: If duplicate elements must be supported, additional checks are required and worst-case complexity may degrade.

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Checklist:

  • I ran below commands using the latest version of rust nightly.
  • I ran cargo clippy --all -- -D warnings just before my last commit and fixed any issue that was found.
  • I ran cargo fmt just before my last commit.
  • I ran cargo test just before my last commit and all tests passed.
  • I added my algorithm to the corresponding mod.rs file within its own folder, and in any parent folder(s).
  • I added my algorithm to DIRECTORY.md with the correct link.
  • I checked CONTRIBUTING.md and my code follows its guidelines.

Copy link

codecov-commenter commented Oct 5, 2025
edited
Loading

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.34%. Comparing base (ed7a42e) to head (23b8eb8).

Additional details and impacted files
@@ Coverage Diff @@
## master #922 +/- ##
==========================================
+ Coverage 95.32% 95.34% +0.01% 
==========================================
 Files 319 320 +1 
 Lines 20899 20964 +65 
==========================================
+ Hits 19923 19988 +65 
 Misses 976 976 

☔ 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@imp2002 imp2002 Awaiting requested review from imp2002 imp2002 is a code owner

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /