[FEATURE REQUEST] Add Search in Rotated Sorted Array implementation with JUnit tests
维护者通常 1 天内回复
@Pratik5545 已经在做这个了。
开始于 2026年11月3日。
评估
这个 Issue 还没有评估数据。
描述
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 $\mathcal{O}(\log N)$ time complexity by checking which half of the rotated array is sorted at each step.
Proposed Changes
I would like to add:
SearchInRotatedArray.javaundersrc/main/java/com/thealgorithms/searches/- Complete implementation with clear Javadoc explanations ($\mathcal{O}(\log N)$ Time, $\mathcal{O}(1)$ Space).
- Proper null checks and edge-case handling.
SearchInRotatedArrayTest.javaundersrc/test/java/com/thealgorithms/searches/- Comprehensive JUnit 5 test suite covering standard rotations, target not found, empty arrays, and single-element arrays.
Verification
I will ensure all code follows the project's formatting rules and passes ./gradlew test / mvn test locally before opening a PR.
I would love to implement this as my first open-source contribution! Could a maintainer please assign this issue to me?
Issue details
Issue Details & Algorithm Overview
1. Algorithm Description
- Algorithm: Search in Rotated Sorted Array
- Category: Searching Algorithms / Binary Search Variation
- Language: Java
2. How the Algorithm Works
Given 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.
Key Logic:
- Find the middle element using
int mid = left + (right - left) / 2;to avoid integer overflow. - Check if the left half of the array (
nums[left]tonums[mid]) is sorted:- If sorted, check if the target falls within
nums[left]andnums[mid]. Adjustleftorrightboundaries accordingly.
- If sorted, check if the target falls within
- Otherwise, the right half must be sorted:
- Check if the target falls within
nums[mid]andnums[right]. Adjust boundaries accordingly.
- Check if the target falls within
3. Complexity Analysis
- Time Complexity: $\mathcal{O}(\log N)$ — Divides the search space in half at each iteration.
- Space Complexity: $\mathcal{O}(1)$ — Uses constant iterative space without recursion stacks or extra memory allocation.
4. Planned Files & Folder Structure
src/main/java/com/thealgorithms/searches/SearchInRotatedArray.java(Implementation)src/test/java/com/thealgorithms/searches/SearchInRotatedArrayTest.java(JUnit 5 Test Suite)
Additional Information
No response
- 主要语言
- Java
- 星标
- 67.2k
- 派生
- 21.5k
- 平均合并
- 2 天 5 小时
- 30 天内合并 PR
- 42
环境准备
在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
TheAlgorithms/Java 的其他 Issue
-
[OTHER] Contributors Wanted for New Open-Source Projects可能重新可做 @ankkrish 于 73 天前认领,目前没有进行中的 PR。 未关闭hacktoberfest help wanted
难度 5/5 一周以上 新手友好度 1/100
TheAlgorithms/Java#7546 · 11 条评论 ·
维护者通常 1 天内回复
-
Centralized Configuration Management可能重新可做 @Eyablg-ops 于 60 天前认领,目前没有进行中的 PR。 未关闭enhancement
难度 5/5 一周以上 新手友好度 20/100
TheAlgorithms/Java#6974 · 3 条评论 ·
维护者通常 1 天内回复
查看 TheAlgorithms/Java 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 84/100
apache/flink-agents#1395 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 77/100
维护者通常 1 天内回复
-
难度 1/5 1 小时以内 新手友好度 68/100
quarkiverse/quarkiverse#476 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 77/100
chinabugotech/hutool#4364 · 1 条评论 ·
维护者通常 1 天内回复
-
lesson-submission pending-review
难度 1/5 1 小时以内 新手友好度 72/100
Ikalus1988/MisakaNet#5115 ·
维护者通常 1 天内回复