algorithm work