School of Engineering and Applied Science
Department of Computer Science
CSci 133 -- Introduction to Software Development 
http://www.seas.gwu.edu/~csci133/spring05
Prof. Michael B. Feldman
mfeldman@gwu.edu

Occasional Lecture Notes

last change: Monday, March 7, 2005

Binary Search function from class, March 4, 2005

// Main, Fig. 11.2, p. 554
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 middle;
    else if (target < a[middle])
      // the target is less than a[middle],
      // so search before the middle
      return search(a, first, size/2, target);
    else
      // the target must be greater than a[middle],
      // so search after the middle
      return search(a, middle+1, (size-1)/2, target);
  }
}


Notes from Start of Semester on Classes, Methods, and Testing

Application Programs vs. Software Components (reusable classes)

Writing Your Own ADT Classes

Characteristics of Data Values and Methods


(end of document)