maoruibin / maoruibin/maoruibin.github.com
二分查找算法
Open
Nobody has claimed this yet.
基本算法
- Dominant language
- HTML
- Stars
- 22
- Forks
- 4
- PR merge metrics
- No merged PRs in 30d
Description
原理:在一个有序的数组中,先从中间找,如果中间元素大于目标值,说明目标值在中间元素靠左,这时设置 end 位置为 middle-1。
反之,如果中间元素小于目标值,说明目标值在中间元素靠右,这时 start 位置设为 middle +1,如果相等,则表示找到了目标值。
static int bsearchWithoutRecursion(int a[], int key) {
int start = 0;
int end = a.length-1;
while (start<=end){
int mid = (start+end)/2;
System.out.println("mid is "+mid);
if(a[mid] >key){
end = mid-1;
}else if(a[mid]<key){
start = mid+1;
}else{
return mid;
}
}
return -1;
}
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
The issue provides a Java binary-search explanation and code but names no file, post location, or specific requested change. Start by reviewing the repository's blog content structure and deciding how this submission is intended to fit. Done criteria are not stated in the issue, so the scope and expected result need clarification first.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- content, documentation
- Issue type
- Documentation
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100