17. The apparatus of claim 16 , wherein the program further comprises a set of instructions for defining a structured document based on the structural elements and the primitive elements.
16. An apparatus comprising: a set of processing units for executing sets of instructions; a machine readable medium storing a program which when executed by at least one of the processing units defines a program for defining structure for a document, the program comprising sets of instructions for: identifying pairs of nearest primitive elements in a document comprising a plurality of primitive elements that are defined in terms of their position in the document; sorting the pairs of nearest primitive elements based on an order from a pair of nearest primitive elements that are a closest distance apart to a pair of nearest primitive elements that are a furthest distance apart; storing a single value that identifies, from the sorted pairs of nearest primitive elements, a particular pair of nearest primitive elements whose primitive elements are a minimum distance apart to form a partition, wherein each pair of nearest primitive elements that are greater distance apart than the minimum distance is after the particular pair in the order; identifying partitions between the primitive elements in the document based on the single value and the sorted pairs of nearest primitive elements; and using the partitions to define structural elements for the document.