The thesis algorithm