Computer Dictionary Online

Medical Dictionary   Law Dictionary   Legal Dictionary   Website Design

0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f  g  h  i  j  k  l  m  n  o  p  q  r  s  t  u  v  w  x  y  z 

binary search

<algorithm> A search algorithm which repeatedly divides an ordered search space in half according to how the required (key) value compares with the middle element.

The following pseudo-C routine performs a binary search return the index of the element of vector "thing[first..last]" equal to "target":

	 if (target < thing[first] || target > thing[last])
	   return NOT_FOUND;
	 while (first < last)
	   mid = (first+last)/2;	/* truncate to integer */
	   if (target == thing[mid])
	     return mid;
	   if (target < thing[mid])
	     last = mid-1;
	     first = mid+1;
	 if (target == thing[last])
	   return last;
	 return NOT_FOUND;


Contact the Computer Dictionary Online  ::  Link to the Computer Dictionary Online  ::  Disclaimer for Computer Dictionary Online

Computer Dictionary Online
Copyright © 2018