Title: [FEATURE REQUEST] Add Search in Rotated Sorted Array implementation with JUnit tests · Issue #7579 · TheAlgorithms/Java · GitHub
Open Graph Title: [FEATURE REQUEST] Add Search in Rotated Sorted Array implementation with JUnit tests · Issue #7579 · TheAlgorithms/Java
X Title: [FEATURE REQUEST] Add Search in Rotated Sorted Array implementation with JUnit tests · Issue #7579 · TheAlgorithms/Java
Description: What would you like to Propose? Feature Description I would like to propose adding an implementation of Search in Rotated Sorted Array in Java using the Binary Search technique. This is a classic variation of Binary Search that achieves ...
Open Graph Description: What would you like to Propose? Feature Description I would like to propose adding an implementation of Search in Rotated Sorted Array in Java using the Binary Search technique. This is a classic v...
X Description: What would you like to Propose? Feature Description I would like to propose adding an implementation of Search in Rotated Sorted Array in Java using the Binary Search technique. This is a classic v...
Opengraph URL: https://github.com/TheAlgorithms/Java/issues/7579
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[FEATURE REQUEST] Add Search in Rotated Sorted Array implementation with JUnit tests","articleBody":"### What would you like to Propose?\n\n### Feature Description\nI would like to propose adding an implementation of **Search in Rotated Sorted Array** in Java using the Binary Search technique. \n\nThis is a classic variation of Binary Search that achieves $\\mathcal{O}(\\log N)$ time complexity by checking which half of the rotated array is sorted at each step.\n\n### Proposed Changes\nI would like to add:\n1. `SearchInRotatedArray.java` under `src/main/java/com/thealgorithms/searches/`\n - Complete implementation with clear Javadoc explanations ($\\mathcal{O}(\\log N)$ Time, $\\mathcal{O}(1)$ Space).\n - Proper null checks and edge-case handling.\n2. `SearchInRotatedArrayTest.java` under `src/test/java/com/thealgorithms/searches/`\n - Comprehensive JUnit 5 test suite covering standard rotations, target not found, empty arrays, and single-element arrays.\n\n### Verification\nI will ensure all code follows the project's formatting rules and passes `./gradlew test` / `mvn test` locally before opening a PR.\n\n---\n*I would love to implement this as my first open-source contribution! Could a maintainer please assign this issue to me?*\n\n### Issue details\n\n### Issue Details & Algorithm Overview\n\n#### 1. Algorithm Description\n- **Algorithm:** Search in Rotated Sorted Array\n- **Category:** Searching Algorithms / Binary Search Variation\n- **Language:** Java\n\n#### 2. How the Algorithm Works\nGiven a sorted array of integers that has been rotated at an unknown pivot index (e.g., `[0, 1, 2, 4, 5, 6, 7]` becomes `[4, 5, 6, 7, 0, 1, 2]`), find the index of a given target element. If the element is not present, return `-1`.\n\nKey Logic:\n1. Find the middle element using `int mid = left + (right - left) / 2;` to avoid integer overflow.\n2. Check if the left half of the array (`nums[left]` to `nums[mid]`) is sorted:\n - If sorted, check if the target falls within `nums[left]` and `nums[mid]`. Adjust `left` or `right` boundaries accordingly.\n3. Otherwise, the right half must be sorted:\n - Check if the target falls within `nums[mid]` and `nums[right]`. Adjust boundaries accordingly.\n\n#### 3. Complexity Analysis\n- **Time Complexity:** $\\mathcal{O}(\\log N)$ — Divides the search space in half at each iteration.\n- **Space Complexity:** $\\mathcal{O}(1)$ — Uses constant iterative space without recursion stacks or extra memory allocation.\n\n#### 4. Planned Files & Folder Structure\n- `src/main/java/com/thealgorithms/searches/SearchInRotatedArray.java` (Implementation)\n- `src/test/java/com/thealgorithms/searches/SearchInRotatedArrayTest.java` (JUnit 5 Test Suite)\n\n### Additional Information\n\n_No response_","author":{"url":"https://github.com/Dhanshri07-tech","@type":"Person","name":"Dhanshri07-tech"},"datePublished":"2026-08-23T16:57:13Z","url":"https://github.com/TheAlgorithms/Java/issues/7579"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:de2a731d-198c-8529-49b1-f2d141ff77c8 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8CEE:1EC9BC:30B6EAC:3E23F49:6B01D2EE |
| html-safe-nonce | 520a99c2f0fc480512d80245c9d3abdc29830cbe9327bb3e3da86106bc170da7 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4Q0VFOjFFQzlCQzozMEI2RUFDOjNFMjNGNDk6NkIwMUQyRUUiLCJ2aXNpdG9yX2lkIjoiNTcwNzk1NzI0NTQ5NzY5MjkxMCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 8c5d2a2fe58cded7c6aaac1cf5fd27759fc044689167a97a720151d5ca759733 |
| hovercard-subject-tag | issue:5228008976 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/TheAlgorithms/Java/7579/issue_layout |
| twitter:image | https://opengraph.githubassets.com/2d71c38e93fa1c7d2d6b56f9d054ea81f6df13e36b7638bcdf016a9981b26366/TheAlgorithms/Java/issues/7579 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/2d71c38e93fa1c7d2d6b56f9d054ea81f6df13e36b7638bcdf016a9981b26366/TheAlgorithms/Java/issues/7579 |
| og:image:alt | What would you like to Propose? Feature Description I would like to propose adding an implementation of Search in Rotated Sorted Array in Java using the Binary Search technique. This is a classic v... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | Dhanshri07-tech |
| hostname | github.com |
| expected-hostname | github.com |
| None | cc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c |
| turbo-cache-control | no-preview |
| go-import | github.com/TheAlgorithms/Java git https://github.com/TheAlgorithms/Java.git |
| octolytics-dimension-user_id | 20487725 |
| octolytics-dimension-user_login | TheAlgorithms |
| octolytics-dimension-repository_id | 63477660 |
| octolytics-dimension-repository_nwo | TheAlgorithms/Java |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 63477660 |
| octolytics-dimension-repository_network_root_nwo | TheAlgorithms/Java |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 8c77c9e8439031ad54c75a250694842892f693e1 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width