sorting and proper data structure