1. A computer readable medium storing a computer program which when executed by at least one processor defines structure for a document comprising a plurality of primitive elements that are defined in terms of their position in the document, the computer program comprising sets of instructions for: identifying, for a particular set of primitive elements, a pairwise grouping of nearest primitive elements in the set; sorting the pairwise groupings of primitive elements based on an order from the closest to the furthest pairs; storing a single value that identifies which of the pairwise groupings of primitive elements are sufficiently far apart to form a partition; and using the stored single value to identify and analyze the partition in order to define structural elements for the document.