add optimal algorithm