Sorting and searching in faulty memories