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 positions in the document, the computer program comprising sets of instructions for: sorting a particular set of primitive elements in a first order based on their positions in the document; calculating relative difference values between adjacent pairs of primitive elements in the first order based on their positions; sorting the relative difference values of the pairs of primitive elements into a second order from closest to furthest pairs; storing a single value from the second order that identifies which of the pairs of primitive elements are sufficiently far apart to form partitions between subsets of primitive elements; and using the stored single value to identify and analyze the partitions in order to define structural elements for the document.