Add algorithm and test for find_end