maoruibin / maoruibin/maoruibin.github.com

二分查找算法

Open
#94 0 comments 0 reactions 0 assignees View on GitHub

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

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.