Impossible is Nothing !
如果我QQ上线但又没有给你发消息. 那请你原谅 因为我那时候正专心于我的事业中. 但这并不代表我没有把你放在第一位 恰恰因为我把你放在了第一位 所以才利用没有和你在一起的时间做完我该做的事. 而当我们在一起的时候. 我才能全心全意地和你在一起
posts - 17,comments - 0,trackbacks - 0
1.Binary Search
/*
Preconditions: 
   If size>0 , the first through first+size-1 must be valid indexes for the 
array a. Also , starting at a[first] , the next size elements are sorted in 
increasing order form small to large.
*/
public static int search(int[] a , int first , int size , int target)
{
    int middle;
    if(size <= 0)
       return -1;
    else{
       middle = first + size/2;
       if(target == a[middle])
          return search(a, first , size/2 , target);
       else
          return search(a , middle+1 , (size-1)/2 , target);
    }
}
worst-case runningtime: O(logN)
The binary search algorthm is very efficient. For example suppose the constant c is 10. 
Then an array with a thousand elemenets has a running time of 1
posted on 2006-03-28 20:59 kinns 阅读(93) 评论(0)  编辑 收藏 引用 所属分类: Data Structure
只有注册用户登录后才能发表评论。