Basic hierarchical algorithm