adapted search algorithm