Skip to content Skip to sidebar Skip to footer

Efficiently Get Kth Smallest Element In Unsorted List In Python

Is there any fast/efficient method available for solving this problem? I can do it in O(nlogn) but faster solution I am expecting.

Solution 1:

You are looking for Selection algorithm, which is done in O(n)


Solution 2:

Just looking at the Python libraries you might try heapq.nsmallest.


Post a Comment for "Efficiently Get Kth Smallest Element In Unsorted List In Python"