Friday, 19 July 2013

Algorithm for Binary Search

  1. Input an array A of an element an “data” to be sort
  2. LB=0,UB=n; mid = int((LB+UB)/2)
  3. Repeat Step 4 and 5 while(LB<=UB) and (A[Mid])!= data UB= mid-1
  4. If(data<A[mid])UB=mid-1ElseLB=mid+1
  5. Mid=int((LB+UB)/2)
  6. If(A[mid]==data)Printf(“The data is found”);ElsePrintf(“The data is not found”);
  7. Exit

No comments:

Post a Comment