search algorithm and tests