implemented find_top_k_elements algorithm