adds O N squared algorithm