Algorithm code (sort and search)