Exhaustive Search: CS 306 Lecture notes

Computer Algorithms II Lecture Notes

30 September 2008 • Exhaustive Search


Given an array of points p find a point pair at least as close to each other as any other point pair in p.

(int, int) closest(points p[])

  n = size(p)
  assert n > 1

  p1, p2 = 0, 1
  d = distance(p[p1], p[p2])

  for i = 0 to n - 2
    for j = i + 1 to n - 1
      d' = distance(p[i], p[j])
      if d' < d
        p1, p2 = i, j
        d = d'

  return p1, p2


This page last modified on 24 January 2006.